mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Legacy annotations: add dataplane support (#96226)
This commit is contained in:
parent
580d073b96
commit
68db1c6e68
@ -442,9 +442,74 @@ describe('LokiDatasource', () => {
|
||||
expect(res.length).toBe(2);
|
||||
expect(res[0].text).toBe('hello');
|
||||
expect(res[0].tags).toEqual(['value']);
|
||||
expect(res[0].time).toEqual(1);
|
||||
|
||||
expect(res[1].text).toBe('hello 2');
|
||||
expect(res[1].tags).toEqual(['value2']);
|
||||
expect(res[1].time).toEqual(2);
|
||||
});
|
||||
|
||||
it('should transform the loki dataplane data to annotation response', async () => {
|
||||
const originalDataplaneState = config.featureToggles.lokiLogsDataplane;
|
||||
config.featureToggles.lokiLogsDataplane = true;
|
||||
const testFrame: DataFrame = {
|
||||
refId: 'A',
|
||||
fields: [
|
||||
{
|
||||
name: 'timestamp',
|
||||
type: FieldType.time,
|
||||
config: {},
|
||||
values: [1, 2],
|
||||
},
|
||||
{
|
||||
name: 'body',
|
||||
type: FieldType.string,
|
||||
config: {},
|
||||
values: ['hello', 'hello 2'],
|
||||
},
|
||||
{
|
||||
name: 'labels',
|
||||
type: FieldType.other,
|
||||
config: {},
|
||||
values: [
|
||||
{
|
||||
label: 'value',
|
||||
label2: 'value ',
|
||||
},
|
||||
{
|
||||
label: '',
|
||||
label2: 'value2',
|
||||
label3: ' ',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'tsNs',
|
||||
type: FieldType.string,
|
||||
config: {},
|
||||
values: ['1000000', '2000000'],
|
||||
},
|
||||
{
|
||||
name: 'id',
|
||||
type: FieldType.string,
|
||||
config: {},
|
||||
values: ['id1', 'id2'],
|
||||
},
|
||||
],
|
||||
length: 2,
|
||||
};
|
||||
const res = await getTestContext(testFrame, { stepInterval: '15s' });
|
||||
|
||||
expect(res.length).toBe(2);
|
||||
expect(res[0].text).toBe('hello');
|
||||
expect(res[0].tags).toEqual(['value']);
|
||||
expect(res[0].time).toEqual(1);
|
||||
|
||||
expect(res[1].text).toBe('hello 2');
|
||||
expect(res[1].tags).toEqual(['value2']);
|
||||
expect(res[1].time).toEqual(2);
|
||||
|
||||
config.featureToggles.lokiLogsDataplane = originalDataplaneState;
|
||||
});
|
||||
|
||||
describe('Formatting', () => {
|
||||
|
@ -1042,8 +1042,12 @@ export class LokiDatasource
|
||||
const annotations: AnnotationEvent[] = [];
|
||||
const splitKeys: string[] = tagKeys.split(',').filter((v: string) => v !== '');
|
||||
|
||||
const isDataplaneLog = config.featureToggles.lokiLogsDataplane;
|
||||
|
||||
for (const frame of data) {
|
||||
const view = new DataFrameView<{ Time: string; Line: string; labels: Labels }>(frame);
|
||||
const view = new DataFrameView<{ timestamp: string; Time: string; body: string; Line: string; labels: Labels }>(
|
||||
frame
|
||||
);
|
||||
|
||||
view.forEach((row) => {
|
||||
const { labels } = row;
|
||||
@ -1063,15 +1067,17 @@ export class LokiDatasource
|
||||
|
||||
return true;
|
||||
})
|
||||
.map(([key, val]) => val); // keep only the label-value
|
||||
.map(([_, val]) => val); // keep only the label-value
|
||||
|
||||
// remove duplicates
|
||||
const tags = Array.from(new Set(maybeDuplicatedTags));
|
||||
|
||||
const logLine = isDataplaneLog ? row.body : row.Line;
|
||||
|
||||
annotations.push({
|
||||
time: new Date(row.Time).valueOf(),
|
||||
time: isDataplaneLog ? new Date(row.timestamp).valueOf() : new Date(row.Time).valueOf(),
|
||||
title: renderLegendFormat(titleFormat, labels),
|
||||
text: renderLegendFormat(textFormat, labels) || row.Line,
|
||||
text: renderLegendFormat(textFormat, labels) || logLine,
|
||||
tags,
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user