@@ -116,6 +116,12 @@ type LatencyTrackers struct {
116
116
// Validate webhooks are done in parallel, so max function is used.
117
117
ValidatingWebhookTracker DurationTracker
118
118
119
+ // AuthenticationTracker tracks the latency incurred by Authentication of request
120
+ AuthenticationTracker DurationTracker
121
+
122
+ // AuthorizationTracker tracks the latency incurred by Authorization of request
123
+ AuthorizationTracker DurationTracker
124
+
119
125
// APFQueueWaitTracker tracks the latency incurred by queue wait times
120
126
// from priority & fairness.
121
127
APFQueueWaitTracker DurationTracker
@@ -179,6 +185,8 @@ func WithLatencyTrackersAndCustomClock(parent context.Context, c clock.Clock) co
179
185
return WithValue (parent , latencyTrackersKey , & LatencyTrackers {
180
186
MutatingWebhookTracker : newSumLatencyTracker (c ),
181
187
ValidatingWebhookTracker : newMaxLatencyTracker (c ),
188
+ AuthenticationTracker : newSumLatencyTracker (c ),
189
+ AuthorizationTracker : newMaxLatencyTracker (c ),
182
190
APFQueueWaitTracker : newMaxLatencyTracker (c ),
183
191
StorageTracker : newSumLatencyTracker (c ),
184
192
TransformTracker : newSumLatencyTracker (c ),
@@ -243,6 +251,22 @@ func TrackResponseWriteLatency(ctx context.Context, d time.Duration) {
243
251
}
244
252
}
245
253
254
+ // TrackAuthenticationLatency is used to track latency incurred
255
+ // by Authentication phase of request.
256
+ func TrackAuthenticationLatency (ctx context.Context , d time.Duration ) {
257
+ if tracker , ok := LatencyTrackersFrom (ctx ); ok {
258
+ tracker .AuthenticationTracker .TrackDuration (d )
259
+ }
260
+ }
261
+
262
+ // TrackAuthorizationLatency is used to track latency incurred
263
+ // by Authorization phase of request.
264
+ func TrackAuthorizationLatency (ctx context.Context , d time.Duration ) {
265
+ if tracker , ok := LatencyTrackersFrom (ctx ); ok {
266
+ tracker .AuthorizationTracker .TrackDuration (d )
267
+ }
268
+ }
269
+
246
270
// TrackAPFQueueWaitLatency is used to track latency incurred
247
271
// by priority and fairness queues.
248
272
func TrackAPFQueueWaitLatency (ctx context.Context , d time.Duration ) {
@@ -275,6 +299,8 @@ func AuditAnnotationsFromLatencyTrackers(ctx context.Context) map[string]string
275
299
validatingWebhookLatencyKey = "apiserver.latency.k8s.io/validating-webhook"
276
300
decodeLatencyKey = "apiserver.latency.k8s.io/decode-response-object"
277
301
apfQueueWaitLatencyKey = "apiserver.latency.k8s.io/apf-queue-wait"
302
+ authenticationLatencyKey = "apiserver.latency.k8s.io/authentication"
303
+ authorizationLatencyKey = "apiserver.latency.k8s.io/authorization"
278
304
)
279
305
280
306
tracker , ok := LatencyTrackersFrom (ctx )
@@ -307,5 +333,11 @@ func AuditAnnotationsFromLatencyTrackers(ctx context.Context) map[string]string
307
333
if latency := tracker .APFQueueWaitTracker .GetLatency (); latency != 0 {
308
334
annotations [apfQueueWaitLatencyKey ] = latency .String ()
309
335
}
336
+ if latency := tracker .AuthenticationTracker .GetLatency (); latency != 0 {
337
+ annotations [authenticationLatencyKey ] = latency .String ()
338
+ }
339
+ if latency := tracker .AuthorizationTracker .GetLatency (); latency != 0 {
340
+ annotations [authorizationLatencyKey ] = latency .String ()
341
+ }
310
342
return annotations
311
343
}
0 commit comments