mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
P&F: clean up mutating work estimator tests
This commit is contained in:
parent
fa6bb7cad0
commit
943bc38c0e
@ -24,28 +24,37 @@ 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())
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -252,9 +252,6 @@ 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",
|
name: "request verb is create, no watches",
|
||||||
requestURI: "http://server/apis/foo.bar/v1/foos",
|
requestURI: "http://server/apis/foo.bar/v1/foos",
|
||||||
@ -381,7 +378,6 @@ func TestWorkEstimator(t *testing.T) {
|
|||||||
finalSeatsExpected: 3,
|
finalSeatsExpected: 3,
|
||||||
additionalLatencyExpected: 5 * time.Millisecond,
|
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
Block a user