Prometheus: Variable query, allow for label values query type with label, label filters and no metric (#76472)

allow for label values query type with label, label filters and no metric
This commit is contained in:
Brendan O'Handley 2023-10-12 13:03:33 -04:00 committed by GitHub
parent 94ce87571d
commit c21e2bee1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -108,6 +108,27 @@ describe('PromVariableQueryEditor', () => {
expect(migration).toEqual(expected);
});
test('Migrates a query object with no metric and only label filters to an expression correctly', () => {
const query: PromVariableQuery = {
qryType: PromVariableQueryType.LabelValues,
label: 'name',
labelFilters: [
{
label: 'label',
op: '=',
value: 'value',
},
],
refId: 'PrometheusDatasource-VariableQuery',
};
const migration: string = migrateVariableEditorBackToVariableSupport(query);
const expected = 'label_values({label="value"},name)';
expect(migration).toEqual(expected);
});
beforeEach(() => {
props = {
datasource: {

View File

@ -50,7 +50,7 @@ export const PromVariableQueryEditor = ({ onChange, query, datasource }: Props)
// seriesQuery is only a whole
const [seriesQuery, setSeriesQuery] = useState('');
// the original variable query implementation
// the original variable query implementation, e.g. label_value(metric, label_name)
const [classicQuery, setClassicQuery] = useState('');
// list of label names for label_values(), /api/v1/labels, contains the same results as label_names() function

View File

@ -105,7 +105,7 @@ export function migrateVariableEditorBackToVariableSupport(QueryVariable: PromVa
}
return 'label_names()';
case QueryType.LabelValues:
if (QueryVariable.metric) {
if (QueryVariable.metric || (QueryVariable.labelFilters && QueryVariable.labelFilters.length !== 0)) {
const visualQueryQuery = {
metric: QueryVariable.metric,
labels: QueryVariable.labelFilters ?? [],