@@ -63,9 +63,9 @@ var _ = Describe("controller", func() {
63
63
informers = & informertest.FakeInformers {}
64
64
ctrl = & Controller {
65
65
MaxConcurrentReconciles : 1 ,
66
- Do : fakeReconcile ,
67
- Queue : queue ,
68
- Cache : informers ,
66
+ Do : fakeReconcile ,
67
+ Queue : queue ,
68
+ Cache : informers ,
69
69
}
70
70
ctrl .InjectFunc (func (interface {}) error { return nil })
71
71
})
@@ -410,12 +410,12 @@ 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
- var queueLength , reconcileErrs dto.Metric
413
+ var queueLength , reconcileErrs , reconcileTotal dto.Metric
414
414
ctrlmetrics .QueueLength .Reset ()
415
415
Expect (func () error {
416
416
ctrlmetrics .QueueLength .WithLabelValues (ctrl .Name ).Write (& queueLength )
417
417
if queueLength .GetGauge ().GetValue () != 0.0 {
418
- return fmt .Errorf ("metrics not reset" )
418
+ return fmt .Errorf ("metric queue length not reset" )
419
419
}
420
420
return nil
421
421
}()).Should (Succeed ())
@@ -424,7 +424,24 @@ var _ = Describe("controller", func() {
424
424
Expect (func () error {
425
425
ctrlmetrics .ReconcileErrors .WithLabelValues (ctrl .Name ).Write (& reconcileErrs )
426
426
if reconcileErrs .GetCounter ().GetValue () != 0.0 {
427
- return fmt .Errorf ("metrics not reset" )
427
+ return fmt .Errorf ("metric reconcile errors not reset" )
428
+ }
429
+ return nil
430
+ }()).Should (Succeed ())
431
+
432
+ ctrlmetrics .ReconcileTotal .Reset ()
433
+ Expect (func () error {
434
+ ctrlmetrics .ReconcileTotal .WithLabelValues (ctrl .Name , "success" ).Write (& reconcileTotal )
435
+ if reconcileTotal .GetCounter ().GetValue () != 0.0 {
436
+ return fmt .Errorf ("metric reconcile total with label success not reset" )
437
+ }
438
+ ctrlmetrics .ReconcileTotal .WithLabelValues (ctrl .Name , "error" ).Write (& reconcileTotal )
439
+ if reconcileTotal .GetCounter ().GetValue () != 0.0 {
440
+ return fmt .Errorf ("metric reconcile total with label error not reset" )
441
+ }
442
+ ctrlmetrics .ReconcileTotal .WithLabelValues (ctrl .Name , "retry" ).Write (& reconcileTotal )
443
+ if reconcileTotal .GetCounter ().GetValue () != 0.0 {
444
+ return fmt .Errorf ("metric reconcile total with label retry not reset" )
428
445
}
429
446
return nil
430
447
}()).Should (Succeed ())
@@ -444,7 +461,7 @@ var _ = Describe("controller", func() {
444
461
Eventually (func () error {
445
462
ctrlmetrics .QueueLength .WithLabelValues (ctrl .Name ).Write (& queueLength )
446
463
if queueLength .GetGauge ().GetValue () != 1.0 {
447
- return fmt .Errorf ("metrics not updated" )
464
+ return fmt .Errorf ("metric queue length not updated" )
448
465
}
449
466
return nil
450
467
}, 2.0 ).Should (Succeed ())
@@ -455,6 +472,13 @@ var _ = Describe("controller", func() {
455
472
}
456
473
return nil
457
474
}, 2.0 ).Should (Succeed ())
475
+ Eventually (func () error {
476
+ ctrlmetrics .ReconcileTotal .WithLabelValues (ctrl .Name , "error" ).Write (& reconcileTotal )
477
+ if reconcileTotal .GetCounter ().GetValue () != 1.0 {
478
+ return fmt .Errorf ("metric reconcile total not updated" )
479
+ }
480
+ return nil
481
+ }, 2.0 ).Should (Succeed ())
458
482
459
483
By ("Invoking Reconciler a second time without error" )
460
484
fakeReconcile .Err = nil
@@ -464,6 +488,23 @@ var _ = Describe("controller", func() {
464
488
Eventually (ctrl .Queue .Len ).Should (Equal (0 ))
465
489
Eventually (func () int { return ctrl .Queue .NumRequeues (request ) }).Should (Equal (0 ))
466
490
491
+ By ("Examining ReconcileTotal post second reconcile" )
492
+ Eventually (func () error {
493
+ ctrlmetrics .ReconcileTotal .WithLabelValues (ctrl .Name , "error" ).Write (& reconcileTotal )
494
+ if reconcileTotal .GetCounter ().GetValue () != 1.0 {
495
+ return fmt .Errorf ("metric reconcile total with label error not updated" )
496
+ }
497
+ ctrlmetrics .ReconcileTotal .WithLabelValues (ctrl .Name , "success" ).Write (& reconcileTotal )
498
+ if reconcileTotal .GetCounter ().GetValue () != 1.0 {
499
+ return fmt .Errorf ("metric reconcile total with label success not updated" )
500
+ }
501
+ ctrlmetrics .ReconcileTotal .WithLabelValues (ctrl .Name , "retry" ).Write (& reconcileTotal )
502
+ if reconcileTotal .GetCounter ().GetValue () != 0.0 {
503
+ return fmt .Errorf ("metric reconcile total with label error was updated" )
504
+ }
505
+ return nil
506
+ }, 2.0 ).Should (Succeed ())
507
+
467
508
close (done )
468
509
}, 2.0 )
469
510
0 commit comments