Skip to content

Commit c043856

Browse files
authored
Merge pull request kubernetes-sigs#233 from DirectXMan12/features/client-go-metrics
✨ Expose client-go metrics
2 parents b44385d + ed6a18c commit c043856

File tree

6 files changed

+309
-34
lines changed

6 files changed

+309
-34
lines changed

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/internal/controller/controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,5 @@ func (c *Controller) InjectFunc(f inject.Func) error {
248248

249249
// updateMetrics updates prometheus metrics within the controller
250250
func (c *Controller) updateMetrics(reconcileTime time.Duration) {
251-
ctrlmetrics.QueueLength.WithLabelValues(c.Name).Set(float64(c.Queue.Len()))
252251
ctrlmetrics.ReconcileTime.WithLabelValues(c.Name).Observe(reconcileTime.Seconds())
253252
}

pkg/internal/controller/controller_test.go

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ var _ = Describe("controller", func() {
176176
Expect(ctrl.Watch(src, evthdl)).To(Equal(expected))
177177
})
178178

179-
It("should inject dependencies into the Reconciler", func() {
179+
PIt("should inject dependencies into the Reconciler", func() {
180180
// TODO(community): Write this
181181
})
182182

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

@@ -299,7 +299,7 @@ var _ = Describe("controller", func() {
299299
close(done)
300300
})
301301

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

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

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

398-
It("should return if the queue is shutdown", func() {
398+
PIt("should return if the queue is shutdown", func() {
399399
// TODO(community): write this test
400400
})
401401

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

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

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

534534
Context("should update prometheus metrics", func() {
535535
It("should requeue a Request if there is an error and continue processing items", func(done Done) {
536-
var queueLength, reconcileErrs dto.Metric
537-
ctrlmetrics.QueueLength.Reset()
538-
Expect(func() error {
539-
ctrlmetrics.QueueLength.WithLabelValues(ctrl.Name).Write(&queueLength)
540-
if queueLength.GetGauge().GetValue() != 0.0 {
541-
return fmt.Errorf("metric queue length not reset")
542-
}
543-
return nil
544-
}()).Should(Succeed())
545-
536+
var reconcileErrs dto.Metric
546537
ctrlmetrics.ReconcileErrors.Reset()
547538
Expect(func() error {
548539
ctrlmetrics.ReconcileErrors.WithLabelValues(ctrl.Name).Write(&reconcileErrs)
@@ -564,13 +555,6 @@ var _ = Describe("controller", func() {
564555

565556
By("Invoking Reconciler which will give an error")
566557
Expect(<-reconciled).To(Equal(request))
567-
Eventually(func() error {
568-
ctrlmetrics.QueueLength.WithLabelValues(ctrl.Name).Write(&queueLength)
569-
if queueLength.GetGauge().GetValue() != 1.0 {
570-
return fmt.Errorf("metric queue length not updated")
571-
}
572-
return nil
573-
}, 2.0).Should(Succeed())
574558
Eventually(func() error {
575559
ctrlmetrics.ReconcileErrors.WithLabelValues(ctrl.Name).Write(&reconcileErrs)
576560
if reconcileErrs.GetCounter().GetValue() != 1.0 {

pkg/internal/controller/metrics/metrics.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ import (
2222
)
2323

2424
var (
25-
// QueueLength is a prometheus metric which counts the current reconcile
26-
// queue length per controller
27-
QueueLength = prometheus.NewGaugeVec(prometheus.GaugeOpts{
28-
Name: "controller_runtime_reconcile_queue_length",
29-
Help: "Length of reconcile queue per controller",
30-
}, []string{"controller"})
31-
3225
// ReconcileTotal is a prometheus counter metrics which holds the total
3326
// number of reconciliations per controller. It has two labels. controller label refers
3427
// to the controller name and result label refers to the reconcile result i.e
@@ -55,7 +48,6 @@ var (
5548

5649
func init() {
5750
metrics.Registry.MustRegister(
58-
QueueLength,
5951
ReconcileTotal,
6052
ReconcileErrors,
6153
ReconcileTime,

0 commit comments

Comments
 (0)