@@ -580,17 +580,10 @@ func (dsf *Farm) spawnDaemonSet(
580
580
for {
581
581
select {
582
582
case <- ctx .Done ():
583
- for _ , name := range ds .MetricNames ("healthy" ) {
584
- p2metrics .Registry .Unregister (name )
585
- }
586
- for _ , name := range ds .MetricNames ("critical" ) {
587
- p2metrics .Registry .Unregister (name )
588
- }
589
- for _ , name := range ds .MetricNames ("unknown" ) {
590
- p2metrics .Registry .Unregister (name )
591
- }
592
- for _ , name := range ds .MetricNames ("warning" ) {
593
- p2metrics .Registry .Unregister (name )
583
+ for _ , suffix := range []string {"healthy" , "critical" , "unknown" , "warning" } {
584
+ for _ , name := range ds .MetricNames (suffix ) {
585
+ p2metrics .Registry .Unregister (name )
586
+ }
594
587
}
595
588
return
596
589
case <- ticks .C :
@@ -600,29 +593,19 @@ func (dsf *Farm) spawnDaemonSet(
600
593
continue
601
594
}
602
595
603
- numHealthy := aggregateHealth .NumHealthyOf (eligible )
604
- numUnhealthy := aggregateHealth .NumUnhealthyOf (eligible )
605
- numUnknownHealth := aggregateHealth .NumUnknownHealthOf (eligible )
606
- numWarningHealth := aggregateHealth .NumWarningHealthOf (eligible )
607
-
608
- for _ , name := range ds .MetricNames ("healthy" ) {
609
- gauge := metrics .GetOrRegisterGauge (name , p2metrics .Registry )
610
- gauge .Update (int64 (numHealthy ))
611
- }
612
-
613
- for _ , name := range ds .MetricNames ("critical" ) {
614
- gauge := metrics .GetOrRegisterGauge (name , p2metrics .Registry )
615
- gauge .Update (int64 (numUnhealthy ))
616
- }
617
-
618
- for _ , name := range ds .MetricNames ("unknown" ) {
619
- gauge := metrics .GetOrRegisterGauge (name , p2metrics .Registry )
620
- gauge .Update (int64 (numUnknownHealth ))
621
- }
622
-
623
- for _ , name := range ds .MetricNames ("warning" ) {
624
- gauge := metrics .GetOrRegisterGauge (name , p2metrics .Registry )
625
- gauge .Update (int64 (numWarningHealth ))
596
+ for _ , metric := range []struct {
597
+ suffix string
598
+ val int
599
+ }{
600
+ {"healthy" , aggregateHealth .NumHealthyOf (eligible )},
601
+ {"critical" , aggregateHealth .NumUnhealthyOf (eligible )},
602
+ {"unknown" , aggregateHealth .NumUnknownHealthOf (eligible )},
603
+ {"warning" , aggregateHealth .NumWarningHealthOf (eligible )},
604
+ } {
605
+ for _ , name := range ds .MetricNames (metric .suffix ) {
606
+ gauge := metrics .GetOrRegisterGauge (name , p2metrics .Registry )
607
+ gauge .Update (int64 (metric .val ))
608
+ }
626
609
}
627
610
}
628
611
}
0 commit comments