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

pull/93075/head
Leon Sorokin 9 months ago committed by GitHub
parent c43bd82c92
commit fc4b3a2b03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      packages/grafana-prometheus/src/result_transformer.test.ts
  2. 2
      packages/grafana-prometheus/src/result_transformer.ts

@ -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);
});
});

@ -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));

Loading…
Cancel
Save