feat(alerting): enable loki query optimization by default (#74739)

This commit is contained in:
Jean-Philippe Quéméner
2023-09-13 13:52:40 +02:00
committed by GitHub
parent 99be6fb747
commit f3b6d01306
6 changed files with 5 additions and 23 deletions

View File

@@ -10,7 +10,6 @@ import (
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/folder"
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
"github.com/grafana/grafana/pkg/services/search/model"
@@ -540,7 +539,6 @@ func (st DBstore) GetAlertRulesForScheduling(ctx context.Context, query *ngmodel
st.Logger.Error("Unable to close rows session", "error", err)
}
}()
lokiRangeToInstantEnabled := st.FeatureToggles.IsEnabled(featuremgmt.FlagAlertingLokiRangeToInstant)
// Deserialize each rule separately in case any of them contain invalid JSON.
for rows.Next() {
rule := new(ngmodels.AlertRule)
@@ -553,13 +551,11 @@ func (st DBstore) GetAlertRulesForScheduling(ctx context.Context, query *ngmodel
// In previous versions of Grafana, Loki datasources would default to range queries
// instead of instant queries, sometimes creating unnecessary load. This is only
// done for Grafana Cloud.
if lokiRangeToInstantEnabled {
if indices, migratable := canBeInstant(rule); migratable {
if err := migrateToInstant(rule, indices); err != nil {
st.Logger.Error("Could not migrate rule from range to instant query", "rule", rule.UID, "err", err)
} else {
st.Logger.Info("Migrated rule from range to instant query", "rule", rule.UID, "migrated_queries", len(indices))
}
if indices, migratable := canBeInstant(rule); migratable {
if err := migrateToInstant(rule, indices); err != nil {
st.Logger.Error("Could not migrate rule from range to instant query", "rule", rule.UID, "err", err)
} else {
st.Logger.Info("Migrated rule from range to instant query", "rule", rule.UID, "migrated_queries", len(indices))
}
}
rules = append(rules, rule)