@@ -100,7 +100,7 @@ func TestWatchCacheEnabledForCRD(t *testing.T) {
100100 require .Equal (t , 1 , len (res .Items ), "expected to get exactly one cowboy" )
101101 }
102102
103- totalCacheHits , cowboysCacheHit := collectCacheHitsFor (ctx , t , server .RootShardSystemMasterBaseConfig (t ), "/ wildwest.dev/ cowboys/customresources " )
103+ totalCacheHits , cowboysCacheHit := collectCacheHitsFor (ctx , t , server .RootShardSystemMasterBaseConfig (t ), "wildwest.dev" , " cowboys" )
104104 if totalCacheHits == 0 {
105105 t .Fatalf ("the watch cache is turned off, didn't find instances of %q metrics" , "apiserver_cache_list_total" )
106106 }
@@ -152,7 +152,7 @@ func TestWatchCacheEnabledForAPIBindings(t *testing.T) {
152152 require .Equal (t , 1 , len (res .Items ), "expected to get exactly one sheriff" )
153153 }
154154
155- totalCacheHits , sheriffsCacheHit := collectCacheHitsFor (ctx , t , server .RootShardSystemMasterBaseConfig (t ), "/ newyork.io/ sheriffs" )
155+ totalCacheHits , sheriffsCacheHit := collectCacheHitsFor (ctx , t , server .RootShardSystemMasterBaseConfig (t ), "newyork.io" , " sheriffs" )
156156 if totalCacheHits == 0 {
157157 t .Fatalf ("the watch cache is turned off, didn't find instances of %q metrics" , "apiserver_cache_list_total" )
158158 }
@@ -212,7 +212,7 @@ func TestWatchCacheEnabledForBuiltinTypes(t *testing.T) {
212212 }
213213 }
214214
215- totalCacheHits , secretsCacheHit := collectCacheHitsFor (ctx , t , server .RootShardSystemMasterBaseConfig (t ), "/core/ secrets" )
215+ totalCacheHits , secretsCacheHit := collectCacheHitsFor (ctx , t , server .RootShardSystemMasterBaseConfig (t ), "" , " secrets" )
216216 if totalCacheHits == 0 {
217217 t .Fatalf ("the watch cache is turned off, didn't find instances of %q metrics" , "apiserver_cache_list_total" )
218218 }
@@ -221,13 +221,14 @@ func TestWatchCacheEnabledForBuiltinTypes(t *testing.T) {
221221 }
222222}
223223
224- func collectCacheHitsFor (ctx context.Context , t * testing.T , rootCfg * rest.Config , metricResourcePrefix string ) (int , int ) {
224+ func collectCacheHitsFor (ctx context.Context , t * testing.T , rootCfg * rest.Config , group , resource string ) (int , int ) {
225225 t .Helper ()
226226
227227 rootShardKubeClusterClient , err := kcpkubernetesclientset .NewForConfig (rootCfg )
228228 require .NoError (t , err )
229229
230- t .Logf ("Reading %q metrics from the API server via %q endpoint for %q prefix" , "apiserver_cache_list_total" , "/metrics" , metricResourcePrefix )
230+ // metrics example: "apiserver_cache_list_total{group=\"\",index=\"\",resource=\"secrets\"} 118
231+ t .Logf ("Reading %q metrics from the API server via %q endpoint for group %q and resource %q" , "apiserver_cache_list_total" , "/metrics" , group , resource )
231232 rsp := rootShardKubeClusterClient .RESTClient ().Get ().AbsPath ("/metrics" ).Do (ctx )
232233 raw , err := rsp .Raw ()
233234 require .NoError (t , err )
@@ -237,7 +238,8 @@ func collectCacheHitsFor(ctx context.Context, t *testing.T, rootCfg *rest.Config
237238 txt := scanner .Text ()
238239 if strings .Contains (txt , "apiserver_cache_list_total" ) {
239240 totalCacheHits ++
240- if strings .Contains (txt , fmt .Sprintf (`resource_prefix="%v` , metricResourcePrefix )) {
241+ if strings .Contains (txt , fmt .Sprintf (`group="%s"` , group )) &&
242+ strings .Contains (txt , fmt .Sprintf (`resource="%s"` , resource )) {
241243 re := regexp .MustCompile (`\b\d+\b` )
242244 prefixCacheHitInstance , err := strconv .Atoi (string (re .Find ([]byte (txt ))))
243245 if err != nil {
0 commit comments