Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metrics UI] Clear threshold alert groups state when filterQuery changes #116205

Merged
merged 3 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,50 @@ describe('The metric threshold alert type', () => {
);
expect(stateResult3.groups).toEqual(expect.arrayContaining(['a', 'b']));
});

const executeWithFilter = (
comparator: Comparator,
threshold: number[],
filterQuery: string,
metric?: string,
state?: any
) =>
executor({
...mockOptions,
services,
params: {
groupBy: ['something'],
criteria: [
{
...baseNonCountCriterion,
comparator,
threshold,
metric: metric ?? baseNonCountCriterion.metric,
},
],
},
state: state ?? mockOptions.state.wrapped,
});
test('persists previous groups that go missing, until the filterQuery param changes', async () => {
const stateResult1 = await executeWithFilter(Comparator.GT, [0.75], 'query', 'test.metric.2');
expect(stateResult1.groups).toEqual(expect.arrayContaining(['a', 'b', 'c']));
const stateResult2 = await executeWithFilter(
Comparator.GT,
[0.75],
'query',
'test.metric.1',
stateResult1
);
expect(stateResult2.groups).toEqual(expect.arrayContaining(['a', 'b', 'c']));
const stateResult3 = await executeWithFilter(
Comparator.GT,
[0.75],
'different query',
'test.metric.1',
stateResult2
);
expect(stateResult3.groups).toEqual(expect.arrayContaining(['a', 'b']));
});
});

describe('querying with multiple criteria', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type MetricThresholdAlertTypeParams = Record<string, any>;
export type MetricThresholdAlertTypeState = AlertTypeState & {
groups: string[];
groupBy?: string | string[];
filterQuery?: string;
};
export type MetricThresholdAlertInstanceState = AlertInstanceState; // no specific instace state used
export type MetricThresholdAlertInstanceContext = AlertInstanceContext; // no specific instace state used
Expand Down Expand Up @@ -94,8 +95,11 @@ export const createMetricThresholdExecutor = (libs: InfraBackendLibs) =>
const config = source.configuration;

const previousGroupBy = state.groupBy;
const previousFilterQuery = state.filterQuery;
const prevGroups =
alertOnGroupDisappear && isEqual(previousGroupBy, params.groupBy)
alertOnGroupDisappear &&
isEqual(previousGroupBy, params.groupBy) &&
isEqual(previousFilterQuery, params.filterQuery)
? // Filter out the * key from the previous groups, only include it if it's one of
// the current groups. In case of a groupBy alert that starts out with no data and no
// groups, we don't want to persist the existence of the * alert instance
Expand Down Expand Up @@ -220,7 +224,7 @@ export const createMetricThresholdExecutor = (libs: InfraBackendLibs) =>
}
}

return { groups, groupBy: params.groupBy };
return { groups, groupBy: params.groupBy, filterQuery: params.filterQuery };
});

export const FIRED_ACTIONS = {
Expand Down