Add deprecated metric for requests to deprecated custom resource versions

This commit is contained in:
Jordan Liggitt 2020-07-06 14:32:55 -04:00
parent f03290c390
commit a17e297245

View File

@ -142,6 +142,9 @@ type crdInfo struct {
spec *apiextensionsv1.CustomResourceDefinitionSpec
acceptedNames *apiextensionsv1.CustomResourceDefinitionNames
// Deprecated per version
deprecated map[string]bool
// Warnings per version
warnings map[string][]string
@ -329,6 +332,7 @@ func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
deprecated := crdInfo.deprecated[requestInfo.APIVersion]
for _, w := range crdInfo.warnings[requestInfo.APIVersion] {
warning.AddWarning(req.Context(), "", w)
}
@ -370,7 +374,7 @@ func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
if handlerFunc != nil {
handlerFunc = metrics.InstrumentHandlerFunc(verb, requestInfo.APIGroup, requestInfo.APIVersion, resource, subresource, scope, metrics.APIServerComponent, false, "", handlerFunc)
handlerFunc = metrics.InstrumentHandlerFunc(verb, requestInfo.APIGroup, requestInfo.APIVersion, resource, subresource, scope, metrics.APIServerComponent, deprecated, "", handlerFunc)
handler := genericfilters.WithWaitGroup(handlerFunc, longRunningFilter, crdInfo.waitGroup)
handler.ServeHTTP(w, req)
return
@ -620,6 +624,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
storages := map[string]customresource.CustomResourceStorage{}
statusScopes := map[string]*handlers.RequestScope{}
scaleScopes := map[string]*handlers.RequestScope{}
deprecated := map[string]bool{}
warnings := map[string][]string{}
equivalentResourceRegistry := runtime.NewEquivalentResourceRegistry()
@ -881,6 +886,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
statusScopes[v.Name] = &statusScope
if v.Deprecated {
deprecated[v.Name] = true
if utilfeature.DefaultFeatureGate.Enabled(features.WarningHeaders) {
if v.DeprecationWarning != nil {
warnings[v.Name] = append(warnings[v.Name], *v.DeprecationWarning)
@ -898,6 +904,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
requestScopes: requestScopes,
scaleRequestScopes: scaleScopes,
statusRequestScopes: statusScopes,
deprecated: deprecated,
warnings: warnings,
storageVersion: storageVersion,
waitGroup: &utilwaitgroup.SafeWaitGroup{},