Skip to content

chore(AlertRuleGroup): Remove unnecessary requests during reconcile #2051

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Baarsgaard
Copy link
Collaborator

@Baarsgaard Baarsgaard commented Jun 16, 2025

Background

Noticed that the AlertRuleGroup reconciler would send 1 request per rule in the spec and thought it was a bit excessive.

It turns out that you can update all rules in a group at once by just updating the group, and if a rule is omitted from the update, it is then deleted.

But to create a rule, it is necessary to send POST for each new rule.
Knowing that, it was simple to just find the missing rules on a given instance and do the minimum GET and PUT requests to reconcile the difference.

Implementation

I would have liked to make smaller commits, but making individual commits that compiled and worked could not really be done easily.

  • The conversion to a Grafana compatible model has pulled out of the reconcile loop and is now done before any requests are made.
  • Existing rules are now updated at once with a PUT request on the group.
  • Deleted rules are removed in the same PUT request
  • New rules are created individually if missing on the remote instance
  • Provenance header is now always included, editable is still immutable and requires a recreate.
  • The array of rules now has a MinItems=1 requiring at least one rule to be defined.
    In the old implementation this would apply successfully but do nothing?

Number of requests sent to each Grafana instance during a reconcile*.

Scenario Before Now
New AlertRuleGroup created N+2 N+2
No changes N+2 2
1 new rule N+2 ΔN+2 = 1+2
2 new rules N+2 ΔN+2 = 2+2
1 Deleted rule N+1+2 2
2 Deleted rules N+2+2 2

N = number of rules in a group

*multiply by the number of instances for the total number of requests

I would appreciate individual testing as this is almost a rewrite of the reconcile function with a lot of changes.

@github-actions github-actions bot added the chore label Jun 16, 2025
@Baarsgaard Baarsgaard marked this pull request as ready for review June 17, 2025 11:45
@Baarsgaard Baarsgaard force-pushed the chore_simplify_alertrulegroup_reconcile branch from bd5cf18 to 1d2fb3a Compare June 17, 2025 20:15
@Baarsgaard Baarsgaard force-pushed the chore_simplify_alertrulegroup_reconcile branch from 1d2fb3a to 0207b6b Compare June 19, 2025 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant