Prometheus: Retain time field's interval with Table formatted queries (#93065)

This commit is contained in:
Leon Sorokin 2024-09-08 13:18:58 -05:00 committed by GitHub
parent c43bd82c92
commit fc4b3a2b03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -1213,4 +1213,21 @@ describe('Prometheus Result Transformer', () => {
expect(transformedTableDataFrames[1].meta?.executedQueryString).toEqual(executedQueryForRefB);
});
});
it("transforms dataFrame and retains time field's `config.interval`", () => {
const df = createDataFrame({
refId: 'A',
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3], config: { interval: 1 } },
{
name: 'value',
type: FieldType.number,
values: [5, 10, 5],
},
],
});
const tableDf = transformDFToTable([df])[0];
expect(tableDf.fields[0].config.interval).toEqual(1);
});
});

View File

@ -212,6 +212,8 @@ export function transformDFToTable(dfs: DataFrame[]): DataFrame[] {
// Fill valueField, timeField and labelFields with values
dataFramesByRefId[refId].forEach((df) => {
timeField.config.interval ??= df.fields[0]?.config.interval;
const timeFields = df.fields[0]?.values ?? [];
const dataFields = df.fields[1]?.values ?? [];
timeFields.forEach((value) => timeField.values.push(value));