From 09f1ce9ec821c14013c775ba106e4888cb29c2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Zi=C4=99ba?= Date: Mon, 19 Sep 2022 07:42:45 +0000 Subject: [PATCH] Fix list estimator for lists that are executed as gets --- .../request/list_work_estimator.go | 9 ++++++ .../util/flowcontrol/request/width_test.go | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/request/list_work_estimator.go b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/request/list_work_estimator.go index 4771fcdecfe..75d70a0ad46 100644 --- a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/request/list_work_estimator.go +++ b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/request/list_work_estimator.go @@ -50,6 +50,15 @@ func (e *listWorkEstimator) estimate(r *http.Request, flowSchemaName, priorityLe return WorkEstimate{InitialSeats: e.config.MaximumSeats} } + if requestInfo.Name != "" { + // Requests with metadata.name specified are usually executed as get + // requests in storage layer so their width should be 1. + // Example of such list requests: + // /apis/certificates.k8s.io/v1/certificatesigningrequests?fieldSelector=metadata.name%3Dcsr-xxs4m + // /api/v1/namespaces/test/configmaps?fieldSelector=metadata.name%3Dbig-deployment-1&limit=500&resourceVersion=0 + return WorkEstimate{InitialSeats: e.config.MinimumSeats} + } + query := r.URL.Query() listOptions := metav1.ListOptions{} if err := metav1.Convert_url_Values_To_v1_ListOptions(&query, &listOptions, nil); err != nil { diff --git a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/request/width_test.go b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/request/width_test.go index 315e05d4587..c51164488a2 100644 --- a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/request/width_test.go +++ b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/request/width_test.go @@ -256,6 +256,34 @@ func TestWorkEstimator(t *testing.T) { countErr: errors.New("unknown error"), initialSeatsExpected: maximumSeats, }, + { + name: "request verb is list, metadata.name specified", + requestURI: "http://server/apis/foo.bar/v1/events?fieldSelector=metadata.name%3Dtest", + requestInfo: &apirequest.RequestInfo{ + Verb: "list", + Name: "test", + APIGroup: "foo.bar", + Resource: "events", + }, + counts: map[string]int64{ + "events.foo.bar": 799, + }, + initialSeatsExpected: minimumSeats, + }, + { + name: "request verb is list, metadata.name, resourceVersion and limit specified", + requestURI: "http://server/apis/foo.bar/v1/events?fieldSelector=metadata.name%3Dtest&limit=500&resourceVersion=0", + requestInfo: &apirequest.RequestInfo{ + Verb: "list", + Name: "test", + APIGroup: "foo.bar", + Resource: "events", + }, + counts: map[string]int64{ + "events.foo.bar": 799, + }, + initialSeatsExpected: minimumSeats, + }, { name: "request verb is create, no watches", requestURI: "http://server/apis/foo.bar/v1/foos",