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