@@ -25,6 +25,7 @@ import (
25
25
26
26
restful "github.com/emicklei/go-restful"
27
27
"github.com/go-openapi/spec"
28
+
28
29
"k8s.io/klog"
29
30
30
31
"k8s.io/apiserver/pkg/server"
@@ -107,7 +108,11 @@ func BuildAndRegisterAggregator(downloader *Downloader, delegationTarget server.
107
108
// Build initial spec to serve.
108
109
klog .V (2 ).Infof ("Building initial OpenAPI spec" )
109
110
defer func (start time.Time ) {
110
- klog .V (2 ).Infof ("Finished initial OpenAPI spec generation after %v" , time .Now ().Sub (start ))
111
+ duration := time .Now ().Sub (start )
112
+ klog .V (2 ).Infof ("Finished initial OpenAPI spec generation after %v" , duration )
113
+
114
+ regenerationCounter .With (map [string ]string {"apiservice" : "*" , "reason" : "startup" })
115
+ regenerationDurationGauge .With (map [string ]string {"reason" : "startup" }).Set (duration .Seconds ())
111
116
}(time .Now ())
112
117
specToServe , err := s .buildOpenAPISpec ()
113
118
if err != nil {
@@ -207,6 +212,7 @@ func (s *specAggregator) tryUpdatingServiceSpecs(specInfo *openAPISpecInfo) erro
207
212
if specInfo == nil {
208
213
return fmt .Errorf ("invalid input: specInfo must be non-nil" )
209
214
}
215
+ _ , updated := s .openAPISpecs [specInfo .apiService .Name ]
210
216
origSpecInfo , existedBefore := s .openAPISpecs [specInfo .apiService .Name ]
211
217
s .openAPISpecs [specInfo .apiService .Name ] = specInfo
212
218
@@ -216,7 +222,16 @@ func (s *specAggregator) tryUpdatingServiceSpecs(specInfo *openAPISpecInfo) erro
216
222
}
217
223
klog .V (2 ).Infof ("Updating OpenAPI spec because %s is updated" , specInfo .apiService .Name )
218
224
defer func (start time.Time ) {
219
- klog .V (2 ).Infof ("Finished OpenAPI spec generation after %v" , time .Now ().Sub (start ))
225
+ duration := time .Now ().Sub (start )
226
+ klog .V (2 ).Infof ("Finished OpenAPI spec generation after %v" , duration )
227
+
228
+ reason := "add"
229
+ if updated {
230
+ reason = "update"
231
+ }
232
+
233
+ regenerationCounter .With (map [string ]string {"apiservice" : specInfo .apiService .Name , "reason" : reason })
234
+ regenerationDurationGauge .With (map [string ]string {"reason" : reason }).Set (duration .Seconds ())
220
235
}(time .Now ())
221
236
if err := s .updateOpenAPISpec (); err != nil {
222
237
if existedBefore {
@@ -239,7 +254,11 @@ func (s *specAggregator) tryDeleteServiceSpecs(apiServiceName string) error {
239
254
delete (s .openAPISpecs , apiServiceName )
240
255
klog .V (2 ).Infof ("Updating OpenAPI spec because %s is removed" , apiServiceName )
241
256
defer func (start time.Time ) {
242
- klog .V (2 ).Infof ("Finished OpenAPI spec generation after %v" , time .Now ().Sub (start ))
257
+ duration := time .Now ().Sub (start )
258
+ klog .V (2 ).Infof ("Finished OpenAPI spec generation after %v" , duration )
259
+
260
+ regenerationCounter .With (map [string ]string {"apiservice" : apiServiceName , "reason" : "delete" })
261
+ regenerationDurationGauge .With (map [string ]string {"reason" : "delete" }).Set (duration .Seconds ())
243
262
}(time .Now ())
244
263
if err := s .updateOpenAPISpec (); err != nil {
245
264
s .openAPISpecs [apiServiceName ] = orgSpecInfo
0 commit comments