mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elastic: Fix parsing for millisecond number timestamps (#20290)
* Stop parsing 'field' * Remove time field from query for docs queries * Test refactor to test all versions * Fix tests
This commit is contained in:
parent
c43aa3485c
commit
4c9cb415ec
@ -58,7 +58,7 @@ describe('Apending DataFrame', () => {
|
||||
]);
|
||||
|
||||
// Add a time value that has an array type
|
||||
frame.add({ time: [300] });
|
||||
frame.add({ time: 300 });
|
||||
expect(frame.toArray()).toEqual([
|
||||
{ time: 100, name: 'a', value: 1, value2: null }, // 1
|
||||
{ time: 200, name: 'BB', value: 20, value2: null }, // 2
|
||||
|
@ -231,11 +231,6 @@ export class MutableDataFrame<T = any> implements DataFrame, MutableVector<T> {
|
||||
field.parse = makeFieldParser(val, field);
|
||||
}
|
||||
val = field.parse(val);
|
||||
} else if (field.type === FieldType.time && isArray(val)) {
|
||||
if (!field.parse) {
|
||||
field.parse = (val: any[]) => val[0] || undefined;
|
||||
}
|
||||
val = field.parse(val);
|
||||
}
|
||||
|
||||
if (val === undefined) {
|
||||
|
@ -424,40 +424,26 @@ export class ElasticResponse {
|
||||
throw this.getErrorFromElasticResponse(this.response, response.error);
|
||||
}
|
||||
|
||||
const hits = response.hits;
|
||||
// We keep a list of all props so that we can create all the fields in the dataFrame, this can lead
|
||||
// to wide sparse dataframes in case the scheme is different per document.
|
||||
let propNames: string[] = [];
|
||||
let propName, hit, doc: any, i;
|
||||
|
||||
for (i = 0; i < hits.hits.length; i++) {
|
||||
hit = hits.hits[i];
|
||||
for (const hit of response.hits.hits) {
|
||||
const flattened = hit._source ? flatten(hit._source, null) : {};
|
||||
doc = {};
|
||||
doc[this.targets[0].timeField] = null;
|
||||
doc = {
|
||||
...doc,
|
||||
const doc = {
|
||||
_id: hit._id,
|
||||
_type: hit._type,
|
||||
_index: hit._index,
|
||||
_source: { ...flattened },
|
||||
...flattened,
|
||||
};
|
||||
|
||||
// Note: the order of for...in is arbitrary amd implementation dependant
|
||||
// and should probably not be relied upon.
|
||||
for (propName in hit.fields) {
|
||||
if (propNames.indexOf(propName) === -1) {
|
||||
propNames.push(propName);
|
||||
}
|
||||
doc[propName] = hit.fields[propName];
|
||||
}
|
||||
|
||||
for (propName in doc) {
|
||||
for (const propName of Object.keys(doc)) {
|
||||
if (propNames.indexOf(propName) === -1) {
|
||||
propNames.push(propName);
|
||||
}
|
||||
}
|
||||
|
||||
doc._source = { ...flattened };
|
||||
|
||||
docs.push(doc);
|
||||
}
|
||||
|
||||
@ -468,9 +454,7 @@ export class ElasticResponse {
|
||||
series.addField({
|
||||
name: this.targets[0].timeField,
|
||||
type: FieldType.time,
|
||||
}).parse = (v: any) => {
|
||||
return v[0] || '';
|
||||
};
|
||||
});
|
||||
|
||||
if (logMessageField) {
|
||||
series.addField({
|
||||
|
@ -5,7 +5,7 @@ export class ElasticQueryBuilder {
|
||||
timeField: string;
|
||||
esVersion: number;
|
||||
|
||||
constructor(options: any) {
|
||||
constructor(options: { timeField: string; esVersion: number }) {
|
||||
this.timeField = options.timeField;
|
||||
this.esVersion = options.esVersion;
|
||||
}
|
||||
@ -129,11 +129,6 @@ export class ElasticQueryBuilder {
|
||||
}
|
||||
|
||||
query.script_fields = {};
|
||||
if (this.esVersion < 5) {
|
||||
query.fielddata_fields = [this.timeField];
|
||||
} else {
|
||||
query.docvalue_fields = [this.timeField];
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
|
@ -871,9 +871,6 @@ describe('ElasticResponse', () => {
|
||||
host: 'djisaodjsoad',
|
||||
message: 'hello, i am a message',
|
||||
},
|
||||
fields: {
|
||||
'@timestamp': ['2019-06-24T09:51:19.765Z'],
|
||||
},
|
||||
},
|
||||
{
|
||||
_id: 'kdospaidopa',
|
||||
@ -884,9 +881,6 @@ describe('ElasticResponse', () => {
|
||||
host: 'dsalkdakdop',
|
||||
message: 'hello, i am also message',
|
||||
},
|
||||
fields: {
|
||||
'@timestamp': ['2019-06-24T09:52:19.765Z'],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user