From 73681a251efa505494893c725a5f81669dbc7b99 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Thu, 25 May 2023 15:09:44 +0200 Subject: [PATCH] Alerting: Add support for Alert State History Loki primary (#69065) add support for multiple ash targets with loki as primary --- packages/grafana-data/src/types/config.ts | 2 ++ packages/grafana-runtime/src/config.ts | 6 +++++- pkg/api/dtos/frontend_settings.go | 1 + pkg/api/frontendsettings.go | 1 + .../unified/hooks/useStateHistoryModal.tsx | 16 ++++++++++++---- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/grafana-data/src/types/config.ts b/packages/grafana-data/src/types/config.ts index 7331280cc1a..2b55c23bed6 100644 --- a/packages/grafana-data/src/types/config.ts +++ b/packages/grafana-data/src/types/config.ts @@ -64,6 +64,8 @@ export interface UnifiedAlertingConfig { minInterval: string; // will be undefined if alerStateHistory is not enabled alertStateHistoryBackend?: string; + // will be undefined if implementation is not "multiple" + alertStateHistoryPrimary?: string; } /** Supported OAuth services diff --git a/packages/grafana-runtime/src/config.ts b/packages/grafana-runtime/src/config.ts index f21b548ce33..4188c0a117c 100644 --- a/packages/grafana-runtime/src/config.ts +++ b/packages/grafana-runtime/src/config.ts @@ -130,7 +130,11 @@ export class GrafanaBootConfig implements GrafanaConfig { geomapDefaultBaseLayerConfig?: MapLayerOptions; geomapDisableCustomBaseLayer?: boolean; unifiedAlertingEnabled = false; - unifiedAlerting = { minInterval: '', alertStateHistoryBackend: undefined }; + unifiedAlerting = { + minInterval: '', + alertStateHistoryBackend: undefined, + alertStateHistoryPrimary: undefined, + }; applicationInsightsConnectionString?: string; applicationInsightsEndpointUrl?: string; recordedQueries = { diff --git a/pkg/api/dtos/frontend_settings.go b/pkg/api/dtos/frontend_settings.go index 770486f5798..182cc7a8370 100644 --- a/pkg/api/dtos/frontend_settings.go +++ b/pkg/api/dtos/frontend_settings.go @@ -64,6 +64,7 @@ type FrontendSettingsReportingDTO struct { type FrontendSettingsUnifiedAlertingDTO struct { MinInterval string `json:"minInterval"` AlertStateHistoryBackend string `json:"alertStateHistoryBackend,omitempty"` + AlertStateHistoryPrimary string `json:"alertStateHistoryPrimary,omitempty"` } // Enterprise-only diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index b3a2fb4b3b6..9172a84a436 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -236,6 +236,7 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro if hs.Cfg.UnifiedAlerting.StateHistory.Enabled { frontendSettings.UnifiedAlerting.AlertStateHistoryBackend = hs.Cfg.UnifiedAlerting.StateHistory.Backend + frontendSettings.UnifiedAlerting.AlertStateHistoryPrimary = hs.Cfg.UnifiedAlerting.StateHistory.MultiPrimary } if hs.Cfg.UnifiedAlerting.Enabled != nil { diff --git a/public/app/features/alerting/unified/hooks/useStateHistoryModal.tsx b/public/app/features/alerting/unified/hooks/useStateHistoryModal.tsx index c3c66d175a2..2d08ec52875 100644 --- a/public/app/features/alerting/unified/hooks/useStateHistoryModal.tsx +++ b/public/app/features/alerting/unified/hooks/useStateHistoryModal.tsx @@ -20,10 +20,18 @@ function useStateHistoryModal() { const styles = useStyles2(getStyles); - const implementation = - config.unifiedAlerting.alertStateHistoryBackend === StateHistoryImplementation.Loki - ? StateHistoryImplementation.Loki - : StateHistoryImplementation.Annotations; + // can be "loki", "multiple" or "annotations" + const stateHistoryBackend = config.unifiedAlerting.alertStateHistoryBackend; + // can be "loki" or "annotations" + const stateHistoryPrimary = config.unifiedAlerting.alertStateHistoryPrimary; + + // if "loki" is either the backend or the primary, show the new state history implementation + const usingNewAlertStateHistory = [stateHistoryBackend, stateHistoryPrimary].some( + (implementation) => implementation === StateHistoryImplementation.Loki + ); + const implementation = usingNewAlertStateHistory + ? StateHistoryImplementation.Loki + : StateHistoryImplementation.Annotations; const dismissModal = useCallback(() => { setRule(undefined);