Loki: Create Variable Query Editor for Loki. (#54102)

* feat(loki-query-editor): create base editor component

* feat(loki-query-editor): update editor to use loki query type

* feat(loki-query-editor): add custom variable support to datasource

* feat(loki-query-editor): prevent errors when no label is present

* Add unit test for LokiMetricFindQuery

* Update datasource test

* Add component test

* Add variable query migration support

* feat(loki-query-editor): add migration support for older-format variables

* Fix enum capitalization for consistency

* Move attribute to the top of the class

* Remove unnecessary from()

* Update capitalization of new enum

* Fix enum capitalization in component

* feat(loki-query-editor): replace unnecessary class with class method
This commit is contained in:
Matias Chomicki
2022-08-30 18:18:51 +02:00
committed by GitHub
parent 4a707e2a88
commit 6e6069a2ba
10 changed files with 368 additions and 3 deletions

View File

@ -0,0 +1,48 @@
import { LokiVariableQuery, LokiVariableQueryType } from '../types';
import { migrateVariableQuery } from './variableQueryMigrations';
describe('Loki migrateVariableQuery()', () => {
it('Does not migrate LokiVariableQuery instances', () => {
const query: LokiVariableQuery = {
refId: 'test',
type: LokiVariableQueryType.LabelValues,
label: 'label',
stream: 'stream',
};
expect(migrateVariableQuery(query)).toBe(query);
expect(migrateVariableQuery(query)).toStrictEqual(query);
});
it('Migrates label_names() queries', () => {
const query = 'label_names()';
expect(migrateVariableQuery(query)).toStrictEqual({
refId: 'LokiVariableQueryEditor-VariableQuery',
type: LokiVariableQueryType.LabelNames,
});
});
it('Migrates label_values(label) queries', () => {
const query = 'label_values(label)';
expect(migrateVariableQuery(query)).toStrictEqual({
refId: 'LokiVariableQueryEditor-VariableQuery',
type: LokiVariableQueryType.LabelValues,
label: 'label',
stream: undefined,
});
});
it('Migrates label_values(log stream selector, label) queries', () => {
const query = 'label_values(log stream selector, label)';
expect(migrateVariableQuery(query)).toStrictEqual({
refId: 'LokiVariableQueryEditor-VariableQuery',
type: LokiVariableQueryType.LabelValues,
label: 'label',
stream: 'log stream selector',
});
});
});