Skip to content

Commit

Permalink
Move Registerer to Config Struct in Notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
gouthamve committed Mar 31, 2017
1 parent af222b6 commit 0d0c9d5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 4 additions & 0 deletions cmd/prometheus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"unicode"

"github.com/asaskevich/govalidator"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/config"
Expand Down Expand Up @@ -56,6 +57,9 @@ var cfg = struct {
prometheusURL string
}{
alertmanagerURLs: stringset{},
notifier: notifier.Options{
Registerer: prometheus.DefaultRegisterer,
},
}

// Value type for flags that are now unused, but which are kept around to
Expand Down
2 changes: 1 addition & 1 deletion cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Main() int {
reloadables = append(reloadables, remoteStorage)

var (
notifier = notifier.New(&cfg.notifier, prometheus.DefaultRegisterer)
notifier = notifier.New(&cfg.notifier)
targetManager = retrieval.NewTargetManager(sampleAppender)
queryEngine = promql.NewEngine(localStorage, &cfg.queryEngine)
ctx, cancelCtx = context.WithCancel(context.Background())
Expand Down
6 changes: 4 additions & 2 deletions notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type Options struct {
RelabelConfigs []*config.RelabelConfig
// Used for sending HTTP requests to the Alertmanager.
Do func(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)

Registerer prometheus.Registerer
}

type alertMetrics struct {
Expand Down Expand Up @@ -147,7 +149,7 @@ func newAlertMetrics(r prometheus.Registerer, o *Options) *alertMetrics {
}

// New constructs a new Notifier.
func New(o *Options, r prometheus.Registerer) *Notifier {
func New(o *Options) *Notifier {
ctx, cancel := context.WithCancel(context.Background())

if o.Do == nil {
Expand All @@ -160,7 +162,7 @@ func New(o *Options, r prometheus.Registerer) *Notifier {
cancel: cancel,
more: make(chan struct{}, 1),
opts: o,
metrics: newAlertMetrics(r, o),
metrics: newAlertMetrics(o.Registerer, o),
}
}

Expand Down
12 changes: 6 additions & 6 deletions notifier/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestPostPath(t *testing.T) {
}

func TestHandlerNextBatch(t *testing.T) {
h := New(&Options{}, prometheus.DefaultRegisterer)
h := New(&Options{})
defer unregisterMetrics()

for i := range make([]struct{}, 2*maxBatchSize+1) {
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestHandlerSendAll(t *testing.T) {
defer server1.Close()
defer server2.Close()

h := New(&Options{}, prometheus.DefaultRegisterer)
h := New(&Options{})
defer unregisterMetrics()
h.alertmanagers = append(h.alertmanagers, &alertmanagerSet{
ams: []alertmanager{
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestCustomDo(t *testing.T) {
Body: ioutil.NopCloser(nil),
}, nil
},
}, prometheus.DefaultRegisterer)
})
defer unregisterMetrics()

h.sendOne(context.Background(), nil, testURL, []byte(testBody))
Expand All @@ -250,7 +250,7 @@ func TestExternalLabels(t *testing.T) {
Replacement: "c",
},
},
}, prometheus.DefaultRegisterer)
})
defer unregisterMetrics()

// This alert should get the external label attached.
Expand Down Expand Up @@ -305,7 +305,7 @@ func TestHandlerRelabel(t *testing.T) {
Replacement: "renamed",
},
},
}, prometheus.DefaultRegisterer)
})
defer unregisterMetrics()

// This alert should be dropped due to the configuration
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestHandlerQueueing(t *testing.T) {

h := New(&Options{
QueueCapacity: 3 * maxBatchSize,
}, prometheus.DefaultRegisterer)
})
defer unregisterMetrics()
h.alertmanagers = append(h.alertmanagers, &alertmanagerSet{
ams: []alertmanager{
Expand Down

0 comments on commit 0d0c9d5

Please sign in to comment.