@@ -621,6 +621,8 @@ var _ = Describe("Controller", func() {
621
621
})
622
622
It ("should ensure that we don't leak metrics when changing labels" , func () {
623
623
metrics .Registry = prometheus .NewRegistry ()
624
+ metrics .Registry .Register (status .ConditionCount .(* pmetrics.PrometheusGauge ).GaugeVec )
625
+ metrics .Registry .Register (status .ConditionCurrentStatusSeconds .(* pmetrics.PrometheusGauge ).GaugeVec )
624
626
testObject := test .Object (& test.CustomObject {
625
627
ObjectMeta : metav1.ObjectMeta {
626
628
Labels : map [string ]string {
@@ -635,7 +637,7 @@ var _ = Describe("Controller", func() {
635
637
})
636
638
ExpectApplied (ctx , kubeClient , testObject )
637
639
638
- controller = status .NewController [* test.CustomObject ](kubeClient , recorder , status .WithLabels ("operator.pkg/key1" , "operator.pkg/key2" , "operator.pkg/key3" ))
640
+ controller = status .NewController [* test.CustomObject ](kubeClient , recorder , status .WithLabels ("operator.pkg/key1" , "operator.pkg/key2" , "operator.pkg/key3" ), status . EmitDeprecatedMetrics )
639
641
ExpectReconciled (ctx , controller , testObject )
640
642
641
643
Expect (GetMetric ("operator_customobject_status_condition_count" , lo .Assign (conditionLabels (test .ConditionTypeFoo , metav1 .ConditionTrue ), map [string ]string {"operator_pkg_key1" : "value1" , "operator_pkg_key2" : "value2" , "operator_pkg_key3" : "" }))).To (BeNil ())
@@ -645,6 +647,9 @@ var _ = Describe("Controller", func() {
645
647
Expect (GetMetric ("operator_customobject_status_condition_current_status_seconds" , lo .Assign (conditionLabels (test .ConditionTypeFoo , metav1 .ConditionFalse ), map [string ]string {"operator_pkg_key1" : "value1" , "operator_pkg_key2" : "value2" , "operator_pkg_key3" : "" }))).To (BeNil ())
646
648
Expect (GetMetric ("operator_customobject_status_condition_current_status_seconds" , lo .Assign (conditionLabels (test .ConditionTypeFoo , metav1 .ConditionUnknown ), map [string ]string {"operator_pkg_key1" : "value1" , "operator_pkg_key2" : "value2" , "operator_pkg_key3" : "" })).GetGauge ().GetValue ()).ToNot (BeZero ())
647
649
650
+ Expect (GetMetric ("operator_status_condition_count" , conditionLabels (test .ConditionTypeFoo , metav1 .ConditionUnknown )).GetGauge ().GetValue ()).To (BeEquivalentTo (1 ))
651
+ Expect (GetMetric ("operator_status_condition_current_status_seconds" , conditionLabels (test .ConditionTypeFoo , metav1 .ConditionUnknown )).GetGauge ().GetValue ()).ToNot (BeZero ())
652
+
648
653
// Set empty label to a different value and ensure that we don't still keep track of the old metric
649
654
testObject .Labels ["operator.pkg/key3" ] = "value3"
650
655
@@ -660,6 +665,17 @@ var _ = Describe("Controller", func() {
660
665
Expect (GetMetric ("operator_customobject_status_condition_current_status_seconds" , lo .Assign (conditionLabels (test .ConditionTypeFoo , metav1 .ConditionFalse ), map [string ]string {"operator_pkg_key1" : "value1" , "operator_pkg_key2" : "value2" , "operator_pkg_key3" : "value3" }))).To (BeNil ())
661
666
Expect (GetMetric ("operator_customobject_status_condition_current_status_seconds" , lo .Assign (conditionLabels (test .ConditionTypeFoo , metav1 .ConditionUnknown ), map [string ]string {"operator_pkg_key1" : "value1" , "operator_pkg_key2" : "value2" , "operator_pkg_key3" : "" })).GetGauge ()).To (BeNil ())
662
667
Expect (GetMetric ("operator_customobject_status_condition_current_status_seconds" , lo .Assign (conditionLabels (test .ConditionTypeFoo , metav1 .ConditionUnknown ), map [string ]string {"operator_pkg_key1" : "value1" , "operator_pkg_key2" : "value2" , "operator_pkg_key3" : "value3" })).GetGauge ().GetValue ()).ToNot (BeZero ())
668
+
669
+ Expect (GetMetric ("operator_status_condition_count" , conditionLabels (test .ConditionTypeFoo , metav1 .ConditionUnknown )).GetGauge ().GetValue ()).To (BeEquivalentTo (1 ))
670
+ Expect (GetMetric ("operator_status_condition_current_status_seconds" , conditionLabels (test .ConditionTypeFoo , metav1 .ConditionUnknown )).GetGauge ().GetValue ()).ToNot (BeZero ())
671
+
672
+ testObject .StatusConditions ().SetTrueWithReason (test .ConditionTypeFoo , "reason" , "message" )
673
+ ExpectApplied (ctx , kubeClient , testObject )
674
+ ExpectReconciled (ctx , controller , testObject )
675
+ Expect (GetMetric ("operator_status_condition_count" , conditionLabels (test .ConditionTypeFoo , metav1 .ConditionUnknown )).GetGauge ().GetValue ()).To (BeEquivalentTo (0 ))
676
+ Expect (GetMetric ("operator_status_condition_count" , conditionLabels (test .ConditionTypeFoo , metav1 .ConditionTrue )).GetGauge ().GetValue ()).To (BeEquivalentTo (1 ))
677
+ Expect (GetMetric ("operator_status_condition_current_status_seconds" , conditionLabels (test .ConditionTypeFoo , metav1 .ConditionUnknown )).GetGauge ().GetValue ()).To (BeZero ())
678
+ Expect (GetMetric ("operator_status_condition_current_status_seconds" , conditionLabels (test .ConditionTypeFoo , metav1 .ConditionTrue )).GetGauge ().GetValue ()).ToNot (BeZero ())
663
679
})
664
680
DescribeTable ("should add labels to metrics" , func (labelOption option.Function [status.Option ], isGaugeOption bool ) {
665
681
metrics .Registry = prometheus .NewRegistry ()
0 commit comments