@@ -763,6 +763,45 @@ var _ = Describe("Controller", func() {
763763 Entry ("when using WithFields" , status .WithFields (map [string ]string {"operator.pkg/key1" : ".spec.field1" , "operator.pkg/key2" : ".spec.field2" , "operator.pkg/key3" : ".spec.field3" }), false ),
764764 Entry ("when using WithGaugeFields" , status .WithGaugeFields (map [string ]string {"operator.pkg/key1" : ".spec.field1" , "operator.pkg/key2" : ".spec.field2" , "operator.pkg/key3" : ".spec.field3" }), true ),
765765 )
766+ It ("should use custom histogram buckets when specified" , func () {
767+ customBuckets := []float64 {0.1 , 0.5 , 1.0 , 2.0 , 5.0 }
768+ metrics .Registry = prometheus .NewRegistry ()
769+
770+ controller = status .NewController [* test.CustomObject ](kubeClient , recorder , status .WithHistogramBuckets (customBuckets ))
771+
772+ testObject := test .Object (& test.CustomObject {})
773+ testObject .StatusConditions () // initialize conditions
774+
775+ // Apply object and reconcile to set initial state
776+ ExpectApplied (ctx , kubeClient , testObject )
777+ ExpectReconciled (ctx , controller , testObject )
778+
779+ // Wait a bit to ensure some time passes for duration measurement
780+ time .Sleep (100 * time .Millisecond )
781+
782+ // Transition a condition to trigger histogram observation
783+ testObject .StatusConditions ().SetTrue (test .ConditionTypeFoo )
784+ ExpectApplied (ctx , kubeClient , testObject )
785+ ExpectReconciled (ctx , controller , testObject )
786+
787+ // Verify that the histogram metric exists and has data
788+ metric := GetMetric ("operator_customobject_status_condition_transition_seconds" , conditionLabels (test .ConditionTypeFoo , metav1 .ConditionUnknown ))
789+ Expect (metric ).ToNot (BeNil ())
790+
791+ histogram := metric .GetHistogram ()
792+ Expect (histogram ).ToNot (BeNil ())
793+ Expect (histogram .GetSampleCount ()).To (BeNumerically (">" , 0 ))
794+
795+ // Verify custom buckets are being used by checking bucket count matches our custom buckets
796+ // The histogram should have len(customBuckets) + 1 buckets (including +Inf)
797+ buckets := histogram .GetBucket ()
798+ Expect (len (buckets )).To (Equal (len (customBuckets )))
799+
800+ // Verify the bucket upper bounds match our custom buckets
801+ for i , bucket := range buckets {
802+ Expect (bucket .GetUpperBound ()).To (Equal (customBuckets [i ]))
803+ }
804+ })
766805})
767806
768807var _ = Describe ("Generic Controller" , func () {
0 commit comments