From fdb46268472e54dc913267811a6c19418e1733a1 Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Mon, 11 Dec 2023 15:49:35 +0100 Subject: [PATCH] =?UTF-8?q?Alerting:=20Fix=20UI=20inheriting=20mute=20timi?= =?UTF-8?q?ngs=20from=20parent=20when=20calculating=20the=20polic=E2=80=A6?= =?UTF-8?q?=20(#79295)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix UI inheriting mute timings from parent when calculating the policy tree properties * Add test for this use case --- .../notification-policies/Policy.test.tsx | 2 +- .../utils/notification-policies.test.ts | 19 +++++++++++++++++-- .../unified/utils/notification-policies.ts | 1 - 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/public/app/features/alerting/unified/components/notification-policies/Policy.test.tsx b/public/app/features/alerting/unified/components/notification-policies/Policy.test.tsx index 3631d7dfa068..88fece21e9f9 100644 --- a/public/app/features/alerting/unified/components/notification-policies/Policy.test.tsx +++ b/public/app/features/alerting/unified/components/notification-policies/Policy.test.tsx @@ -134,7 +134,7 @@ describe('Policy', () => { expect(within(secondPolicy).getByTestId('label-matchers')).toHaveTextContent(/^region \= EMEA$/); expect(within(secondPolicy).queryByTestId('continue-matching')).not.toBeInTheDocument(); expect(within(secondPolicy).queryByTestId('mute-timings')).not.toBeInTheDocument(); - expect(within(secondPolicy).getByTestId('inherited-properties')).toHaveTextContent('Inherited4 properties'); + expect(within(secondPolicy).getByTestId('inherited-properties')).toHaveTextContent('Inherited3 properties'); // third custom policy should be correct const thirdPolicy = customPolicies[2]; diff --git a/public/app/features/alerting/unified/utils/notification-policies.test.ts b/public/app/features/alerting/unified/utils/notification-policies.test.ts index 4880ee33098b..e5eb78e6706f 100644 --- a/public/app/features/alerting/unified/utils/notification-policies.test.ts +++ b/public/app/features/alerting/unified/utils/notification-policies.test.ts @@ -1,11 +1,11 @@ import { MatcherOperator, Route, RouteWithID } from 'app/plugins/datasource/alertmanager/types'; import { + computeInheritedTree, findMatchingRoutes, - normalizeRoute, getInheritedProperties, - computeInheritedTree, matchLabels, + normalizeRoute, } from './notification-policies'; import 'core-js/stable/structured-clone'; @@ -294,6 +294,21 @@ describe('getInheritedProperties()', () => { expect(childInherited).toHaveProperty('group_interval', '2m'); }); }); + it('should not inherit mute timings from parent route', () => { + const parent: Route = { + receiver: 'PARENT', + group_by: ['parentLabel'], + mute_time_intervals: ['Mon-Fri 09:00-17:00'], + }; + + const child: Route = { + receiver: 'CHILD', + group_by: ['childLabel'], + }; + + const childInherited = getInheritedProperties(parent, child); + expect(childInherited).not.toHaveProperty('mute_time_intervals'); + }); }); describe('computeInheritedTree', () => { diff --git a/public/app/features/alerting/unified/utils/notification-policies.ts b/public/app/features/alerting/unified/utils/notification-policies.ts index 81ce28223455..dceaf3ba201f 100644 --- a/public/app/features/alerting/unified/utils/notification-policies.ts +++ b/public/app/features/alerting/unified/utils/notification-policies.ts @@ -169,7 +169,6 @@ function getInheritedProperties( 'group_wait', 'group_interval', 'repeat_interval', - 'mute_time_intervals', ]); // TODO how to solve this TypeScript mystery?