Alerting: Move rule_groups_rules metric from State to Scheduler. (#63144)

The `rule_groups_rules` metric is currently defined and computed by `State`.
It makes more sense for this metric to be computed off of the configured rule
set, not based on the rule evaluation state. There could be an edge condition
where a rule does not have a state yet, and so is uncounted.

Additionally, we would like this metric (and others), to have a `rule_group`
label, and this is much easier to achieve if the metric is produced from the
`Scheduler` package.
This commit is contained in:
Steve Simpson
2023-02-09 17:05:19 +01:00
committed by GitHub
parent 90f8959d3c
commit 4d1a2c3370
5 changed files with 64 additions and 22 deletions

View File

@@ -2,7 +2,6 @@ package state
import (
"context"
"fmt"
"math"
"net/url"
"strings"
@@ -282,8 +281,7 @@ func (c *cache) recordMetrics(metrics *metrics.State) {
eval.Error: 0,
}
for org, orgMap := range c.states {
metrics.GroupRules.WithLabelValues(fmt.Sprint(org)).Set(float64(len(orgMap)))
for _, orgMap := range c.states {
for _, rule := range orgMap {
for _, state := range rule.states {
n := ct[state.State]