mirror of
https://github.com/prometheus/prometheus
synced 2025-01-12 09:40:00 +00:00
Move Registerer to Config Struct in Notifier
This commit is contained in:
parent
af222b63fc
commit
0d0c9d5440
@ -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"
|
||||
@ -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
|
||||
|
@ -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())
|
||||
|
@ -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 {
|
||||
@ -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 {
|
||||
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
@ -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{
|
||||
@ -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))
|
||||
@ -250,7 +250,7 @@ func TestExternalLabels(t *testing.T) {
|
||||
Replacement: "c",
|
||||
},
|
||||
},
|
||||
}, prometheus.DefaultRegisterer)
|
||||
})
|
||||
defer unregisterMetrics()
|
||||
|
||||
// This alert should get the external label attached.
|
||||
@ -305,7 +305,7 @@ func TestHandlerRelabel(t *testing.T) {
|
||||
Replacement: "renamed",
|
||||
},
|
||||
},
|
||||
}, prometheus.DefaultRegisterer)
|
||||
})
|
||||
defer unregisterMetrics()
|
||||
|
||||
// This alert should be dropped due to the configuration
|
||||
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user