Skip to content

Commit

Permalink
Add Prometheus registry flag to recorder
Browse files Browse the repository at this point in the history
- fix tests
  • Loading branch information
stefanprodan committed Oct 29, 2018
1 parent 3a28768 commit 1b21080
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewController(
metricsServer: metricServer,
}

recorder := NewCanaryRecorder()
recorder := NewCanaryRecorder(true)

ctrl := &Controller{
kubeClient: kubeClient,
Expand Down
11 changes: 7 additions & 4 deletions pkg/controller/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestScheduler_Init(t *testing.T) {
deployer: deployer,
router: router,
observer: observer,
recorder: NewCanaryRecorder(),
recorder: NewCanaryRecorder(false),
}
ctrl.flaggerSynced = alwaysReady

Expand Down Expand Up @@ -116,7 +116,7 @@ func TestScheduler_NewRevision(t *testing.T) {
deployer: deployer,
router: router,
observer: observer,
recorder: NewCanaryRecorder(),
recorder: NewCanaryRecorder(false),
}
ctrl.flaggerSynced = alwaysReady

Expand Down

0 comments on commit 1b21080

Please sign in to comment.