Prometheus: Fix ad hoc filters when using explore table column filtering (#111141)
* add support for ad hoc filtering from explore * fix test * remove helper function and keep check in if statement
This commit is contained in:
@@ -66,6 +66,15 @@ describe('addLabelToQuery()', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should modify existing labels if the operator is different', () => {
|
||||
expect(addLabelToQuery(addLabelToQuery('foo{x="yy"}', 'bar', 'baz', '!='), 'bar', 'baz', '=')).toBe(
|
||||
'foo{x="yy", bar="baz"}'
|
||||
);
|
||||
expect(addLabelToQuery(addLabelToQuery('foo{x="yy"}', 'bar', 'baz', '='), 'bar', 'baz', '!=')).toBe(
|
||||
'foo{x="yy", bar!="baz"}'
|
||||
);
|
||||
});
|
||||
|
||||
it('should not remove filters', () => {
|
||||
expect(addLabelToQuery('{x="y"} |="yy"', 'bar', 'baz')).toBe('{x="y", bar="baz"} |="yy"');
|
||||
expect(addLabelToQuery('{x="y"} |="yy" !~"xx"', 'bar', 'baz')).toBe('{x="y", bar="baz"} |="yy" !~"xx"');
|
||||
|
||||
@@ -79,8 +79,17 @@ function addFilter(
|
||||
const start = query.substring(prev, match.from);
|
||||
const end = isLast ? query.substring(match.to) : '';
|
||||
|
||||
if (!labelExists(match.query.labels, filter)) {
|
||||
const labelToMatch = labelExists(match.query.labels, filter);
|
||||
if (labelToMatch) {
|
||||
// if label exists, check the operator, if it is different, update it.
|
||||
// We don't want to add duplicate labels.
|
||||
if (labelToMatch.op !== filter.op) {
|
||||
match.query.labels = match.query.labels.map((label) =>
|
||||
label.label === filter.label && label.value === filter.value ? filter : label
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// label does not exist, add as is.
|
||||
match.query.labels.push(filter);
|
||||
}
|
||||
const newLabels = renderQuery(match.query);
|
||||
|
||||
Reference in New Issue
Block a user