P&F: clean up mutating work estimator tests

This commit is contained in:
Wojciech Tyczyński 2021-10-27 10:05:13 +02:00
parent fa6bb7cad0
commit 943bc38c0e
2 changed files with 142 additions and 130 deletions

View File

@ -24,28 +24,37 @@ import (
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 {
return newTestMutatingWorkEstimator(countFn, enableMutatingWorkEstimator)
}
func newTestMutatingWorkEstimator(countFn watchCountGetterFunc, enabled bool) WorkEstimatorFunc {
estimator := &mutatingWorkEstimator{
countFn: countFn,
enabled: enabled,
}
return estimator.estimate
}
type mutatingWorkEstimator struct {
countFn watchCountGetterFunc
enabled bool
}
const (
watchesPerSeat = 10.0
eventAdditionalDuration = 5 * time.Millisecond
)
func (e *mutatingWorkEstimator) estimate(r *http.Request) WorkEstimate {
// TODO(wojtekt): Remove once we tune the algorithm to not fail
// scalability tests.
if (!e.enabled) {
return WorkEstimate{
InitialSeats: 1,
}
}
requestInfo, ok := apirequest.RequestInfoFrom(r.Context())
if !ok {

View File

@ -252,9 +252,6 @@ func TestWorkEstimator(t *testing.T) {
countErr: errors.New("unknown error"),
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",
@ -381,7 +378,6 @@ func TestWorkEstimator(t *testing.T) {
finalSeatsExpected: 3,
additionalLatencyExpected: 5 * time.Millisecond,
},
*/
}
for _, test := range tests {
@ -396,7 +392,14 @@ func TestWorkEstimator(t *testing.T) {
watchCountsFn := func(_ *apirequest.RequestInfo) int {
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)
if err != nil {