Alerting: Clamp Loki ASH range query to configured max_query_length (#83986)

* Clamp range in loki http client to configured max_query_length

Defaults to 721h to match Loki default
This commit is contained in:
William Wernert
2024-03-15 12:59:45 -04:00
committed by GitHub
parent f2628bfad4
commit 97f37b2e6f
6 changed files with 159 additions and 45 deletions

View File

@@ -60,6 +60,7 @@ const (
// DefaultRuleEvaluationInterval indicates a default interval of for how long a rule should be evaluated to change state from Pending to Alerting
DefaultRuleEvaluationInterval = SchedulerBaseInterval * 6 // == 60 seconds
stateHistoryDefaultEnabled = true
lokiDefaultMaxQueryLength = 721 * time.Hour // 30d1h, matches the default value in Loki
)
type UnifiedAlertingSettings struct {
@@ -134,6 +135,7 @@ type UnifiedAlertingStateHistorySettings struct {
// if one of them is set.
LokiBasicAuthPassword string
LokiBasicAuthUsername string
LokiMaxQueryLength time.Duration
MultiPrimary string
MultiSecondaries []string
ExternalLabels map[string]string
@@ -362,6 +364,7 @@ func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error {
LokiTenantID: stateHistory.Key("loki_tenant_id").MustString(""),
LokiBasicAuthUsername: stateHistory.Key("loki_basic_auth_username").MustString(""),
LokiBasicAuthPassword: stateHistory.Key("loki_basic_auth_password").MustString(""),
LokiMaxQueryLength: stateHistory.Key("loki_max_query_length").MustDuration(lokiDefaultMaxQueryLength),
MultiPrimary: stateHistory.Key("primary").MustString(""),
MultiSecondaries: splitTrim(stateHistory.Key("secondaries").MustString(""), ","),
ExternalLabels: stateHistoryLabels.KeysHash(),