Prometheus: variable query editor interpolate variables in label values (#69735)

update regex for label values query type to support variable interpolation
pull/69749/head
Brendan O'Handley 2 years ago committed by GitHub
parent d31a9b66e4
commit 2656c06e0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      public/app/plugins/datasource/prometheus/components/VariableQueryEditor.test.tsx
  2. 2
      public/app/plugins/datasource/prometheus/migrations/variableMigration.ts

@ -29,6 +29,23 @@ describe('PromVariableQueryEditor', () => {
expect(migration).toEqual(expected);
});
test('Allows for use of variables to interpolate label names in the label values query type.', () => {
const query: StandardPromVariableQuery = {
query: 'label_values($label_name)',
refId: 'StandardVariableQuery',
};
const migration: PromVariableQuery = variableMigration(query);
const expected: PromVariableQuery = {
qryType: PromVariableQueryType.LabelValues,
label: '$label_name',
refId: 'PrometheusDatasource-VariableQuery',
};
expect(migration).toEqual(expected);
});
test('Migrates from jsonnet grafana as code variable to custom variable query', () => {
const query = 'label_names()';

@ -1,7 +1,7 @@
import { PromVariableQuery, PromVariableQueryType as QueryType } from '../types';
const labelNamesRegex = /^label_names\(\)\s*$/;
const labelValuesRegex = /^label_values\((?:(.+),\s*)?([a-zA-Z_][a-zA-Z0-9_]*)\)\s*$/;
const labelValuesRegex = /^label_values\((?:(.+),\s*)?([a-zA-Z_$][a-zA-Z0-9_]*)\)\s*$/;
const metricNamesRegex = /^metrics\((.+)\)\s*$/;
const queryResultRegex = /^query_result\((.+)\)\s*$/;

Loading…
Cancel
Save