Loki: Add scopedVars support in legend formatting for repeated variables (#27046)

* Pass scoped vars to createMetricLabel

* Add tests

* Refacotr

* Update tests

* Update test
This commit is contained in:
Ivana Huckova
2020-08-19 08:28:50 +02:00
committed by GitHub
parent 918fb4d02a
commit eafc132d3d
4 changed files with 22 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
import { CircularDataFrame, FieldCache, FieldType, MutableDataFrame } from '@grafana/data';
import { LokiStreamResult, LokiTailResponse, LokiStreamResponse, LokiResultType } from './types';
import { LokiStreamResult, LokiTailResponse, LokiStreamResponse, LokiResultType, TransformerOptions } from './types';
import * as ResultTransformer from './result_transformer';
import { enhanceDataFrame } from './result_transformer';
@@ -114,6 +114,15 @@ describe('loki result transformer', () => {
});
});
});
describe('createMetricLabel', () => {
it('should create correct label based on passed variables', () => {
const label = ResultTransformer.createMetricLabel({}, ({
scopedVars: { testLabel: { selected: true, text: 'label1', value: 'label1' } },
legendFormat: '{{$testLabel}}',
} as unknown) as TransformerOptions);
expect(label).toBe('label1');
});
});
});
describe('enhanceDataFrame', () => {