Skip to content

Commit

Permalink
Merge pull request #233 from DirectXMan12/features/client-go-metrics
Browse files Browse the repository at this point in the history
✨ Expose client-go metrics
  • Loading branch information
k8s-ci-robot committed Jan 11, 2019
2 parents b44385d + ed6a18c commit c043856
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 34 deletions.
1 change: 1 addition & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,5 @@ func (c *Controller) InjectFunc(f inject.Func) error {

// updateMetrics updates prometheus metrics within the controller
func (c *Controller) updateMetrics(reconcileTime time.Duration) {
ctrlmetrics.QueueLength.WithLabelValues(c.Name).Set(float64(c.Queue.Len()))
ctrlmetrics.ReconcileTime.WithLabelValues(c.Name).Observe(reconcileTime.Seconds())
}
32 changes: 8 additions & 24 deletions pkg/internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ var _ = Describe("controller", func() {
Expect(ctrl.Watch(src, evthdl)).To(Equal(expected))
})

It("should inject dependencies into the Reconciler", func() {
PIt("should inject dependencies into the Reconciler", func() {
// TODO(community): Write this
})

It("should return an error if there is an error injecting into the Reconciler", func() {
PIt("should return an error if there is an error injecting into the Reconciler", func() {
// TODO(community): Write this
})

Expand Down Expand Up @@ -299,7 +299,7 @@ var _ = Describe("controller", func() {
close(done)
})

It("should forget an item if it is not a Request and continue processing items", func() {
PIt("should forget an item if it is not a Request and continue processing items", func() {
// TODO(community): write this test
})

Expand Down Expand Up @@ -391,19 +391,19 @@ var _ = Describe("controller", func() {
Eventually(func() int { return ctrl.Queue.NumRequeues(request) }).Should(Equal(0))
})

It("should forget the Request if Reconciler is successful", func() {
PIt("should forget the Request if Reconciler is successful", func() {
// TODO(community): write this test
})

It("should return if the queue is shutdown", func() {
PIt("should return if the queue is shutdown", func() {
// TODO(community): write this test
})

It("should wait for informers to be synced before processing items", func() {
PIt("should wait for informers to be synced before processing items", func() {
// TODO(community): write this test
})

It("should create a new go routine for MaxConcurrentReconciles", func() {
PIt("should create a new go routine for MaxConcurrentReconciles", func() {
// TODO(community): write this test
})

Expand Down Expand Up @@ -533,16 +533,7 @@ var _ = Describe("controller", func() {

Context("should update prometheus metrics", func() {
It("should requeue a Request if there is an error and continue processing items", func(done Done) {
var queueLength, reconcileErrs dto.Metric
ctrlmetrics.QueueLength.Reset()
Expect(func() error {
ctrlmetrics.QueueLength.WithLabelValues(ctrl.Name).Write(&queueLength)
if queueLength.GetGauge().GetValue() != 0.0 {
return fmt.Errorf("metric queue length not reset")
}
return nil
}()).Should(Succeed())

var reconcileErrs dto.Metric
ctrlmetrics.ReconcileErrors.Reset()
Expect(func() error {
ctrlmetrics.ReconcileErrors.WithLabelValues(ctrl.Name).Write(&reconcileErrs)
Expand All @@ -564,13 +555,6 @@ var _ = Describe("controller", func() {

By("Invoking Reconciler which will give an error")
Expect(<-reconciled).To(Equal(request))
Eventually(func() error {
ctrlmetrics.QueueLength.WithLabelValues(ctrl.Name).Write(&queueLength)
if queueLength.GetGauge().GetValue() != 1.0 {
return fmt.Errorf("metric queue length not updated")
}
return nil
}, 2.0).Should(Succeed())
Eventually(func() error {
ctrlmetrics.ReconcileErrors.WithLabelValues(ctrl.Name).Write(&reconcileErrs)
if reconcileErrs.GetCounter().GetValue() != 1.0 {
Expand Down
8 changes: 0 additions & 8 deletions pkg/internal/controller/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ import (
)

var (
// QueueLength is a prometheus metric which counts the current reconcile
// queue length per controller
QueueLength = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "controller_runtime_reconcile_queue_length",
Help: "Length of reconcile queue per controller",
}, []string{"controller"})

// ReconcileTotal is a prometheus counter metrics which holds the total
// number of reconciliations per controller. It has two labels. controller label refers
// to the controller name and result label refers to the reconcile result i.e
Expand All @@ -55,7 +48,6 @@ var (

func init() {
metrics.Registry.MustRegister(
QueueLength,
ReconcileTotal,
ReconcileErrors,
ReconcileTime,
Expand Down
Loading

0 comments on commit c043856

Please sign in to comment.