mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Provisioning: Allows specifying uid for datasource and use that in derived fields (#23585)
* Add uid to datasource * Fix uid passing when provisioning * Better error handling and Uid column type change * Fix test and strict null error counts * Add backend tests * Add tests * Fix strict null checks * Update test * Improve tests * Update pkg/services/sqlstore/datasource.go Co-Authored-By: Arve Knudsen <arve.knudsen@gmail.com> * Variable rename Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { CircularDataFrame, FieldType, MutableDataFrame } from '@grafana/data';
|
||||
import { CircularDataFrame, FieldCache, FieldType, MutableDataFrame } from '@grafana/data';
|
||||
import { LokiLegacyStreamResult, LokiStreamResult, LokiTailResponse } from './types';
|
||||
import * as ResultTransformer from './result_transformer';
|
||||
import { enhanceDataFrame } from './result_transformer';
|
||||
|
||||
const legacyStreamResult: LokiLegacyStreamResult[] = [
|
||||
{
|
||||
@@ -180,3 +181,29 @@ describe('loki result transformer', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('enhanceDataFrame', () => {
|
||||
it('', () => {
|
||||
const df = new MutableDataFrame({ fields: [{ name: 'line', values: ['nothing', 'trace1=1234', 'trace2=foo'] }] });
|
||||
enhanceDataFrame(df, {
|
||||
derivedFields: [
|
||||
{
|
||||
matcherRegex: 'trace1=(\\w+)',
|
||||
name: 'trace1',
|
||||
url: 'http://localhost/${__value.raw}',
|
||||
},
|
||||
{
|
||||
matcherRegex: 'trace2=(\\w+)',
|
||||
name: 'trace2',
|
||||
datasourceUid: 'uid',
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(df.fields.length).toBe(3);
|
||||
const fc = new FieldCache(df);
|
||||
expect(fc.getFieldByName('trace1').values.toArray()).toEqual([null, '1234', null]);
|
||||
expect(fc.getFieldByName('trace1').config.links[0]).toEqual({ url: 'http://localhost/${__value.raw}', title: '' });
|
||||
expect(fc.getFieldByName('trace2').values.toArray()).toEqual([null, null, 'foo']);
|
||||
expect(fc.getFieldByName('trace2').config.links[0]).toEqual({ title: '', meta: { datasourceUid: 'uid' } });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user