File tree Expand file tree Collapse file tree 3 files changed +50
-2
lines changed
staging/src/k8s.io/apiextensions-apiserver/pkg/controller/openapi Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
2
2
3
3
go_library (
4
4
name = "go_default_library" ,
5
- srcs = ["controller.go" ],
5
+ srcs = [
6
+ "controller.go" ,
7
+ "metrics.go" ,
8
+ ],
6
9
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiextensions-apiserver/pkg/controller/openapi" ,
7
10
importpath = "k8s.io/apiextensions-apiserver/pkg/controller/openapi" ,
8
11
visibility = ["//visibility:public" ],
@@ -17,6 +20,8 @@ go_library(
17
20
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library" ,
18
21
"//staging/src/k8s.io/client-go/tools/cache:go_default_library" ,
19
22
"//staging/src/k8s.io/client-go/util/workqueue:go_default_library" ,
23
+ "//staging/src/k8s.io/component-base/metrics:go_default_library" ,
24
+ "//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library" ,
20
25
"//vendor/github.com/go-openapi/spec:go_default_library" ,
21
26
"//vendor/k8s.io/klog:go_default_library" ,
22
27
"//vendor/k8s.io/kube-openapi/pkg/handler:go_default_library" ,
Original file line number Diff line number Diff line change @@ -169,11 +169,12 @@ func (c *Controller) sync(name string) error {
169
169
}
170
170
delete (c .crdSpecs , name )
171
171
klog .V (2 ).Infof ("Updating CRD OpenAPI spec because %s was removed" , name )
172
+ regenerationCounter .With (map [string ]string {"crd" : name , "reason" : "remove" })
172
173
return c .updateSpecLocked ()
173
174
}
174
175
175
176
// compute CRD spec and see whether it changed
176
- oldSpecs := c .crdSpecs [crd .Name ]
177
+ oldSpecs , updated := c .crdSpecs [crd .Name ]
177
178
newSpecs , changed , err := buildVersionSpecs (crd , oldSpecs )
178
179
if err != nil {
179
180
return err
@@ -185,6 +186,11 @@ func (c *Controller) sync(name string) error {
185
186
// update specs of this CRD
186
187
c .crdSpecs [crd .Name ] = newSpecs
187
188
klog .V (2 ).Infof ("Updating CRD OpenAPI spec because %s changed" , name )
189
+ reason := "add"
190
+ if updated {
191
+ reason = "update"
192
+ }
193
+ regenerationCounter .With (map [string ]string {"crd" : name , "reason" : reason })
188
194
return c .updateSpecLocked ()
189
195
}
190
196
Original file line number Diff line number Diff line change
1
+ /*
2
+ Copyright 2019 The Kubernetes Authors.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ package openapi
18
+
19
+ import (
20
+ "k8s.io/component-base/metrics"
21
+ "k8s.io/component-base/metrics/legacyregistry"
22
+ )
23
+
24
+ var (
25
+ regenerationCounter = metrics .NewCounterVec (
26
+ & metrics.CounterOpts {
27
+ Name : "apiextensions_openapi_v2_regeneration_count" ,
28
+ Help : "Counter of OpenAPI v2 spec regeneration count broken down by causing CRD name and reason." ,
29
+ StabilityLevel : metrics .ALPHA ,
30
+ },
31
+ []string {"crd" , "reason" },
32
+ )
33
+ )
34
+
35
+ func init () {
36
+ legacyregistry .MustRegister (regenerationCounter )
37
+ }
You can’t perform that action at this time.
0 commit comments