Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PoC) Use only Grafana MSTeams integration #9123

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions development/mimir-read-write-mode/config/mimir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions development/mimir-read-write-mode/docker-compose.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
{},
Expand Down Expand Up @@ -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: [
Expand Down
26 changes: 7 additions & 19 deletions development/mimir-read-write-mode/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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":
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
41 changes: 40 additions & 1 deletion pkg/alertmanager/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading