diff --git a/public/app/plugins/datasource/prometheus/components/VariableQueryEditor.test.tsx b/public/app/plugins/datasource/prometheus/components/VariableQueryEditor.test.tsx index 407023c24d3..28325ff4d7b 100644 --- a/public/app/plugins/datasource/prometheus/components/VariableQueryEditor.test.tsx +++ b/public/app/plugins/datasource/prometheus/components/VariableQueryEditor.test.tsx @@ -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()'; diff --git a/public/app/plugins/datasource/prometheus/migrations/variableMigration.ts b/public/app/plugins/datasource/prometheus/migrations/variableMigration.ts index 17c44fb850a..f10987118c2 100644 --- a/public/app/plugins/datasource/prometheus/migrations/variableMigration.ts +++ b/public/app/plugins/datasource/prometheus/migrations/variableMigration.ts @@ -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*$/;