From bcd2c94d0a8fb3238dbac0081ce7f1c6cc310fa1 Mon Sep 17 00:00:00 2001 From: Quentin Bisson Date: Mon, 3 Jun 2024 12:02:16 +0200 Subject: [PATCH] Mimir enabled: Delete per cluster heartbeats (#1631) Signed-off-by: QuentinBisson --- CHANGELOG.md | 4 ++++ service/controller/clusterapi/resource.go | 2 ++ service/controller/managementcluster/resource.go | 2 ++ service/controller/resource/alerting/heartbeat/create.go | 5 +++++ service/controller/resource/alerting/heartbeat/resource.go | 5 +++++ .../resource/alerting/heartbeatwebhookconfig/resource.go | 6 +++--- 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fbc006cb..f6d2fc1a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Delete per cluster heartbeats when Mimir is enabled. + ## [4.75.1] - 2024-05-23 ### Changed diff --git a/service/controller/clusterapi/resource.go b/service/controller/clusterapi/resource.go index a797c4150..25ec9eb4b 100644 --- a/service/controller/clusterapi/resource.go +++ b/service/controller/clusterapi/resource.go @@ -363,6 +363,8 @@ func New(config Config) ([]resource.Interface, error) { Installation: config.Installation, OpsgenieKey: config.OpsgenieKey, Pipeline: config.Pipeline, + + MimirEnabled: config.MimirEnabled, } heartbeatResource, err = heartbeat.New(c) diff --git a/service/controller/managementcluster/resource.go b/service/controller/managementcluster/resource.go index b1409600b..63ac67056 100644 --- a/service/controller/managementcluster/resource.go +++ b/service/controller/managementcluster/resource.go @@ -290,6 +290,8 @@ func newResources(config resourcesConfig) ([]resource.Interface, error) { Logger: config.Logger, OpsgenieKey: config.OpsgenieKey, Pipeline: config.Pipeline, + + MimirEnabled: config.MimirEnabled, } heartbeatResource, err = heartbeat.New(c) diff --git a/service/controller/resource/alerting/heartbeat/create.go b/service/controller/resource/alerting/heartbeat/create.go index e9a851648..c8b971654 100644 --- a/service/controller/resource/alerting/heartbeat/create.go +++ b/service/controller/resource/alerting/heartbeat/create.go @@ -8,6 +8,11 @@ import ( ) func (r *Resource) EnsureCreated(ctx context.Context, obj interface{}) error { + if r.mimirEnabled { + r.logger.Debugf(ctx, "mimir is enabled, deleting heartbeat if it exists") + return r.EnsureDeleted(ctx, obj) + } + desired, err := toHeartbeat(obj, r.installation, r.pipeline) if err != nil { return microerror.Mask(err) diff --git a/service/controller/resource/alerting/heartbeat/resource.go b/service/controller/resource/alerting/heartbeat/resource.go index 56084ee49..ec259a412 100644 --- a/service/controller/resource/alerting/heartbeat/resource.go +++ b/service/controller/resource/alerting/heartbeat/resource.go @@ -25,6 +25,8 @@ type Config struct { Installation string OpsgenieKey string Pipeline string + + MimirEnabled bool } type Resource struct { @@ -32,6 +34,8 @@ type Resource struct { heartbeatClient *heartbeat.Client installation string pipeline string + + mimirEnabled bool } func New(config Config) (*Resource, error) { @@ -64,6 +68,7 @@ func New(config Config) (*Resource, error) { heartbeatClient: client, installation: config.Installation, pipeline: config.Pipeline, + mimirEnabled: config.MimirEnabled, } return r, nil diff --git a/service/controller/resource/alerting/heartbeatwebhookconfig/resource.go b/service/controller/resource/alerting/heartbeatwebhookconfig/resource.go index ea0ebb130..4a4329430 100644 --- a/service/controller/resource/alerting/heartbeatwebhookconfig/resource.go +++ b/service/controller/resource/alerting/heartbeatwebhookconfig/resource.go @@ -39,7 +39,7 @@ func New(config Config) (*generic.Resource, error) { Logger: config.Logger, Name: Name, GetObjectMeta: func(ctx context.Context, v interface{}) (metav1.ObjectMeta, error) { - return getObjectMeta(v, config) + return getObjectMeta(v) }, GetDesiredObject: func(ctx context.Context, v interface{}) (metav1.Object, error) { return toAlertmanagerConfig(v, config) @@ -54,7 +54,7 @@ func New(config Config) (*generic.Resource, error) { return r, nil } -func getObjectMeta(v interface{}, config Config) (metav1.ObjectMeta, error) { +func getObjectMeta(v interface{}) (metav1.ObjectMeta, error) { cluster, err := key.ToCluster(v) if err != nil { return metav1.ObjectMeta{}, microerror.Mask(err) @@ -72,7 +72,7 @@ func toAlertmanagerConfig(v interface{}, config Config) (metav1.Object, error) { return nil, nil } - objectMeta, err := getObjectMeta(v, config) + objectMeta, err := getObjectMeta(v) if err != nil { return nil, microerror.Mask(err) }