-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Closed
Bug
Copy link
Labels
datasource/Prometheusgood first issueGood for newcomersGood for newcomersinternalfor issues made by grafanistasfor issues made by grafanistastype/bug
Description
If we have a query that contains a recording rule with an empty label matcher, expanding it fails. Because addLabelToQuery
functions is not expecting empty values.
See:
grafana/packages/grafana-prometheus/src/add_label_to_query.ts
Lines 24 to 26 in c65ef07
if (!key || !value) { | |
throw new Error('Need label to add to query.'); | |
} |
If we ignore that by simply removing that lines it works as expected. But this might affect other parts of the data source UI.
So before making any further changes we have to make sure everything is fine.
The error message when we try to expand
Uncaught Error: Need label to add to query.
Sa @ add_label_to_query.ts:25
(anonymous) @ language_utils.ts:191
Hl @ language_utils.ts:188
(anonymous) @ language_utils.ts:146
Wl @ language_utils.ts:129
modifyQuery @ datasource.ts:715
ie @ PromQueryField.tsx:135
A unit test to verify. Put it in language_utils.test.ts
under expandRecordingRules()
section
it('when there is an empty label value it should still be able to expand the rule', () => {
const query = `sum(max by (cluster, container) (pod_cpu:active:kube_limits{container!="", cluster=~"pink"}))`;
const mapping = {
'pod_cpu:active:kube_limits': {
expandedQuery: `kube_limits{job!="", resource="cpu"} * on (namespace, pod, cluster) group_left () max by (namespace, pod, cluster) ((kube_pod_status_phase{phase=~"Pending|Running"} == 1))`,
},
};
const expected = `sum(max by (cluster, container) (kube_limits{job!="", resource="cpu", container!="", cluster=~"pink"} * on (namespace, pod, cluster) group_left () max by (namespace, pod, cluster) ((kube_pod_status_phase{phase=~"Pending|Running", container!="", cluster=~"pink"} == 1))))`;
const result = expandRecordingRules(query, mapping);
expect(result).toBe(expected);
});
Metadata
Metadata
Assignees
Labels
datasource/Prometheusgood first issueGood for newcomersGood for newcomersinternalfor issues made by grafanistasfor issues made by grafanistastype/bug
Type
Projects
Status
Complete