Merge pull request #109188 from wojtek-t/pf_mitigate_delegated_requests

Fix the overestimated cost of deletaged API requests in P&F

Kubernetes-commit: 885f14d162471dfc9a3f8d4c46430805cf6be828
This commit is contained in:
Kubernetes Publisher 2022-03-31 15:49:17 -07:00
commit 1561dcc9b6
4 changed files with 26 additions and 20 deletions

12
go.mod
View File

@ -42,10 +42,10 @@ require (
google.golang.org/grpc v1.40.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/square/go-jose.v2 v2.2.2
k8s.io/api v0.0.0-20220331051217-290a349b5385
k8s.io/api v0.0.0-20220331173702-ec84bcb48bd6
k8s.io/apimachinery v0.0.0-20220330050810-6550efdb7444
k8s.io/client-go v0.0.0-20220331051643-092a109b2b10
k8s.io/component-base v0.0.0-20220330051900-ffc9c87ab39a
k8s.io/client-go v0.0.0-20220331171325-8a672f0fd284
k8s.io/component-base v0.0.0-20220331212037-3b9b201c27aa
k8s.io/klog/v2 v2.60.1
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
@ -56,8 +56,8 @@ require (
)
replace (
k8s.io/api => k8s.io/api v0.0.0-20220331051217-290a349b5385
k8s.io/api => k8s.io/api v0.0.0-20220331173702-ec84bcb48bd6
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20220330050810-6550efdb7444
k8s.io/client-go => k8s.io/client-go v0.0.0-20220331051643-092a109b2b10
k8s.io/component-base => k8s.io/component-base v0.0.0-20220330051900-ffc9c87ab39a
k8s.io/client-go => k8s.io/client-go v0.0.0-20220331171325-8a672f0fd284
k8s.io/component-base => k8s.io/component-base v0.0.0-20220331212037-3b9b201c27aa
)

12
go.sum
View File

@ -954,14 +954,14 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.0.0-20220331051217-290a349b5385 h1:f+qAtGb6ikFhuwOgV62s33+xw7QCi0hrywLfkBtCVRw=
k8s.io/api v0.0.0-20220331051217-290a349b5385/go.mod h1:69QWTzqWVlGn0rU+x3dmk3WAsUQHmeQwIBWMbK1ZEyE=
k8s.io/api v0.0.0-20220331173702-ec84bcb48bd6 h1:EEp8lRTtkXiT5LGxE3PKf3rLvHu5ffQiNNbb9fUT5gI=
k8s.io/api v0.0.0-20220331173702-ec84bcb48bd6/go.mod h1:69QWTzqWVlGn0rU+x3dmk3WAsUQHmeQwIBWMbK1ZEyE=
k8s.io/apimachinery v0.0.0-20220330050810-6550efdb7444 h1:whQmS3GtF822OUer+LPJnMFKn6kPfuJOCM/3xUuATIY=
k8s.io/apimachinery v0.0.0-20220330050810-6550efdb7444/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2UM=
k8s.io/client-go v0.0.0-20220331051643-092a109b2b10 h1:+HZfIcTvYmLQzSP2aDvzBMl1e1kbtJv2j8q/CJ1hz98=
k8s.io/client-go v0.0.0-20220331051643-092a109b2b10/go.mod h1:5KZ2g659eywPk2o9iKo72HhEqqiuTWOrlVyB03peN7k=
k8s.io/component-base v0.0.0-20220330051900-ffc9c87ab39a h1:5GgsJwT9dZE4ta+/a+DDXa2FB0f7ZkmwqJbFE6CHZHo=
k8s.io/component-base v0.0.0-20220330051900-ffc9c87ab39a/go.mod h1:LJBddfwf8ppsSrBEKyFor1D79VOnf+xhBp7/sE+XB/E=
k8s.io/client-go v0.0.0-20220331171325-8a672f0fd284 h1:1l3RyTAyI3yERueHVLMy8T+cCO+En4Dqn+K4Yr+KwZU=
k8s.io/client-go v0.0.0-20220331171325-8a672f0fd284/go.mod h1:ewG6GJpur1bhlVrw9LJD3Bacj/woXhx4XVWTOUw6jkA=
k8s.io/component-base v0.0.0-20220331212037-3b9b201c27aa h1:HXrw3PNPz5LUdx4tWHrhjcRadLTrUmerZmNc4MRYuOg=
k8s.io/component-base v0.0.0-20220331212037-3b9b201c27aa/go.mod h1:3bhERi0RMmLibjhzQTaOenaiYbqZrwtoCRd58dbFtDk=
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=

View File

@ -68,17 +68,23 @@ func (e *listWorkEstimator) estimate(r *http.Request, flowSchemaName, priorityLe
// pruner will eventually remove the CRD from the cache.
return WorkEstimate{InitialSeats: maximumSeats}
case err == ObjectCountNotFoundErr:
// there are two scenarios in which we can see this error:
// there are multiple scenarios in which we can see this error:
// a. the type is truly unknown, a typo on the caller's part.
// b. the count has gone stale for too long and the pruner
// has removed the type from the cache.
// we don't have a way to distinguish between a and b. b seems to indicate
// to a more severe case of degradation, although b can naturally trigger
// when a CRD is removed. let's be conservative and allocate maximum seats.
return WorkEstimate{InitialSeats: maximumSeats}
// c. the type is an aggregated resource that is served by a
// different apiserver (thus its object count is not updated)
// we don't have a way to distinguish between those situations.
// However, in case c, the request is delegated to a different apiserver,
// and thus its cost for our server is minimal. To avoid the situation
// when aggregated API calls are overestimated, we allocate the minimum
// possible seats (see #109106 as an example when being more conservative
// led to problems).
return WorkEstimate{InitialSeats: minimumSeats}
case err != nil:
// we should never be here since Get returns either ObjectCountStaleErr or
// ObjectCountNotFoundErr, return maximumSeats to be on the safe side.
klog.ErrorS(err, "Unexpected error from object count tracker")
return WorkEstimate{InitialSeats: maximumSeats}
}

View File

@ -125,7 +125,7 @@ func TestWorkEstimator(t *testing.T) {
Resource: "events",
},
countErr: ObjectCountNotFoundErr,
initialSeatsExpected: maximumSeats,
initialSeatsExpected: minimumSeats,
},
{
name: "request verb is list, continuation is set",
@ -214,7 +214,7 @@ func TestWorkEstimator(t *testing.T) {
Resource: "events",
},
countErr: ObjectCountNotFoundErr,
initialSeatsExpected: maximumSeats,
initialSeatsExpected: minimumSeats,
},
{
name: "request verb is list, object count is stale",
@ -239,7 +239,7 @@ func TestWorkEstimator(t *testing.T) {
Resource: "events",
},
countErr: ObjectCountNotFoundErr,
initialSeatsExpected: maximumSeats,
initialSeatsExpected: minimumSeats,
},
{
name: "request verb is list, count getter throws unknown error",