@@ -410,14 +410,24 @@ var _ = Describe("controller", func() {
410
410
411
411
Context ("should update prometheus metrics" , func () {
412
412
It ("should requeue a Request if there is an error and continue processing items" , func (done Done ) {
413
- ctrlmetrics .QueueLength = prometheus .NewGaugeVec (prometheus.GaugeOpts {
414
- Name : "controller_runtime_reconcile_queue_length" ,
415
- Help : "Length of reconcile queue per controller" ,
416
- }, []string {"controller" })
417
- ctrlmetrics .ReconcileErrors = prometheus .NewCounterVec (prometheus.CounterOpts {
418
- Name : "controller_runtime_reconcile_errors_total" ,
419
- Help : "Total number of reconcile errors per controller" ,
420
- }, []string {"controller" })
413
+ var queueLength , reconcileErrs dto.Metric
414
+ ctrlmetrics .QueueLength .Reset ()
415
+ Expect (func () error {
416
+ ctrlmetrics .QueueLength .WithLabelValues (ctrl .Name ).Write (& queueLength )
417
+ if queueLength .GetGauge ().GetValue () != 0.0 {
418
+ return fmt .Errorf ("metrics not reset" )
419
+ }
420
+ return nil
421
+ }()).Should (Succeed ())
422
+
423
+ ctrlmetrics .ReconcileErrors .Reset ()
424
+ Expect (func () error {
425
+ ctrlmetrics .ReconcileErrors .WithLabelValues (ctrl .Name ).Write (& reconcileErrs )
426
+ if reconcileErrs .GetCounter ().GetValue () != 0.0 {
427
+ return fmt .Errorf ("metrics not reset" )
428
+ }
429
+ return nil
430
+ }()).Should (Succeed ())
421
431
422
432
fakeReconcile .Err = fmt .Errorf ("expected error: reconcile" )
423
433
go func () {
@@ -431,7 +441,6 @@ var _ = Describe("controller", func() {
431
441
432
442
By ("Invoking Reconciler which will give an error" )
433
443
Expect (<- reconciled ).To (Equal (request ))
434
- var queueLength , reconcileErrs dto.Metric
435
444
Eventually (func () error {
436
445
ctrlmetrics .QueueLength .WithLabelValues (ctrl .Name ).Write (& queueLength )
437
446
if queueLength .GetGauge ().GetValue () != 1.0 {
@@ -459,10 +468,18 @@ var _ = Describe("controller", func() {
459
468
}, 2.0 )
460
469
461
470
It ("should add a reconcile time to the reconcile time histogram" , func (done Done ) {
462
- ctrlmetrics .ReconcileTime = prometheus .NewHistogramVec (prometheus.HistogramOpts {
463
- Name : "controller_runtime_reconcile_time_second" ,
464
- Help : "Length of time per reconcile per controller" ,
465
- }, []string {"controller" })
471
+ var reconcileTime dto.Metric
472
+ ctrlmetrics .ReconcileTime .Reset ()
473
+
474
+ Expect (func () error {
475
+ histObserver := ctrlmetrics .ReconcileTime .WithLabelValues (ctrl .Name )
476
+ hist := histObserver .(prometheus.Histogram )
477
+ hist .Write (& reconcileTime )
478
+ if reconcileTime .GetHistogram ().GetSampleCount () != uint64 (0 ) {
479
+ return fmt .Errorf ("metrics not reset" )
480
+ }
481
+ return nil
482
+ }()).Should (Succeed ())
466
483
467
484
go func () {
468
485
defer GinkgoRecover ()
@@ -477,12 +494,11 @@ var _ = Describe("controller", func() {
477
494
Eventually (ctrl .Queue .Len ).Should (Equal (0 ))
478
495
Eventually (func () int { return ctrl .Queue .NumRequeues (request ) }).Should (Equal (0 ))
479
496
480
- var reconcileTime dto.Metric
481
497
Eventually (func () error {
482
498
histObserver := ctrlmetrics .ReconcileTime .WithLabelValues (ctrl .Name )
483
499
hist := histObserver .(prometheus.Histogram )
484
500
hist .Write (& reconcileTime )
485
- if reconcileTime .GetHistogram ().GetSampleCount () != uint64 (1 ) {
501
+ if reconcileTime .GetHistogram ().GetSampleCount () == uint64 (0 ) {
486
502
return fmt .Errorf ("metrics not updated" )
487
503
}
488
504
return nil
0 commit comments