P&F: clean up mutating work estimator tests
Kubernetes-commit: 943bc38c0e0076935701d32067d5a2d8d512be8a
This commit is contained in:
parent
ecb503ed6a
commit
9c98ce48a5
|
@ -24,27 +24,36 @@ import (
|
||||||
apirequest "k8s.io/apiserver/pkg/endpoints/request"
|
apirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
watchesPerSeat = 10.0
|
||||||
|
eventAdditionalDuration = 5 * time.Millisecond
|
||||||
|
// TODO(wojtekt): Remove it once we tune the algorithm to not fail
|
||||||
|
// scalability tests.
|
||||||
|
enableMutatingWorkEstimator = false
|
||||||
|
)
|
||||||
|
|
||||||
func newMutatingWorkEstimator(countFn watchCountGetterFunc) WorkEstimatorFunc {
|
func newMutatingWorkEstimator(countFn watchCountGetterFunc) WorkEstimatorFunc {
|
||||||
|
return newTestMutatingWorkEstimator(countFn, enableMutatingWorkEstimator)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestMutatingWorkEstimator(countFn watchCountGetterFunc, enabled bool) WorkEstimatorFunc {
|
||||||
estimator := &mutatingWorkEstimator{
|
estimator := &mutatingWorkEstimator{
|
||||||
countFn: countFn,
|
countFn: countFn,
|
||||||
|
enabled: enabled,
|
||||||
}
|
}
|
||||||
return estimator.estimate
|
return estimator.estimate
|
||||||
}
|
}
|
||||||
|
|
||||||
type mutatingWorkEstimator struct {
|
type mutatingWorkEstimator struct {
|
||||||
countFn watchCountGetterFunc
|
countFn watchCountGetterFunc
|
||||||
|
enabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
watchesPerSeat = 10.0
|
|
||||||
eventAdditionalDuration = 5 * time.Millisecond
|
|
||||||
)
|
|
||||||
|
|
||||||
func (e *mutatingWorkEstimator) estimate(r *http.Request) WorkEstimate {
|
func (e *mutatingWorkEstimator) estimate(r *http.Request) WorkEstimate {
|
||||||
// TODO(wojtekt): Remove once we tune the algorithm to not fail
|
if (!e.enabled) {
|
||||||
// scalability tests.
|
return WorkEstimate{
|
||||||
return WorkEstimate{
|
InitialSeats: 1,
|
||||||
InitialSeats: 1,
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
requestInfo, ok := apirequest.RequestInfoFrom(r.Context())
|
requestInfo, ok := apirequest.RequestInfoFrom(r.Context())
|
||||||
|
|
|
@ -252,136 +252,132 @@ func TestWorkEstimator(t *testing.T) {
|
||||||
countErr: errors.New("unknown error"),
|
countErr: errors.New("unknown error"),
|
||||||
initialSeatsExpected: maximumSeats,
|
initialSeatsExpected: maximumSeats,
|
||||||
},
|
},
|
||||||
// TODO(wojtekt): Reenable these tests after tuning algorithm to
|
{
|
||||||
// not fail scalability tests.
|
name: "request verb is create, no watches",
|
||||||
/*
|
requestURI: "http://server/apis/foo.bar/v1/foos",
|
||||||
{
|
requestInfo: &apirequest.RequestInfo{
|
||||||
name: "request verb is create, no watches",
|
Verb: "create",
|
||||||
requestURI: "http://server/apis/foo.bar/v1/foos",
|
APIGroup: "foo.bar",
|
||||||
requestInfo: &apirequest.RequestInfo{
|
Resource: "foos",
|
||||||
Verb: "create",
|
|
||||||
APIGroup: "foo.bar",
|
|
||||||
Resource: "foos",
|
|
||||||
},
|
|
||||||
initialSeatsExpected: 1,
|
|
||||||
finalSeatsExpected: 0,
|
|
||||||
additionalLatencyExpected: 0,
|
|
||||||
},
|
},
|
||||||
{
|
initialSeatsExpected: 1,
|
||||||
name: "request verb is create, watches registered",
|
finalSeatsExpected: 0,
|
||||||
requestURI: "http://server/apis/foo.bar/v1/foos",
|
additionalLatencyExpected: 0,
|
||||||
requestInfo: &apirequest.RequestInfo{
|
},
|
||||||
Verb: "create",
|
{
|
||||||
APIGroup: "foo.bar",
|
name: "request verb is create, watches registered",
|
||||||
Resource: "foos",
|
requestURI: "http://server/apis/foo.bar/v1/foos",
|
||||||
},
|
requestInfo: &apirequest.RequestInfo{
|
||||||
watchCount: 29,
|
Verb: "create",
|
||||||
initialSeatsExpected: 1,
|
APIGroup: "foo.bar",
|
||||||
finalSeatsExpected: 3,
|
Resource: "foos",
|
||||||
additionalLatencyExpected: 5 * time.Millisecond,
|
|
||||||
},
|
},
|
||||||
{
|
watchCount: 29,
|
||||||
name: "request verb is create, watches registered, no additional latency",
|
initialSeatsExpected: 1,
|
||||||
requestURI: "http://server/apis/foo.bar/v1/foos",
|
finalSeatsExpected: 3,
|
||||||
requestInfo: &apirequest.RequestInfo{
|
additionalLatencyExpected: 5 * time.Millisecond,
|
||||||
Verb: "create",
|
},
|
||||||
APIGroup: "foo.bar",
|
{
|
||||||
Resource: "foos",
|
name: "request verb is create, watches registered, no additional latency",
|
||||||
},
|
requestURI: "http://server/apis/foo.bar/v1/foos",
|
||||||
watchCount: 5,
|
requestInfo: &apirequest.RequestInfo{
|
||||||
initialSeatsExpected: 1,
|
Verb: "create",
|
||||||
finalSeatsExpected: 0,
|
APIGroup: "foo.bar",
|
||||||
additionalLatencyExpected: 0,
|
Resource: "foos",
|
||||||
},
|
},
|
||||||
{
|
watchCount: 5,
|
||||||
name: "request verb is create, watches registered, maximum is exceeded",
|
initialSeatsExpected: 1,
|
||||||
requestURI: "http://server/apis/foo.bar/v1/foos",
|
finalSeatsExpected: 0,
|
||||||
requestInfo: &apirequest.RequestInfo{
|
additionalLatencyExpected: 0,
|
||||||
Verb: "create",
|
},
|
||||||
APIGroup: "foo.bar",
|
{
|
||||||
Resource: "foos",
|
name: "request verb is create, watches registered, maximum is exceeded",
|
||||||
},
|
requestURI: "http://server/apis/foo.bar/v1/foos",
|
||||||
watchCount: 199,
|
requestInfo: &apirequest.RequestInfo{
|
||||||
initialSeatsExpected: 1,
|
Verb: "create",
|
||||||
finalSeatsExpected: 20,
|
APIGroup: "foo.bar",
|
||||||
additionalLatencyExpected: 5 * time.Millisecond,
|
Resource: "foos",
|
||||||
},
|
},
|
||||||
{
|
watchCount: 199,
|
||||||
name: "request verb is update, no watches",
|
initialSeatsExpected: 1,
|
||||||
requestURI: "http://server/apis/foo.bar/v1/foos/myfoo",
|
finalSeatsExpected: 20,
|
||||||
requestInfo: &apirequest.RequestInfo{
|
additionalLatencyExpected: 5 * time.Millisecond,
|
||||||
Verb: "update",
|
},
|
||||||
APIGroup: "foo.bar",
|
{
|
||||||
Resource: "foos",
|
name: "request verb is update, no watches",
|
||||||
},
|
requestURI: "http://server/apis/foo.bar/v1/foos/myfoo",
|
||||||
initialSeatsExpected: 1,
|
requestInfo: &apirequest.RequestInfo{
|
||||||
finalSeatsExpected: 0,
|
Verb: "update",
|
||||||
additionalLatencyExpected: 0,
|
APIGroup: "foo.bar",
|
||||||
|
Resource: "foos",
|
||||||
},
|
},
|
||||||
{
|
initialSeatsExpected: 1,
|
||||||
name: "request verb is update, watches registered",
|
finalSeatsExpected: 0,
|
||||||
requestURI: "http://server/apis/foor.bar/v1/foos/myfoo",
|
additionalLatencyExpected: 0,
|
||||||
requestInfo: &apirequest.RequestInfo{
|
},
|
||||||
Verb: "update",
|
{
|
||||||
APIGroup: "foo.bar",
|
name: "request verb is update, watches registered",
|
||||||
Resource: "foos",
|
requestURI: "http://server/apis/foor.bar/v1/foos/myfoo",
|
||||||
},
|
requestInfo: &apirequest.RequestInfo{
|
||||||
watchCount: 29,
|
Verb: "update",
|
||||||
initialSeatsExpected: 1,
|
APIGroup: "foo.bar",
|
||||||
finalSeatsExpected: 3,
|
Resource: "foos",
|
||||||
additionalLatencyExpected: 5 * time.Millisecond,
|
|
||||||
},
|
},
|
||||||
{
|
watchCount: 29,
|
||||||
name: "request verb is patch, no watches",
|
initialSeatsExpected: 1,
|
||||||
requestURI: "http://server/apis/foo.bar/v1/foos/myfoo",
|
finalSeatsExpected: 3,
|
||||||
requestInfo: &apirequest.RequestInfo{
|
additionalLatencyExpected: 5 * time.Millisecond,
|
||||||
Verb: "patch",
|
},
|
||||||
APIGroup: "foo.bar",
|
{
|
||||||
Resource: "foos",
|
name: "request verb is patch, no watches",
|
||||||
},
|
requestURI: "http://server/apis/foo.bar/v1/foos/myfoo",
|
||||||
initialSeatsExpected: 1,
|
requestInfo: &apirequest.RequestInfo{
|
||||||
finalSeatsExpected: 0,
|
Verb: "patch",
|
||||||
additionalLatencyExpected: 0,
|
APIGroup: "foo.bar",
|
||||||
|
Resource: "foos",
|
||||||
},
|
},
|
||||||
{
|
initialSeatsExpected: 1,
|
||||||
name: "request verb is patch, watches registered",
|
finalSeatsExpected: 0,
|
||||||
requestURI: "http://server/apis/foo.bar/v1/foos/myfoo",
|
additionalLatencyExpected: 0,
|
||||||
requestInfo: &apirequest.RequestInfo{
|
},
|
||||||
Verb: "patch",
|
{
|
||||||
APIGroup: "foo.bar",
|
name: "request verb is patch, watches registered",
|
||||||
Resource: "foos",
|
requestURI: "http://server/apis/foo.bar/v1/foos/myfoo",
|
||||||
},
|
requestInfo: &apirequest.RequestInfo{
|
||||||
watchCount: 29,
|
Verb: "patch",
|
||||||
initialSeatsExpected: 1,
|
APIGroup: "foo.bar",
|
||||||
finalSeatsExpected: 3,
|
Resource: "foos",
|
||||||
additionalLatencyExpected: 5 * time.Millisecond,
|
|
||||||
},
|
},
|
||||||
{
|
watchCount: 29,
|
||||||
name: "request verb is delete, no watches",
|
initialSeatsExpected: 1,
|
||||||
requestURI: "http://server/apis/foo.bar/v1/foos/myfoo",
|
finalSeatsExpected: 3,
|
||||||
requestInfo: &apirequest.RequestInfo{
|
additionalLatencyExpected: 5 * time.Millisecond,
|
||||||
Verb: "delete",
|
},
|
||||||
APIGroup: "foo.bar",
|
{
|
||||||
Resource: "foos",
|
name: "request verb is delete, no watches",
|
||||||
},
|
requestURI: "http://server/apis/foo.bar/v1/foos/myfoo",
|
||||||
initialSeatsExpected: 1,
|
requestInfo: &apirequest.RequestInfo{
|
||||||
finalSeatsExpected: 0,
|
Verb: "delete",
|
||||||
additionalLatencyExpected: 0,
|
APIGroup: "foo.bar",
|
||||||
|
Resource: "foos",
|
||||||
},
|
},
|
||||||
{
|
initialSeatsExpected: 1,
|
||||||
name: "request verb is delete, watches registered",
|
finalSeatsExpected: 0,
|
||||||
requestURI: "http://server/apis/foo.bar/v1/foos/myfoo",
|
additionalLatencyExpected: 0,
|
||||||
requestInfo: &apirequest.RequestInfo{
|
},
|
||||||
Verb: "delete",
|
{
|
||||||
APIGroup: "foo.bar",
|
name: "request verb is delete, watches registered",
|
||||||
Resource: "foos",
|
requestURI: "http://server/apis/foo.bar/v1/foos/myfoo",
|
||||||
},
|
requestInfo: &apirequest.RequestInfo{
|
||||||
watchCount: 29,
|
Verb: "delete",
|
||||||
initialSeatsExpected: 1,
|
APIGroup: "foo.bar",
|
||||||
finalSeatsExpected: 3,
|
Resource: "foos",
|
||||||
additionalLatencyExpected: 5 * time.Millisecond,
|
|
||||||
},
|
},
|
||||||
*/
|
watchCount: 29,
|
||||||
|
initialSeatsExpected: 1,
|
||||||
|
finalSeatsExpected: 3,
|
||||||
|
additionalLatencyExpected: 5 * time.Millisecond,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
@ -396,7 +392,14 @@ func TestWorkEstimator(t *testing.T) {
|
||||||
watchCountsFn := func(_ *apirequest.RequestInfo) int {
|
watchCountsFn := func(_ *apirequest.RequestInfo) int {
|
||||||
return test.watchCount
|
return test.watchCount
|
||||||
}
|
}
|
||||||
estimator := NewWorkEstimator(countsFn, watchCountsFn)
|
|
||||||
|
// TODO(wojtek-t): Simplify it once we enable mutating work estimator
|
||||||
|
// by default.
|
||||||
|
testEstimator := &workEstimator{
|
||||||
|
listWorkEstimator: newListWorkEstimator(countsFn),
|
||||||
|
mutatingWorkEstimator: newTestMutatingWorkEstimator(watchCountsFn, true),
|
||||||
|
}
|
||||||
|
estimator := WorkEstimatorFunc(testEstimator.estimate)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", test.requestURI, nil)
|
req, err := http.NewRequest("GET", test.requestURI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue