Loki: Fix hiding of series in table if labels have number values (#30185)
* Fix summing of label names for Loki * Add test
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
import { CircularDataFrame, FieldCache, FieldType, MutableDataFrame } from '@grafana/data';
|
import { CircularDataFrame, FieldCache, FieldType, MutableDataFrame } from '@grafana/data';
|
||||||
import { LokiStreamResult, LokiTailResponse, LokiStreamResponse, LokiResultType, TransformerOptions } from './types';
|
import {
|
||||||
|
LokiStreamResult,
|
||||||
|
LokiTailResponse,
|
||||||
|
LokiStreamResponse,
|
||||||
|
LokiResultType,
|
||||||
|
TransformerOptions,
|
||||||
|
LokiMatrixResult,
|
||||||
|
} from './types';
|
||||||
import * as ResultTransformer from './result_transformer';
|
import * as ResultTransformer from './result_transformer';
|
||||||
import { enhanceDataFrame, lokiPointsToTimeseriesPoints } from './result_transformer';
|
import { enhanceDataFrame, lokiPointsToTimeseriesPoints } from './result_transformer';
|
||||||
import { setTemplateSrv } from '@grafana/runtime';
|
import { setTemplateSrv } from '@grafana/runtime';
|
||||||
@@ -209,6 +216,20 @@ describe('loki result transformer', () => {
|
|||||||
expect(label).toBe('label1');
|
expect(label).toBe('label1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('lokiResultsToTableModel', () => {
|
||||||
|
it('should correctly set the type of the label column to be a string', () => {
|
||||||
|
const lokiResultWithIntLabel = ([
|
||||||
|
{ metric: { test: 1 }, value: [1610367143, 10] },
|
||||||
|
{ metric: { test: 2 }, value: [1610367144, 20] },
|
||||||
|
] as unknown) as LokiMatrixResult[];
|
||||||
|
|
||||||
|
const table = ResultTransformer.lokiResultsToTableModel(lokiResultWithIntLabel, 1, 'A', {});
|
||||||
|
expect(table.columns[0].type).toBe('time');
|
||||||
|
expect(table.columns[1].type).toBe('string');
|
||||||
|
expect(table.columns[2].type).toBe('number');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('enhanceDataFrame', () => {
|
describe('enhanceDataFrame', () => {
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ export function lokiResultsToTableModel(
|
|||||||
table.meta = meta;
|
table.meta = meta;
|
||||||
table.columns = [
|
table.columns = [
|
||||||
{ text: 'Time', type: FieldType.time },
|
{ text: 'Time', type: FieldType.time },
|
||||||
...sortedLabels.map(label => ({ text: label, filterable: true })),
|
...sortedLabels.map(label => ({ text: label, filterable: true, type: FieldType.string })),
|
||||||
{ text: resultCount > 1 || valueWithRefId ? `Value #${refId}` : 'Value', type: FieldType.number },
|
{ text: resultCount > 1 || valueWithRefId ? `Value #${refId}` : 'Value', type: FieldType.number },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user