@@ -177,6 +177,10 @@ users:
177
177
}
178
178
t .Log ("serverTimeout" , sar )
179
179
time .Sleep (2 * time .Second )
180
+ sar .Status .Reason = "no opinion"
181
+ if err := json .NewEncoder (w ).Encode (sar ); err != nil {
182
+ t .Error (err )
183
+ }
180
184
}))
181
185
defer serverTimeout .Close ()
182
186
serverTimeoutKubeconfigName := filepath .Join (dir , "serverTimeout.yaml" )
@@ -331,6 +335,13 @@ users:
331
335
332
336
assertCount (errorName , c .errorCount , & serverErrorCalled )
333
337
assertCount (timeoutName , c .timeoutCount , & serverTimeoutCalled )
338
+ expectedTimeoutCounts := map [string ]int {}
339
+ if c .timeoutCount > 0 {
340
+ expectedTimeoutCounts [timeoutName ] = int (c .timeoutCount )
341
+ }
342
+ if ! reflect .DeepEqual (expectedTimeoutCounts , metrics .whTimeoutTotal ) {
343
+ t .Fatalf ("expected timeouts %#v, got %#v" , expectedTimeoutCounts , metrics .whTimeoutTotal )
344
+ }
334
345
assertCount (denyName , c .denyCount , & serverDenyCalled )
335
346
if e , a := c .denyCount , metrics .decisions [authorizerKey {authorizerType : "Webhook" , authorizerName : denyName }]["denied" ]; e != int32 (a ) {
336
347
t .Fatalf ("expected deny webhook denied metrics calls: %d, got %d" , e , a )
@@ -770,6 +781,7 @@ type metrics struct {
770
781
evalErrors int
771
782
772
783
whTotal map [string ]int
784
+ whTimeoutTotal map [string ]int
773
785
whFailOpenTotal map [string ]int
774
786
whDurationCount map [string ]int
775
787
}
@@ -803,6 +815,7 @@ func getMetrics(t *testing.T, client *clientset.Clientset) (*metrics, error) {
803
815
var m metrics
804
816
805
817
m .whTotal = map [string ]int {}
818
+ m .whTimeoutTotal = map [string ]int {}
806
819
m .whFailOpenTotal = map [string ]int {}
807
820
m .whDurationCount = map [string ]int {}
808
821
m .exclusions = 0
@@ -849,6 +862,9 @@ func getMetrics(t *testing.T, client *clientset.Clientset) (*metrics, error) {
849
862
}
850
863
t .Log (count )
851
864
m .whTotal [matches [1 ]] += count
865
+ if matches [2 ] == "timeout" {
866
+ m .whTimeoutTotal [matches [1 ]] += count
867
+ }
852
868
}
853
869
if matches := webhookDurationMetric .FindStringSubmatch (line ); matches != nil {
854
870
t .Log (matches )
0 commit comments