Skip to content

Commit 9a5d42d

Browse files
author
Ganesh Vernekar
committed
Fix alertmanager APIs
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
1 parent cb25e14 commit 9a5d42d

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

pkg/alertmanager/alertmanager.go

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package alertmanager
22

33
import (
4+
"context"
45
"fmt"
56
"net/http"
67
"net/url"
@@ -23,8 +24,6 @@ import (
2324
"github.com/prometheus/alertmanager/ui"
2425
"github.com/prometheus/client_golang/prometheus"
2526
"github.com/prometheus/common/route"
26-
"github.com/prometheus/prometheus/pkg/labels"
27-
"github.com/weaveworks/mesh"
2827
)
2928

3029
const notificationLogMaintenancePeriod = 15 * time.Minute
@@ -68,9 +67,6 @@ func New(cfg *Config) (*Alertmanager, error) {
6867
nflogID := fmt.Sprintf("nflog:%s", cfg.UserID)
6968
var err error
7069
am.nflog, err = nflog.New(
71-
nflog.WithMesh(func(g mesh.Gossiper) mesh.Gossip {
72-
return cfg.MeshRouter.newGossip(nflogID, g)
73-
}),
7470
nflog.WithRetention(cfg.Retention),
7571
nflog.WithSnapshot(filepath.Join(cfg.DataDir, nflogID)),
7672
nflog.WithMaintenance(notificationLogMaintenancePeriod, am.stop, am.wg.Done),
@@ -84,7 +80,7 @@ func New(cfg *Config) (*Alertmanager, error) {
8480
return nil, fmt.Errorf("failed to create notification log: %v", err)
8581
}
8682

87-
am.marker = types.NewMarker()
83+
am.marker = types.NewMarker(nil)
8884

8985
silencesID := fmt.Sprintf("silences:%s", cfg.UserID)
9086
am.silences, err = silence.New(silence.Options{
@@ -95,9 +91,6 @@ func New(cfg *Config) (*Alertmanager, error) {
9591
// For now, these metrics are ignored, as we can't register the same
9692
// metric twice with a single registry.
9793
Metrics: prometheus.NewRegistry(),
98-
Gossip: func(g mesh.Gossiper) mesh.Gossip {
99-
return cfg.MeshRouter.newGossip(silencesID, g)
100-
},
10194
})
10295
if err != nil {
10396
return nil, fmt.Errorf("failed to create silences: %v", err)
@@ -109,22 +102,18 @@ func New(cfg *Config) (*Alertmanager, error) {
109102
am.wg.Done()
110103
}()
111104

112-
marker := types.NewMarker()
113-
am.alerts, err = mem.NewAlerts(marker, 30*time.Minute)
105+
marker := types.NewMarker(nil)
106+
am.alerts, err = mem.NewAlerts(context.Background(), marker, 30*time.Minute, am.logger)
114107
if err != nil {
115108
return nil, fmt.Errorf("failed to create alerts: %v", err)
116109
}
117110

118-
am.api, err = api.New(
119-
am.alerts,
120-
am.silences,
121-
func(matchers []*labels.Matcher) dispatch.AlertOverview {
122-
return am.dispatcher.Groups(matchers)
123-
},
124-
marker.Status,
125-
nil, // Passing a nil mesh router since we don't show mesh router information in Cortex anyway.
126-
log.With(am.logger, "component", "api"),
127-
)
111+
am.api, err = api.New(api.Options{
112+
Alerts: am.alerts,
113+
Silences: am.silences,
114+
StatusFunc: marker.Status,
115+
Logger: log.With(am.logger, "component", "api"),
116+
})
128117
if err != nil {
129118
return nil, fmt.Errorf("failed to create api: %v", err)
130119
}
@@ -133,7 +122,7 @@ func New(cfg *Config) (*Alertmanager, error) {
133122

134123
webReload := make(chan chan error)
135124
ui.Register(am.router.WithPrefix(am.cfg.ExternalURL.Path), webReload, log.With(am.logger, "component", "ui"))
136-
am.api.Register(am.router.WithPrefix(path.Join(am.cfg.ExternalURL.Path, "/api")))
125+
am.api.Register(am.router, path.Join(am.cfg.ExternalURL.Path, "/api"))
137126

138127
go func() {
139128
for {
@@ -171,10 +160,7 @@ func (am *Alertmanager) ApplyConfig(userID string, conf *config.Config) error {
171160
}
172161
tmpl.ExternalURL = am.cfg.ExternalURL
173162

174-
err = am.api.Update(conf, time.Duration(conf.Global.ResolveTimeout))
175-
if err != nil {
176-
return err
177-
}
163+
am.api.Update(conf, nil)
178164

179165
am.inhibitor.Stop()
180166
am.dispatcher.Stop()
@@ -194,9 +180,9 @@ func (am *Alertmanager) ApplyConfig(userID string, conf *config.Config) error {
194180
tmpl,
195181
waitFunc,
196182
am.inhibitor,
197-
am.silences,
183+
silence.NewSilencer(am.silences, am.marker, am.logger),
198184
am.nflog,
199-
am.marker,
185+
nil,
200186
log.With(am.logger, "component", "pipeline"),
201187
)
202188
am.dispatcher = dispatch.NewDispatcher(

pkg/alertmanager/multitenant.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io/ioutil"
99
"net"
1010
"net/http"
11+
"net/url"
1112
"os"
1213
"path/filepath"
1314
"sort"
@@ -385,17 +386,25 @@ func (am *MultitenantAlertmanager) transformConfig(userID string, amConfig *amco
385386
if am.cfg.AutoSlackRoot != "" {
386387
for _, r := range amConfig.Receivers {
387388
for _, s := range r.SlackConfigs {
388-
if s.APIURL == autoSlackURL {
389-
s.APIURL = amconfig.Secret(am.cfg.AutoSlackRoot + "/" + userID + "/monitor")
389+
if s.APIURL.String() == autoSlackURL {
390+
u, err := url.Parse(am.cfg.AutoSlackRoot + "/" + userID + "/monitor")
391+
if err != nil {
392+
return nil, err
393+
}
394+
s.APIURL = &amconfig.SecretURL{URL: u}
390395
}
391396
}
392397
}
393398
}
394399
if am.cfg.AutoWebhookRoot != "" {
395400
for _, r := range amConfig.Receivers {
396401
for _, w := range r.WebhookConfigs {
397-
if w.URL == autoWebhookURL {
398-
w.URL = am.cfg.AutoWebhookRoot + "/" + userID + "/monitor"
402+
if w.URL.String() == autoWebhookURL {
403+
u, err := url.Parse(am.cfg.AutoWebhookRoot + "/" + userID + "/monitor")
404+
if err != nil {
405+
return nil, err
406+
}
407+
w.URL = &amconfig.URL{URL: u}
399408
}
400409
}
401410
}

0 commit comments

Comments
 (0)