Skip to content

Commit

Permalink
Mimir enabled: Delete per cluster heartbeats (#1631)
Browse files Browse the repository at this point in the history
Signed-off-by: QuentinBisson <[email protected]>
  • Loading branch information
QuentinBisson authored Jun 3, 2024
1 parent 3596284 commit bcd2c94
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions service/controller/clusterapi/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions service/controller/managementcluster/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions service/controller/resource/alerting/heartbeat/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions service/controller/resource/alerting/heartbeat/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ type Config struct {
Installation string
OpsgenieKey string
Pipeline string

MimirEnabled bool
}

type Resource struct {
logger micrologger.Logger
heartbeatClient *heartbeat.Client
installation string
pipeline string

mimirEnabled bool
}

func New(config Config) (*Resource, error) {
Expand Down Expand Up @@ -64,6 +68,7 @@ func New(config Config) (*Resource, error) {
heartbeatClient: client,
installation: config.Installation,
pipeline: config.Pipeline,
mimirEnabled: config.MimirEnabled,
}

return r, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit bcd2c94

Please sign in to comment.