mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 01:23:32 -06:00
Elasticsearch: Fix using of datetime format for time field (#64676)
* Elasticsearch: Fix using of datetime format for time field * Use convertFieldType to convert time field for better performance
This commit is contained in:
parent
d2fa019d78
commit
96fc0b814e
@ -1301,6 +1301,7 @@ describe('ElasticResponse', () => {
|
||||
refId: 'A',
|
||||
metrics: [{ type: 'raw_data', id: '1' }],
|
||||
bucketAggs: [],
|
||||
timeField: '@timestamp',
|
||||
},
|
||||
];
|
||||
|
||||
@ -1317,7 +1318,7 @@ describe('ElasticResponse', () => {
|
||||
_id: '1',
|
||||
_type: '_doc',
|
||||
_index: 'index',
|
||||
_source: { sourceProp: 'asd' },
|
||||
_source: { sourceProp: 'asd', '@timestamp': '2019-01-01T00:00:00Z' },
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -1333,6 +1334,12 @@ describe('ElasticResponse', () => {
|
||||
expect(field.config.filterable).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should have time field values in DateTime format', () => {
|
||||
const timeField = result.data[0].fields.find((field) => field.name === '@timestamp');
|
||||
expect(timeField).toBeDefined();
|
||||
expect(timeField?.values.get(0)).toBe(1546300800000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('simple logs query and count', () => {
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
MutableDataFrame,
|
||||
PreferredVisualisationType,
|
||||
} from '@grafana/data';
|
||||
import { convertFieldType } from '@grafana/data/src/transformations/transformers/convertFieldType';
|
||||
import TableModel from 'app/core/TableModel';
|
||||
import flatten from 'app/core/utils/flatten';
|
||||
|
||||
@ -601,6 +602,14 @@ export class ElasticResponse {
|
||||
}
|
||||
}
|
||||
|
||||
for (let frame of dataFrame) {
|
||||
for (let field of frame.fields) {
|
||||
if (field.type === FieldType.time && typeof field.values.get(0) !== 'number') {
|
||||
field.values = convertFieldType(field, { destinationType: FieldType.time }).values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { data: dataFrame };
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user