Fix APF width estimate for creating service account's token
Kubernetes-commit: 2f7b4ca6851aa3d479c9af3c14a168b4974f2fee
This commit is contained in:
parent
297ec95e2d
commit
6887520e10
|
@ -57,6 +57,15 @@ func (e *mutatingWorkEstimator) estimate(r *http.Request, flowSchemaName, priori
|
|||
AdditionalLatency: e.config.eventAdditionalDuration(),
|
||||
}
|
||||
}
|
||||
|
||||
if isRequestExemptFromWatchEvents(requestInfo) {
|
||||
return WorkEstimate{
|
||||
InitialSeats: e.config.MinimumSeats,
|
||||
FinalSeats: 0,
|
||||
AdditionalLatency: time.Duration(0),
|
||||
}
|
||||
}
|
||||
|
||||
watchCount := e.countFn(requestInfo)
|
||||
metrics.ObserveWatchCount(r.Context(), priorityLevelName, flowSchemaName, watchCount)
|
||||
|
||||
|
@ -129,3 +138,12 @@ func (e *mutatingWorkEstimator) estimate(r *http.Request, flowSchemaName, priori
|
|||
AdditionalLatency: additionalLatency,
|
||||
}
|
||||
}
|
||||
|
||||
func isRequestExemptFromWatchEvents(requestInfo *apirequest.RequestInfo) bool {
|
||||
// Creating token for service account does not produce any event,
|
||||
// but still serviceaccounts can have multiple watchers.
|
||||
if requestInfo.Resource == "serviceaccounts" && requestInfo.Subresource == "token" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -410,6 +410,33 @@ func TestWorkEstimator(t *testing.T) {
|
|||
finalSeatsExpected: 3,
|
||||
additionalLatencyExpected: 5 * time.Millisecond,
|
||||
},
|
||||
{
|
||||
name: "creating token for service account",
|
||||
requestURI: "http://server/api/v1/namespaces/foo/serviceaccounts/default/token",
|
||||
requestInfo: &apirequest.RequestInfo{
|
||||
Verb: "create",
|
||||
APIGroup: "v1",
|
||||
Resource: "serviceaccounts",
|
||||
Subresource: "token",
|
||||
},
|
||||
watchCount: 5777,
|
||||
initialSeatsExpected: minimumSeats,
|
||||
finalSeatsExpected: 0,
|
||||
additionalLatencyExpected: 0,
|
||||
},
|
||||
{
|
||||
name: "creating service account",
|
||||
requestURI: "http://server/api/v1/namespaces/foo/serviceaccounts",
|
||||
requestInfo: &apirequest.RequestInfo{
|
||||
Verb: "create",
|
||||
APIGroup: "v1",
|
||||
Resource: "serviceaccounts",
|
||||
},
|
||||
watchCount: 1000,
|
||||
initialSeatsExpected: 1,
|
||||
finalSeatsExpected: maximumSeats,
|
||||
additionalLatencyExpected: 50 * time.Millisecond,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
Loading…
Reference in New Issue