Skip to content

Commit a17e297

Browse files
committed
Add deprecated metric for requests to deprecated custom resource versions
1 parent f03290c commit a17e297

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ type crdInfo struct {
142142
spec *apiextensionsv1.CustomResourceDefinitionSpec
143143
acceptedNames *apiextensionsv1.CustomResourceDefinitionNames
144144

145+
// Deprecated per version
146+
deprecated map[string]bool
147+
145148
// Warnings per version
146149
warnings map[string][]string
147150

@@ -329,6 +332,7 @@ func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
329332
return
330333
}
331334

335+
deprecated := crdInfo.deprecated[requestInfo.APIVersion]
332336
for _, w := range crdInfo.warnings[requestInfo.APIVersion] {
333337
warning.AddWarning(req.Context(), "", w)
334338
}
@@ -370,7 +374,7 @@ func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
370374
}
371375

372376
if handlerFunc != nil {
373-
handlerFunc = metrics.InstrumentHandlerFunc(verb, requestInfo.APIGroup, requestInfo.APIVersion, resource, subresource, scope, metrics.APIServerComponent, false, "", handlerFunc)
377+
handlerFunc = metrics.InstrumentHandlerFunc(verb, requestInfo.APIGroup, requestInfo.APIVersion, resource, subresource, scope, metrics.APIServerComponent, deprecated, "", handlerFunc)
374378
handler := genericfilters.WithWaitGroup(handlerFunc, longRunningFilter, crdInfo.waitGroup)
375379
handler.ServeHTTP(w, req)
376380
return
@@ -620,6 +624,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
620624
storages := map[string]customresource.CustomResourceStorage{}
621625
statusScopes := map[string]*handlers.RequestScope{}
622626
scaleScopes := map[string]*handlers.RequestScope{}
627+
deprecated := map[string]bool{}
623628
warnings := map[string][]string{}
624629

625630
equivalentResourceRegistry := runtime.NewEquivalentResourceRegistry()
@@ -881,6 +886,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
881886
statusScopes[v.Name] = &statusScope
882887

883888
if v.Deprecated {
889+
deprecated[v.Name] = true
884890
if utilfeature.DefaultFeatureGate.Enabled(features.WarningHeaders) {
885891
if v.DeprecationWarning != nil {
886892
warnings[v.Name] = append(warnings[v.Name], *v.DeprecationWarning)
@@ -898,6 +904,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
898904
requestScopes: requestScopes,
899905
scaleRequestScopes: scaleScopes,
900906
statusRequestScopes: statusScopes,
907+
deprecated: deprecated,
901908
warnings: warnings,
902909
storageVersion: storageVersion,
903910
waitGroup: &utilwaitgroup.SafeWaitGroup{},

0 commit comments

Comments
 (0)