@@ -696,7 +696,8 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
696
696
).Leveled (slog .LevelDebug )
697
697
db , pubSub := dbtestutil .NewDB (t )
698
698
fakeEnqueuer := newFakeEnqueuer ()
699
- controller := prebuilds .NewStoreReconciler (db , pubSub , cfg , logger , clock , prometheus .NewRegistry (), fakeEnqueuer )
699
+ registry := prometheus .NewRegistry ()
700
+ controller := prebuilds .NewStoreReconciler (db , pubSub , cfg , logger , clock , registry , fakeEnqueuer )
700
701
701
702
// Template admin to receive a notification.
702
703
templateAdmin := dbgen .User (t , db , database.User {
@@ -732,6 +733,17 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
732
733
workspaceCount := len (workspaces )
733
734
require .Equal (t , 1 , workspaceCount )
734
735
736
+ // Verify initial state: metric is not set - meaning preset is not hard limited.
737
+ require .NoError (t , controller .ForceMetricsUpdate (ctx ))
738
+ mf , err := registry .Gather ()
739
+ require .NoError (t , err )
740
+ metric := findMetric (mf , prebuilds .MetricHardLimitedPresetsGauge , map [string ]string {
741
+ "template_name" : template .Name ,
742
+ "preset_name" : preset .Name ,
743
+ "org_name" : org .Name ,
744
+ })
745
+ require .Nil (t , metric )
746
+
735
747
// We simulate a failed prebuild in the test; Consequently, the backoff mechanism is triggered when ReconcileAll is called.
736
748
// Even though ReconciliationBackoffInterval is set to zero, we still need to advance the clock by at least one nanosecond.
737
749
clock .Advance (time .Nanosecond ).MustWait (ctx )
@@ -755,6 +767,18 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
755
767
// When hard limit is not reached, a new workspace should be created.
756
768
require .Equal (t , 2 , len (workspaces ))
757
769
require .Equal (t , database .PrebuildStatusHealthy , updatedPreset .PrebuildStatus )
770
+
771
+ // When hard limit is not reached, metric is set to 0.
772
+ mf , err = registry .Gather ()
773
+ require .NoError (t , err )
774
+ metric = findMetric (mf , prebuilds .MetricHardLimitedPresetsGauge , map [string ]string {
775
+ "template_name" : template .Name ,
776
+ "preset_name" : preset .Name ,
777
+ "org_name" : org .Name ,
778
+ })
779
+ require .NotNil (t , metric )
780
+ require .NotNil (t , metric .GetGauge ())
781
+ require .EqualValues (t , 0 , metric .GetGauge ().GetValue ())
758
782
return
759
783
}
760
784
@@ -775,6 +799,18 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
775
799
return true
776
800
})
777
801
require .Len (t , matching , 1 )
802
+
803
+ // When hard limit is reached, metric is set to 1.
804
+ mf , err = registry .Gather ()
805
+ require .NoError (t , err )
806
+ metric = findMetric (mf , prebuilds .MetricHardLimitedPresetsGauge , map [string ]string {
807
+ "template_name" : template .Name ,
808
+ "preset_name" : preset .Name ,
809
+ "org_name" : org .Name ,
810
+ })
811
+ require .NotNil (t , metric )
812
+ require .NotNil (t , metric .GetGauge ())
813
+ require .EqualValues (t , 1 , metric .GetGauge ().GetValue ())
778
814
})
779
815
}
780
816
}
0 commit comments