Config updates cause alerting rules to forget firing state
If a config set is updated, all the rules it declares will forget their firing state, even if the rules are unchanged.
We also see this when alertmanager configs change.
This was the underlying cause for our alert tests being stuck in pending states. Our GitOps flow was pushing unnecessary, but unchanged, config updates to cortex. This causes the state of alert rules to be reset for the tenant.
Digging into this to see if this was something we could resolve within the cortex code base, it lead very quickly to the Prometheus code for the NewAlertingRule function. There does not seem to be with a somewhat cursory examination, a way to update an existing rule. Seeing as the Prometheus approach to config updates is to replace existing with new instances, it would seem rather drastic to propose a change in the Prometheus library code. Instead rather any effort should be around refactoring the logic used in the ruler to use a custom alert struct, based on Prom, but updatable perhaps.
Thanks for digging into this! Yes this issue is in part due to there being no easy way to do this in the underlying Prometheus APIs.
Prometheus has an open issue for persisting alert state across restarts, so a proposed change in behaviour might not be that outlandish!
An interesting development: there's an open PR to persist alerting state across restarts
Note that restarting the ruler process itself also causes the ActiveAt state to be lost.
Note the function to let us copy state from an old alert to a new one is exposed now, so we can fix the headline issue. Requires #929.