mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
apiextension: add metric for openapi regeneration
This commit is contained in:
parent
de020ecb1c
commit
63dbb234b8
@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["controller.go"],
|
||||
srcs = [
|
||||
"controller.go",
|
||||
"metrics.go",
|
||||
],
|
||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiextensions-apiserver/pkg/controller/openapi",
|
||||
importpath = "k8s.io/apiextensions-apiserver/pkg/controller/openapi",
|
||||
visibility = ["//visibility:public"],
|
||||
@ -17,6 +20,8 @@ go_library(
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/util/workqueue:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/metrics:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
|
||||
"//vendor/github.com/go-openapi/spec:go_default_library",
|
||||
"//vendor/k8s.io/klog:go_default_library",
|
||||
"//vendor/k8s.io/kube-openapi/pkg/handler:go_default_library",
|
||||
|
@ -169,11 +169,12 @@ func (c *Controller) sync(name string) error {
|
||||
}
|
||||
delete(c.crdSpecs, name)
|
||||
klog.V(2).Infof("Updating CRD OpenAPI spec because %s was removed", name)
|
||||
regenerationCounter.With(map[string]string{"crd": name, "reason": "remove"})
|
||||
return c.updateSpecLocked()
|
||||
}
|
||||
|
||||
// compute CRD spec and see whether it changed
|
||||
oldSpecs := c.crdSpecs[crd.Name]
|
||||
oldSpecs, updated := c.crdSpecs[crd.Name]
|
||||
newSpecs, changed, err := buildVersionSpecs(crd, oldSpecs)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -185,6 +186,11 @@ func (c *Controller) sync(name string) error {
|
||||
// update specs of this CRD
|
||||
c.crdSpecs[crd.Name] = newSpecs
|
||||
klog.V(2).Infof("Updating CRD OpenAPI spec because %s changed", name)
|
||||
reason := "add"
|
||||
if updated {
|
||||
reason = "update"
|
||||
}
|
||||
regenerationCounter.With(map[string]string{"crd": name, "reason": reason})
|
||||
return c.updateSpecLocked()
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package openapi
|
||||
|
||||
import (
|
||||
"k8s.io/component-base/metrics"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
)
|
||||
|
||||
var (
|
||||
regenerationCounter = metrics.NewCounterVec(
|
||||
&metrics.CounterOpts{
|
||||
Name: "apiextensions_openapi_v2_regeneration_count",
|
||||
Help: "Counter of OpenAPI v2 spec regeneration count broken down by causing CRD name and reason.",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
[]string{"crd", "reason"},
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
legacyregistry.MustRegister(regenerationCounter)
|
||||
}
|
Loading…
Reference in New Issue
Block a user