Query splitting: combine nanos attribute con time fields (#73505)

pull/73569/head
Matias Chomicki 2 years ago committed by GitHub
parent 4c37ba494e
commit f7355668e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 75
      public/app/plugins/datasource/loki/responseUtils.test.ts
  2. 4
      public/app/plugins/datasource/loki/responseUtils.ts

@ -403,6 +403,81 @@ describe('combineResponses', () => {
expect(combined.errors?.[1]?.message).toBe('errorB');
});
it('combines frames with nanoseconds', () => {
const { logFrameA, logFrameB } = getMockFrames();
logFrameA.fields[0].nanos = [333333, 444444];
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, 333333, 444444],
},
{
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 => ({

@ -203,6 +203,10 @@ function combineFrames(dest: DataFrame, source: DataFrame) {
const totalFields = dest.fields.length;
for (let i = 0; i < totalFields; i++) {
dest.fields[i].values = [].concat.apply(source.fields[i].values, dest.fields[i].values);
if (source.fields[i].nanos) {
const nanos: number[] = dest.fields[i].nanos?.slice() || [];
dest.fields[i].nanos = source.fields[i].nanos?.concat(nanos);
}
}
dest.length += source.length;
dest.meta = {

Loading…
Cancel
Save