From f3b6d013066180745938284be61076ad2084fd2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Qu=C3=A9m=C3=A9ner?= Date: Wed, 13 Sep 2023 13:52:40 +0200 Subject: [PATCH] feat(alerting): enable loki query optimization by default (#74739) --- .../configure-grafana/feature-toggles/index.md | 1 - .../grafana-data/src/types/featureToggles.gen.ts | 1 - pkg/services/featuremgmt/registry.go | 7 ------- pkg/services/featuremgmt/toggles_gen.csv | 1 - pkg/services/featuremgmt/toggles_gen.go | 4 ---- pkg/services/ngalert/store/alert_rule.go | 14 +++++--------- 6 files changed, 5 insertions(+), 23 deletions(-) diff --git a/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md b/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md index a65b893f3e5..e59c698f2ef 100644 --- a/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md +++ b/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md @@ -117,7 +117,6 @@ Experimental features might be changed or removed without prior notice. | `exploreScrollableLogsContainer` | Improves the scrolling behavior of logs in Explore | | `recordedQueriesMulti` | Enables writing multiple items from a single query within Recorded Queries | | `pluginsDynamicAngularDetectionPatterns` | Enables fetching Angular detection patterns for plugins from GCOM and fallback to hardcoded ones | -| `alertingLokiRangeToInstant` | Rewrites eligible loki range queries to instant queries | | `vizAndWidgetSplit` | Split panels between vizualizations and widgets | | `prometheusIncrementalQueryInstrumentation` | Adds RudderStack events to incremental queries | | `logsExploreTableVisualisation` | A table visualisation for logs in Explore | diff --git a/packages/grafana-data/src/types/featureToggles.gen.ts b/packages/grafana-data/src/types/featureToggles.gen.ts index 7ae86dac25f..912b968ab9a 100644 --- a/packages/grafana-data/src/types/featureToggles.gen.ts +++ b/packages/grafana-data/src/types/featureToggles.gen.ts @@ -97,7 +97,6 @@ export interface FeatureToggles { exploreScrollableLogsContainer?: boolean; recordedQueriesMulti?: boolean; pluginsDynamicAngularDetectionPatterns?: boolean; - alertingLokiRangeToInstant?: boolean; vizAndWidgetSplit?: boolean; prometheusIncrementalQueryInstrumentation?: boolean; logsExploreTableVisualisation?: boolean; diff --git a/pkg/services/featuremgmt/registry.go b/pkg/services/featuremgmt/registry.go index 44c617df8e0..813093f3bbf 100644 --- a/pkg/services/featuremgmt/registry.go +++ b/pkg/services/featuremgmt/registry.go @@ -542,13 +542,6 @@ var ( FrontendOnly: false, Owner: grafanaPluginsPlatformSquad, }, - { - Name: "alertingLokiRangeToInstant", - Description: "Rewrites eligible loki range queries to instant queries", - Stage: FeatureStageExperimental, - FrontendOnly: false, - Owner: grafanaAlertingSquad, - }, { Name: "vizAndWidgetSplit", Description: "Split panels between vizualizations and widgets", diff --git a/pkg/services/featuremgmt/toggles_gen.csv b/pkg/services/featuremgmt/toggles_gen.csv index 780faa9780d..12d2d28ef27 100644 --- a/pkg/services/featuremgmt/toggles_gen.csv +++ b/pkg/services/featuremgmt/toggles_gen.csv @@ -78,7 +78,6 @@ cloudWatchLogsMonacoEditor,preview,@grafana/aws-datasources,false,false,false,tr exploreScrollableLogsContainer,experimental,@grafana/observability-logs,false,false,false,true recordedQueriesMulti,experimental,@grafana/observability-metrics,false,false,false,false pluginsDynamicAngularDetectionPatterns,experimental,@grafana/plugins-platform-backend,false,false,false,false -alertingLokiRangeToInstant,experimental,@grafana/alerting-squad,false,false,false,false vizAndWidgetSplit,experimental,@grafana/dashboards-squad,false,false,false,true prometheusIncrementalQueryInstrumentation,experimental,@grafana/observability-metrics,false,false,false,true logsExploreTableVisualisation,experimental,@grafana/observability-logs,false,false,false,true diff --git a/pkg/services/featuremgmt/toggles_gen.go b/pkg/services/featuremgmt/toggles_gen.go index 4756def629a..c30c4a47451 100644 --- a/pkg/services/featuremgmt/toggles_gen.go +++ b/pkg/services/featuremgmt/toggles_gen.go @@ -323,10 +323,6 @@ const ( // Enables fetching Angular detection patterns for plugins from GCOM and fallback to hardcoded ones FlagPluginsDynamicAngularDetectionPatterns = "pluginsDynamicAngularDetectionPatterns" - // FlagAlertingLokiRangeToInstant - // Rewrites eligible loki range queries to instant queries - FlagAlertingLokiRangeToInstant = "alertingLokiRangeToInstant" - // FlagVizAndWidgetSplit // Split panels between vizualizations and widgets FlagVizAndWidgetSplit = "vizAndWidgetSplit" diff --git a/pkg/services/ngalert/store/alert_rule.go b/pkg/services/ngalert/store/alert_rule.go index fdc0aaf7970..8cfd645c6df 100644 --- a/pkg/services/ngalert/store/alert_rule.go +++ b/pkg/services/ngalert/store/alert_rule.go @@ -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)