Skip to content

Commit

Permalink
fixed a bug where multiple SLA queries not handled correctly (#1910)
Browse files Browse the repository at this point in the history
* fixed a bug where multiple SLA queries not handled correctly

* added test
  • Loading branch information
yesoreyeram authored Nov 12, 2024
1 parent ccb89c5 commit b271949
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/datasource/responseHandler.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { FieldType, MutableDataFrame, TIME_SERIES_TIME_FIELD_NAME } from '@grafana/data';
import { convertToWide } from './responseHandler';

describe('convertToWide', () => {
it('merge multiple SLI frames correctly', () => {
let frames = convertToWide([
new MutableDataFrame({
name: 'SLI',
fields: [
{ name: TIME_SERIES_TIME_FIELD_NAME, values: [1], type: FieldType.time },
{ name: TIME_SERIES_TIME_FIELD_NAME, values: [1.1], type: FieldType.number },
],
}),
new MutableDataFrame({
name: 'SLI',
fields: [
{ name: TIME_SERIES_TIME_FIELD_NAME, values: [1], type: FieldType.time },
{ name: TIME_SERIES_TIME_FIELD_NAME, values: [1.2], type: FieldType.number },
],
}),
]);
expect(frames.length).toStrictEqual(1);
expect(frames[0].fields.length).toStrictEqual(3);
expect(frames[0].fields[0].values.at(0)).toStrictEqual(1);
expect(frames[0].fields[1].values.at(0)).toStrictEqual(1.1);
expect(frames[0].fields[2].values.at(0)).toStrictEqual(1.2);
});
});
5 changes: 4 additions & 1 deletion src/datasource/responseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ export function convertToWide(data: MutableDataFrame[]): DataFrame[] {
const fields: MutableField[] = [timeField];

for (let i = 0; i < data.length; i++) {
const valueField = data[i].fields.find((f) => f.name === TIME_SERIES_VALUE_FIELD_NAME);
let valueField = data[i].fields.find((f) => f.name === TIME_SERIES_VALUE_FIELD_NAME);
if (data[i].name === 'SLI') {
valueField = data[i].fields.find((f) => f.type === FieldType.number);
}
if (!valueField) {
continue;
}
Expand Down

0 comments on commit b271949

Please sign in to comment.