P&F: Update WatchTracker interface to pass more information
Kubernetes-commit: 12746f4bc15458d585ffd4c6e9d6066810e27361
This commit is contained in:
parent
9187c5069a
commit
9ad8b586fc
|
@ -186,7 +186,7 @@ func WithPriorityAndFairness(
|
|||
served = true
|
||||
setResponseHeaders(classification, w)
|
||||
|
||||
forgetWatch = fcIfc.RegisterWatch(requestInfo)
|
||||
forgetWatch = fcIfc.RegisterWatch(r)
|
||||
|
||||
// Notify the main thread that we're ready to start the watch.
|
||||
close(shouldStartWatchCh)
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package flowcontrol
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
|
@ -51,10 +52,10 @@ type ForgetWatchFunc func()
|
|||
// of watches in the system for the purpose of estimating the
|
||||
// cost of incoming mutating requests.
|
||||
type WatchTracker interface {
|
||||
// RegisterWatch reqisters a watch with the provided requestInfo
|
||||
// RegisterWatch reqisters a watch based on the provided http.Request
|
||||
// in the tracker. It returns the function that should be called
|
||||
// to forget the watcher once it is finished.
|
||||
RegisterWatch(requestInfo *request.RequestInfo) ForgetWatchFunc
|
||||
RegisterWatch(r *http.Request) ForgetWatchFunc
|
||||
|
||||
// GetInterestedWatchCount returns the number of watches that are
|
||||
// potentially interested in a request with a given RequestInfo
|
||||
|
@ -77,8 +78,9 @@ func NewWatchTracker() WatchTracker {
|
|||
}
|
||||
|
||||
// RegisterWatch implements WatchTracker interface.
|
||||
func (w *watchTracker) RegisterWatch(requestInfo *request.RequestInfo) ForgetWatchFunc {
|
||||
if requestInfo == nil || requestInfo.Verb != "watch" {
|
||||
func (w *watchTracker) RegisterWatch(r *http.Request) ForgetWatchFunc {
|
||||
requestInfo, ok := request.RequestInfoFrom(r.Context())
|
||||
if !ok || requestInfo == nil || requestInfo.Verb != "watch" {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package flowcontrol
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
@ -107,8 +108,10 @@ func TestRegisterWatch(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unexpected error from requestInfo creation: %#v", err)
|
||||
}
|
||||
ctx := request.WithRequestInfo(context.Background(), requestInfo)
|
||||
r := testCase.request.WithContext(ctx)
|
||||
|
||||
forget := watchTracker.RegisterWatch(requestInfo)
|
||||
forget := watchTracker.RegisterWatch(r)
|
||||
if testCase.expected == nil {
|
||||
if forget != nil {
|
||||
t.Errorf("unexpected watch registered: %#v", watchTracker.watchCount)
|
||||
|
@ -151,7 +154,8 @@ func TestGetInterestedWatchCount(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unexpected error from requestInfo creation: %#v", err)
|
||||
}
|
||||
if forget := watchTracker.RegisterWatch(requestInfo); forget == nil {
|
||||
r := req.WithContext(request.WithRequestInfo(context.Background(), requestInfo))
|
||||
if forget := watchTracker.RegisterWatch(r); forget == nil {
|
||||
t.Errorf("watch wasn't registered: %#v", requestInfo)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue