mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
94ce87571d
commit
c21e2bee1d
@ -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: {
|
||||
|
@ -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
|
||||
|
@ -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 ?? [],
|
||||
|
Loading…
Reference in New Issue
Block a user