From 26bd6da21aa0cd1e9fa41af1fda3e3832ca95456 Mon Sep 17 00:00:00 2001 From: Santiago Date: Wed, 28 Aug 2024 15:05:47 +0200 Subject: [PATCH] (PoC) Use only Grafana MSTeams integration --- .../mimir-read-write-mode/config/mimir.yaml | 1 + .../docker-compose.jsonnet | 5 ++- .../mimir-read-write-mode/docker-compose.yml | 26 ++++-------- pkg/alertmanager/alertmanager.go | 41 ++++++++++++++++++- 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/development/mimir-read-write-mode/config/mimir.yaml b/development/mimir-read-write-mode/config/mimir.yaml index 0e5e0b1a442..37c9b9d5b11 100644 --- a/development/mimir-read-write-mode/config/mimir.yaml +++ b/development/mimir-read-write-mode/config/mimir.yaml @@ -56,6 +56,7 @@ alertmanager: data_dir: /data/alertmanager fallback_config_file: ./config/alertmanager-fallback-config.yaml external_url: http://localhost:8006/alertmanager + grafana_alertmanager_compatibility_enabled: true alertmanager_storage: s3: diff --git a/development/mimir-read-write-mode/docker-compose.jsonnet b/development/mimir-read-write-mode/docker-compose.jsonnet index efe33445083..a8ca550f274 100644 --- a/development/mimir-read-write-mode/docker-compose.jsonnet +++ b/development/mimir-read-write-mode/docker-compose.jsonnet @@ -6,8 +6,8 @@ std.manifestYamlDoc({ self.backend + self.nginx + self.minio + - self.grafana + - self.grafana_agent + + // self.grafana + + // self.grafana_agent + self.memcached + self.prometheus + {}, @@ -159,6 +159,7 @@ std.manifestYamlDoc({ './mimir', '-config.file=./config/mimir.yaml' % options, '-target=%(target)s' % options, + '-log.level=debug' % options, '-activity-tracker.filepath=/activity/%(name)s' % options, ], environment: [ diff --git a/development/mimir-read-write-mode/docker-compose.yml b/development/mimir-read-write-mode/docker-compose.yml index 08d31a521ca..defe53ee159 100644 --- a/development/mimir-read-write-mode/docker-compose.yml +++ b/development/mimir-read-write-mode/docker-compose.yml @@ -1,23 +1,4 @@ "services": - "grafana": - "environment": - - "GF_AUTH_ANONYMOUS_ENABLED=true" - - "GF_AUTH_ANONYMOUS_ORG_ROLE=Admin" - "image": "grafana/grafana:10.4.3" - "ports": - - "3000:3000" - "volumes": - - "./config/datasource-mimir.yaml:/etc/grafana/provisioning/datasources/mimir.yaml" - "grafana-agent": - "command": - - "-config.file=/etc/agent-config/grafana-agent.yaml" - - "-metrics.wal-directory=/tmp" - - "-server.http.address=127.0.0.1:9091" - "image": "grafana/agent:v0.37.3" - "ports": - - "9091:9091" - "volumes": - - "./config:/etc/agent-config" "memcached": "image": "memcached:1.6.19-alpine" "mimir-backend-1": @@ -28,6 +9,7 @@ - "./mimir" - "-config.file=./config/mimir.yaml" - "-target=backend" + - "-log.level=debug" - "-activity-tracker.filepath=/activity/mimir-backend-1" "depends_on": - "minio" @@ -47,6 +29,7 @@ - "./mimir" - "-config.file=./config/mimir.yaml" - "-target=backend" + - "-log.level=debug" - "-activity-tracker.filepath=/activity/mimir-backend-2" "depends_on": - "minio" @@ -66,6 +49,7 @@ - "./mimir" - "-config.file=./config/mimir.yaml" - "-target=read" + - "-log.level=debug" - "-activity-tracker.filepath=/activity/mimir-read-1" "depends_on": - "minio" @@ -85,6 +69,7 @@ - "./mimir" - "-config.file=./config/mimir.yaml" - "-target=read" + - "-log.level=debug" - "-activity-tracker.filepath=/activity/mimir-read-2" "depends_on": - "minio" @@ -104,6 +89,7 @@ - "./mimir" - "-config.file=./config/mimir.yaml" - "-target=write" + - "-log.level=debug" - "-activity-tracker.filepath=/activity/mimir-write-1" "depends_on": - "minio" @@ -124,6 +110,7 @@ - "./mimir" - "-config.file=./config/mimir.yaml" - "-target=write" + - "-log.level=debug" - "-activity-tracker.filepath=/activity/mimir-write-2" "depends_on": - "minio" @@ -144,6 +131,7 @@ - "./mimir" - "-config.file=./config/mimir.yaml" - "-target=write" + - "-log.level=debug" - "-activity-tracker.filepath=/activity/mimir-write-3" "depends_on": - "minio" diff --git a/pkg/alertmanager/alertmanager.go b/pkg/alertmanager/alertmanager.go index 7c82041a18a..99c1936c09e 100644 --- a/pkg/alertmanager/alertmanager.go +++ b/pkg/alertmanager/alertmanager.go @@ -27,6 +27,7 @@ import ( alertingNotify "github.com/grafana/alerting/notify" "github.com/grafana/alerting/notify/nfstatus" alertingReceivers "github.com/grafana/alerting/receivers" + "github.com/grafana/alerting/receivers/teams" alertingTemplates "github.com/grafana/alerting/templates" "github.com/grafana/dskit/flagext" "github.com/pkg/errors" @@ -643,7 +644,45 @@ func (am *Alertmanager) buildIntegrationsMap(gCfg *config.GlobalConfig, nc []*de } integrations, err = buildGrafanaReceiverIntegrations(emailCfg, alertingNotify.PostableAPIReceiverToAPIReceiver(rcv), gTmpl, am.logger) } else { - integrations, err = buildReceiverIntegrations(rcv.Receiver, tmpl, firewallDialer, am.logger, nw) + if len(rcv.MSTeamsConfigs) > 0 { + var grafanaIntegrationCfgs []*alertingNotify.GrafanaIntegrationConfig + // Translate into Grafana config. + for _, cfg := range rcv.MSTeamsConfigs { + gCfg := teams.Config{ + URL: cfg.WebhookURL.String(), + Message: cfg.Text, + Title: cfg.Title, + } + settings, err := json.Marshal(gCfg) + if err != nil { + return nil, err + } + + grafanaIntegrationCfgs = append(grafanaIntegrationCfgs, &alertingNotify.GrafanaIntegrationConfig{ + Name: rcv.Name, + Type: "teams", + DisableResolveMessage: !cfg.SendResolved(), + Settings: json.RawMessage(settings), + }) + } + gInts := alertingNotify.APIReceiver{ + GrafanaIntegrations: alertingNotify.GrafanaIntegrations{ + Integrations: grafanaIntegrationCfgs, + }, + } + // TODO: should we use the grafana tmpl struct? + integrations, err = buildGrafanaReceiverIntegrations(emailCfg, &gInts, tmpl, am.logger) + if err != nil { + return nil, err + } + } + // Empty the Teams configs so we don't create upstream integrations. + rcv.MSTeamsConfigs = nil + gIntegrations, err := buildReceiverIntegrations(rcv.Receiver, tmpl, firewallDialer, am.logger, nw) + if err != nil { + return nil, err + } + integrations = append(integrations, gIntegrations...) } if err != nil { return nil, err