Skip to content

Commit

Permalink
Remove alerting from Prometheus if mimir is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinBisson committed Mar 12, 2024
1 parent ff54985 commit 1bfda39
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 45 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]

### Removed

- Remove alerting from Prometheus if mimir is enabled.

## [4.69.0] - 2024-03-12

### Changed
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/giantswarm/prometheus-meta-operator/v2

go 1.22.1
go 1.22.0

require (
github.com/Masterminds/sprig v2.22.0+incompatible
Expand Down
6 changes: 5 additions & 1 deletion service/controller/clusterapi/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/monitoring/scrapeconfigs"
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/monitoring/verticalpodautoscaler"
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/namespace"
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/noop"
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/rbac"
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/wrapper/monitoringdisabledresource"
"github.com/giantswarm/prometheus-meta-operator/v2/service/key"
Expand Down Expand Up @@ -352,7 +353,10 @@ func New(config Config) ([]resource.Interface, error) {
}

var alertmanagerWiringResource resource.Interface
{
// This resource creates a static secret to connect Prometheus to Alertmanager. When using mimir, this is not needed anymore
if config.MimirEnabled {
alertmanagerWiringResource = &noop.Resource{}
} else {
c := alertmanagerwiring.Config{
K8sClient: config.K8sClient,
Logger: config.Logger,
Expand Down
6 changes: 5 additions & 1 deletion service/controller/managementcluster/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/monitoring/scrapeconfigs"
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/monitoring/verticalpodautoscaler"
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/namespace"
noop "github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/noop"
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/rbac"
"github.com/giantswarm/prometheus-meta-operator/v2/service/controller/resource/wrapper/monitoringdisabledresource"
"github.com/giantswarm/prometheus-meta-operator/v2/service/key"
Expand Down Expand Up @@ -145,7 +146,10 @@ func newResources(config resourcesConfig) ([]resource.Interface, error) {
}

var alertmanagerWiringResource resource.Interface
{
// This resource creates a static secret to connect Prometheus to Alertmanager. When using mimir, this is not needed anymore
if config.MimirEnabled {
alertmanagerWiringResource = &noop.Resource{}
} else {
c := alertmanagerwiring.Config{
K8sClient: config.K8sClient,
Logger: config.Logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func getObjectMeta(ctx context.Context, v interface{}) (metav1.ObjectMeta, error
}, nil
}

func toData(v interface{}) []byte {
func toData() []byte {
return []byte(alertmanagerConfig)
}

Expand All @@ -86,7 +86,7 @@ func toSecret(ctx context.Context, v interface{}) (metav1.Object, error) {
secret := &corev1.Secret{
ObjectMeta: objectMeta,
Data: map[string][]byte{
key.AlertmanagerKey(): toData(v),
key.AlertmanagerKey(): toData(),
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAlertmanagerconfig(t *testing.T) {
OutputDir: outputDir,
T: t,
TestFunc: func(v interface{}) (interface{}, error) {
return toData(v), nil
return toData(), nil
},
TestFuncReturnsBytes: true,
Update: *update,
Expand Down
27 changes: 15 additions & 12 deletions service/controller/resource/monitoring/prometheus/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,10 @@ func toPrometheus(ctx context.Context, v interface{}, config Config) (metav1.Obj
if err != nil {
return nil, microerror.Mask(err)
}

prometheus := &promv1.Prometheus{
ObjectMeta: objectMeta,
Spec: promv1.PrometheusSpec{
// We need to use this to connect each WC prometheus with the central alertmanager instead of the alerting section of the Prometheus CR
// because the alerting section tries to find the alertmanager service in the workload cluster and not in the management cluster
// as it is using the secrets defined under prometheus.Spec.APIServerConfig.
//
// This forces us to use the static config defined in resource/alerting/alertmanagerwiring.
AdditionalAlertManagerConfigs: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: key.AlertmanagerSecretName(),
},
Key: key.AlertmanagerKey(),
},

CommonPrometheusFields: promv1.CommonPrometheusFields{
AdditionalScrapeConfigs: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Expand Down Expand Up @@ -400,6 +389,20 @@ func toPrometheus(ctx context.Context, v interface{}, config Config) (metav1.Obj
prometheus.Spec.ReplicaExternalLabelName = &emptyExternalLabels
prometheus.Spec.RuleNamespaceSelector = nil
prometheus.Spec.RuleSelector = nil
} else {
// We need to use this to connect each WC prometheus with the central alertmanager instead of the alerting section of the Prometheus CR
// because the alerting section tries to find the alertmanager service in the workload cluster and not in the management cluster
// as it is using the secrets defined under prometheus.Spec.APIServerConfig.
//
// This forces us to use the static config defined in resource/alerting/alertmanagerwiring.

// We enable alertmanager on Prometheus only if mimir is not enabled
prometheus.Spec.AdditionalAlertManagerConfigs = &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: key.AlertmanagerSecretName(),
},
Key: key.AlertmanagerKey(),
}
}

if config.PrometheusClient != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ metadata:
name: test-installation
namespace: test-installation-prometheus
spec:
additionalAlertManagerConfigs:
key: alertmanager-additional.yaml
name: alertmanager-config
additionalScrapeConfigs:
key: prometheus-additional.yaml
name: additional-scrape-configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ metadata:
name: baz
namespace: baz-prometheus
spec:
additionalAlertManagerConfigs:
key: alertmanager-additional.yaml
name: alertmanager-config
additionalScrapeConfigs:
key: prometheus-additional.yaml
name: additional-scrape-configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ metadata:
name: foo
namespace: foo-prometheus
spec:
additionalAlertManagerConfigs:
key: alertmanager-additional.yaml
name: alertmanager-config
additionalScrapeConfigs:
key: prometheus-additional.yaml
name: additional-scrape-configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ metadata:
name: eks-sample
namespace: eks-sample-prometheus
spec:
additionalAlertManagerConfigs:
key: alertmanager-additional.yaml
name: alertmanager-config
additionalScrapeConfigs:
key: prometheus-additional.yaml
name: additional-scrape-configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ metadata:
name: gcp-sample
namespace: gcp-sample-prometheus
spec:
additionalAlertManagerConfigs:
key: alertmanager-additional.yaml
name: alertmanager-config
additionalScrapeConfigs:
key: prometheus-additional.yaml
name: additional-scrape-configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ metadata:
name: kubernetes
namespace: kubernetes-prometheus
spec:
additionalAlertManagerConfigs:
key: alertmanager-additional.yaml
name: alertmanager-config
additionalScrapeConfigs:
key: prometheus-additional.yaml
name: additional-scrape-configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ metadata:
name: alice
namespace: alice-prometheus
spec:
additionalAlertManagerConfigs:
key: alertmanager-additional.yaml
name: alertmanager-config
additionalScrapeConfigs:
key: prometheus-additional.yaml
name: additional-scrape-configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ metadata:
name: baz
namespace: baz-prometheus
spec:
additionalAlertManagerConfigs:
key: alertmanager-additional.yaml
name: alertmanager-config
additionalScrapeConfigs:
key: prometheus-additional.yaml
name: additional-scrape-configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ metadata:
name: foo
namespace: foo-prometheus
spec:
additionalAlertManagerConfigs:
key: alertmanager-additional.yaml
name: alertmanager-config
additionalScrapeConfigs:
key: prometheus-additional.yaml
name: additional-scrape-configs
Expand Down
41 changes: 41 additions & 0 deletions service/controller/resource/noop/noop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package noop

import (
"context"

"github.com/giantswarm/micrologger"
)

const (
Name = "noop"
)

type Config struct {
Logger micrologger.Logger
}

type Resource struct {
logger micrologger.Logger
}

func New(config Config) (*Resource, error) {
r := &Resource{
logger: config.Logger,
}

return r, nil
}

func (r *Resource) Name() string {
return Name
}

func (r *Resource) EnsureCreated(ctx context.Context, obj interface{}) error {
r.logger.Debugf(ctx, "noop create")
return nil
}

func (r *Resource) EnsureDeleted(ctx context.Context, obj interface{}) error {
r.logger.Debugf(ctx, "noop delete")
return nil
}

0 comments on commit 1bfda39

Please sign in to comment.