Skip to content

Commit

Permalink
fix(combineResponses): fix nanos recombination
Browse files Browse the repository at this point in the history
  • Loading branch information
matyax committed Aug 28, 2024
1 parent b90697a commit 4706de5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
75 changes: 75 additions & 0 deletions src/services/combineResponses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,81 @@ describe('combineResponses', () => {
});
});

it('combines frames wihtout nanoseconds with frames with nanoseconds', () => {
const { logFrameA, logFrameB } = getMockFrames();
logFrameA.fields[0].nanos = undefined;
logFrameB.fields[0].nanos = [111111, 222222];
const responseA: DataQueryResponse = {
data: [logFrameA],
};
const responseB: DataQueryResponse = {
data: [logFrameB],
};
expect(combineResponses(responseA, responseB)).toEqual({
data: [
{
fields: [
{
config: {},
name: 'Time',
type: 'time',
values: [1, 2, 3, 4],
nanos: [111111, 222222, 0, 0],
},
{
config: {},
name: 'Line',
type: 'string',
values: ['line3', 'line4', 'line1', 'line2'],
},
{
config: {},
name: 'labels',
type: 'other',
values: [
{
otherLabel: 'other value',
},
{
label: 'value',
},
{
otherLabel: 'other value',
},
],
},
{
config: {},
name: 'tsNs',
type: 'string',
values: ['1000000', '2000000', '3000000', '4000000'],
},
{
config: {},
name: 'id',
type: 'string',
values: ['id3', 'id4', 'id1', 'id2'],
},
],
length: 4,
meta: {
custom: {
frameType: 'LabeledTimeValues',
},
stats: [
{
displayName: 'Summary: total bytes processed',
unit: 'decbytes',
value: 33,
},
],
},
refId: 'A',
},
],
});
});

describe('combine stats', () => {
const { metricFrameA } = getMockFrames();
const makeResponse = (stats?: QueryResultMetaStat[]): DataQueryResponse => ({
Expand Down
2 changes: 1 addition & 1 deletion src/services/combineResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function mergeFrames(dest: DataFrame, source: DataFrame) {
// Insert in the `destIdx` position
dest.fields[f].values.splice(destIdx, 0, sourceField.values[i]);
if (sourceField.nanos) {
dest.fields[f].nanos = dest.fields[f].nanos ?? [];
dest.fields[f].nanos = dest.fields[f].nanos ?? new Array(dest.fields[f].values.length - 1).fill(0);
dest.fields[f].nanos?.splice(destIdx, 0, sourceField.nanos[i]);
}
}
Expand Down

0 comments on commit 4706de5

Please sign in to comment.