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

Alerting: Fix notification policies inheritance algorithm #69304

Merged
merged 13 commits into from
Jun 8, 2023

Conversation

gillesdemey
Copy link
Member

@gillesdemey gillesdemey commented May 31, 2023

What is this feature?

This PR fixes the inheritance algorithm to compute what properties are inherited from a parent policy in a child policy.

Additionally

This PR normalizes the behaviour of the notification policies API response between Mimir and the built-in Alertmanager / vanilla Alertmanager.

It also changes to way we write the config for inherit from parent, group_by: [] is only preserved in the configuration by Mimir – other implementations simply return undefined.


Note on grouping

There are several ways to define the group_by property of a notification policy, the following describes the values and their behaviour.

  • group_by: ['label'] is just regular grouping
  • group_by: [] means "inherit from parent" for child policies
  • group_by: [] means "single group" for the default (root) policy
  • group_by: <undefined> (the absence of the group_by key in the policy) inherits the grouping from the parent route
  • group_by: ['...'] means disable grouping

Special notes for your reviewer:

Please review the changes in the inheritance algorithm more closely than the rest of the PR – which is mostly updating the UI to take "no grouping" and "single group" semantics in to account.

I also moved that code to this file

Copy link
Member

@soniaAguilarPeiron soniaAguilarPeiron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!🚀

@gillesdemey gillesdemey force-pushed the alerting/fix-notification-policies-grouping-copy branch from c212a0d to 151a0bf Compare June 6, 2023 09:42
@gillesdemey gillesdemey force-pushed the alerting/fix-notification-policies-grouping-copy branch from f71c053 to 75f7f7f Compare June 6, 2023 10:02
since the behaviour is currently inconsistent between AM flavors and we're not sure which one is correct
@@ -6,7 +6,7 @@ interface Props {}

const Strong = ({ children }: React.PropsWithChildren<Props>) => {
const theme = useTheme2();
return <strong style={{ color: theme.colors.text.maxContrast }}>{children}</strong>;
return <strong style={{ color: theme.colors.text.primary }}>{children}</strong>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to the fix, but looks better :)

@gillesdemey gillesdemey changed the title Alerting: Fix notification policies empty grouping Alerting: Fix notification policies inheritance algorithm Jun 7, 2023
@gillesdemey gillesdemey requested a review from a team June 7, 2023 18:02
@grafanabot grafanabot added the type/ci Tasks related to Continuous Integration workflow label Jun 7, 2023
not sure how this one got updated
childRoute: Route,
propertiesParentInherited?: Partial<InhertitableProperties>
) {
const fullParentProperties = merge({}, parentRoute, propertiesParentInherited);
Copy link
Member Author

@gillesdemey gillesdemey Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So moving it to a new file makes it hard to make out the differences with the algorithm before, the quick version goes:

  1. we now compute the entire parent – with its inherited properties – before we create the inherited child properties
  2. we were previously merging the computed inherited properties with the parent's inherited properties – that's wrong
  3. since merge() mutates (ugh) I merge everything in to {} to avoid any weird mutation bugs
  4. we now also inherit from the parent if group_by is []

Copy link
Member

@soniaAguilarPeiron soniaAguilarPeiron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!🚀

@gillesdemey gillesdemey removed area/backend type/ci Tasks related to Continuous Integration workflow labels Jun 8, 2023
@gillesdemey gillesdemey merged commit f94e07f into main Jun 8, 2023
@gillesdemey gillesdemey deleted the alerting/fix-notification-policies-grouping-copy branch June 8, 2023 11:01
@grafanabot

This comment was marked as resolved.

@grafanabot grafanabot added the backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. label Jun 8, 2023
gillesdemey added a commit that referenced this pull request Jun 8, 2023
@gillesdemey
Copy link
Member Author

Back-port PR here 👉 #69782

gillesdemey added a commit that referenced this pull request Jun 8, 2023
…69782)

* Alerting: Fix notification policies inheritance algorithm (#69304)

(cherry picked from commit f94e07f)
@zerok zerok modified the milestones: 10.0.x, 10.0.1, 10.1.x Jun 20, 2023
@ricky-undeadcoders ricky-undeadcoders modified the milestones: 10.1.x, 10.1.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/alerting Grafana Alerting area/frontend backport v10.0.x backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. type/bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants