Alerting: Improve notification policies view performance (#80209)

This commit is contained in:
Gilles De Mey 2024-01-16 15:30:25 +01:00 committed by GitHub
parent ddbe4d2bba
commit ea4bfc23ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -276,6 +276,12 @@ type RouteFilters = {
export const findRoutesMatchingFilters = (rootRoute: RouteWithID, filters: RouteFilters): RouteWithID[] => {
const { contactPointFilter, labelMatchersFilter = [] } = filters;
const hasFilter = contactPointFilter || labelMatchersFilter.length > 0;
// if filters are empty we short-circuit this function
if (!hasFilter) {
return [];
}
let matchedRoutes: RouteWithID[][] = [];

View File

@ -1,6 +1,7 @@
import { MatcherOperator, Route, RouteWithID } from 'app/plugins/datasource/alertmanager/types';
import {
InhertitableProperties,
computeInheritedTree,
findMatchingRoutes,
getInheritedProperties,
@ -203,6 +204,18 @@ describe('getInheritedProperties()', () => {
const childInherited = getInheritedProperties(parent, child);
expect(childInherited).toHaveProperty('group_by', ['label']);
});
// This scenario is technically impossible unless we have a bug in our code.
// A route cannot both specify a receiver and inherit it from its parent at the same time.
it('should inherit from parent instead of grandparent', () => {
const parent: Route = { receiver: 'parent' };
const parentInherited: InhertitableProperties = { receiver: 'grandparent', group_by: ['foo'] };
const child: Route = {};
const childInherited = getInheritedProperties(parent, child, parentInherited);
expect(childInherited).toHaveProperty('receiver', 'parent');
expect(childInherited.group_by).toEqual(['foo']);
});
});
describe('regular "undefined" values', () => {

View File

@ -160,9 +160,8 @@ function getInheritedProperties(
childRoute: Route,
propertiesParentInherited?: Partial<InhertitableProperties>
) {
const fullParentProperties = merge({}, parentRoute, propertiesParentInherited);
const inheritableProperties: InhertitableProperties = pick(fullParentProperties, INHERITABLE_KEYS);
const propsFromParent: InhertitableProperties = pick(parentRoute, INHERITABLE_KEYS);
const inheritableProperties: InhertitableProperties = merge({}, propertiesParentInherited, propsFromParent);
// TODO how to solve this TypeScript mystery?
const inherited = reduce(