From 1b2108001f82c55f4d5b7a36fd188300045c60ca Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Mon, 29 Oct 2018 14:04:45 +0200 Subject: [PATCH] Add Prometheus registry flag to recorder - fix tests --- pkg/controller/controller.go | 2 +- pkg/controller/recorder.go | 11 +++++++---- pkg/controller/scheduler_test.go | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 0d8519cda..4f62899b1 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -83,7 +83,7 @@ func NewController( metricsServer: metricServer, } - recorder := NewCanaryRecorder() + recorder := NewCanaryRecorder(true) ctrl := &Controller{ kubeClient: kubeClient, diff --git a/pkg/controller/recorder.go b/pkg/controller/recorder.go index 837b1eada..cf967e122 100644 --- a/pkg/controller/recorder.go +++ b/pkg/controller/recorder.go @@ -13,22 +13,25 @@ type CanaryRecorder struct { weight *prometheus.GaugeVec } -// NewCanaryRecorder registers the Prometheus metrics -func NewCanaryRecorder() CanaryRecorder { +// NewCanaryRecorder creates a new recorder and registers the Prometheus metrics +func NewCanaryRecorder(register bool) CanaryRecorder { // 0 - running, 1 - successful, 2 - failed status := prometheus.NewGaugeVec(prometheus.GaugeOpts{ Subsystem: controllerAgentName, Name: "canary_status", Help: "Last canary analysis result", }, []string{"name", "namespace"}) - prometheus.MustRegister(status) weight := prometheus.NewGaugeVec(prometheus.GaugeOpts{ Subsystem: controllerAgentName, Name: "canary_weight", Help: "The virtual service destination weight current value", }, []string{"workload", "namespace"}) - prometheus.MustRegister(weight) + + if register { + prometheus.MustRegister(status) + prometheus.MustRegister(weight) + } return CanaryRecorder{ status: status, diff --git a/pkg/controller/scheduler_test.go b/pkg/controller/scheduler_test.go index 401bc63f6..2653af4a5 100644 --- a/pkg/controller/scheduler_test.go +++ b/pkg/controller/scheduler_test.go @@ -62,7 +62,7 @@ func TestScheduler_Init(t *testing.T) { deployer: deployer, router: router, observer: observer, - recorder: NewCanaryRecorder(), + recorder: NewCanaryRecorder(false), } ctrl.flaggerSynced = alwaysReady @@ -116,7 +116,7 @@ func TestScheduler_NewRevision(t *testing.T) { deployer: deployer, router: router, observer: observer, - recorder: NewCanaryRecorder(), + recorder: NewCanaryRecorder(false), } ctrl.flaggerSynced = alwaysReady