Skip to content

Commit

Permalink
Revert "[Metrics UI] Fix OR logic on redundant groupBy detection (#11…
Browse files Browse the repository at this point in the history
…6695)" (#116820)

This reverts commit c0d005d.
  • Loading branch information
Zacqary authored Oct 29, 2021
1 parent 4712c10 commit 285cd00
Showing 1 changed file with 2 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,29 +260,22 @@ export const Expressions: React.FC<Props> = (props) => {
[alertParams.groupBy]
);

// Test to see if any of the group fields in groupBy are already filtered down to a single
// group by the filterQuery. If this is the case, then a groupBy is unnecessary, as it would only
// ever produce one group instance
const groupByFilterTestPatterns = useMemo(() => {
if (!alertParams.groupBy) return null;
const groups = !Array.isArray(alertParams.groupBy)
? [alertParams.groupBy]
: alertParams.groupBy;
return groups.map((group: string) => ({
groupName: group,
pattern: new RegExp(`{"match(_phrase)?":{"${group}":"(.*?)"}}`, 'g'),
pattern: new RegExp(`{"match(_phrase)?":{"${group}":"(.*?)"}}`),
}));
}, [alertParams.groupBy]);

const redundantFilterGroupBy = useMemo(() => {
if (!alertParams.filterQuery || !groupByFilterTestPatterns) return [];
return groupByFilterTestPatterns
.map(({ groupName, pattern }) => {
// Test to see if there is ONLY ONE match for this group in the query
// If there are 0 matches, then this query isn't filtering out any groups at all
// If there are 2+ matches, the query is using OR logic (e.g. group:a OR group:b) and will
// still allow for more than one groupBy alert instance.
if (alertParams.filterQuery!.match(pattern)?.length === 1) {
if (pattern.test(alertParams.filterQuery!)) {
return groupName;
}
})
Expand Down

0 comments on commit 285cd00

Please sign in to comment.