mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #21377 from wojtek-t/log_if_throttled
Auto commit by PR queue bot
This commit is contained in:
commit
99c1df19b1
@ -46,9 +46,15 @@ import (
|
|||||||
watchjson "k8s.io/kubernetes/pkg/watch/json"
|
watchjson "k8s.io/kubernetes/pkg/watch/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// specialParams lists parameters that are handled specially and which users of Request
|
var (
|
||||||
// are therefore not allowed to set manually.
|
// specialParams lists parameters that are handled specially and which users of Request
|
||||||
var specialParams = sets.NewString("timeout")
|
// are therefore not allowed to set manually.
|
||||||
|
specialParams = sets.NewString("timeout")
|
||||||
|
|
||||||
|
// longThrottleLatency defines threshold for logging requests. All requests being
|
||||||
|
// throttle for more than longThrottleLatency will be logged.
|
||||||
|
longThrottleLatency = 50 * time.Millisecond
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
metrics.Register()
|
metrics.Register()
|
||||||
@ -612,6 +618,16 @@ func (r Request) finalURLTemplate() string {
|
|||||||
return r.URL().String()
|
return r.URL().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Request) tryThrottle() {
|
||||||
|
now := time.Now()
|
||||||
|
if r.throttle != nil {
|
||||||
|
r.throttle.Accept()
|
||||||
|
}
|
||||||
|
if latency := time.Since(now); latency > longThrottleLatency {
|
||||||
|
glog.Warningf("Throttling request took %v, request: %s", latency, r.URL().String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Watch attempts to begin watching the requested location.
|
// Watch attempts to begin watching the requested location.
|
||||||
// Returns a watch.Interface, or an error.
|
// Returns a watch.Interface, or an error.
|
||||||
func (r *Request) Watch() (watch.Interface, error) {
|
func (r *Request) Watch() (watch.Interface, error) {
|
||||||
@ -683,9 +699,7 @@ func (r *Request) Stream() (io.ReadCloser, error) {
|
|||||||
return nil, r.err
|
return nil, r.err
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.throttle != nil {
|
r.tryThrottle()
|
||||||
r.throttle.Accept()
|
|
||||||
}
|
|
||||||
|
|
||||||
url := r.URL().String()
|
url := r.URL().String()
|
||||||
req, err := http.NewRequest(r.verb, url, nil)
|
req, err := http.NewRequest(r.verb, url, nil)
|
||||||
@ -819,9 +833,7 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
|
|||||||
// * If the server responds with a status: *errors.StatusError or *errors.UnexpectedObjectError
|
// * If the server responds with a status: *errors.StatusError or *errors.UnexpectedObjectError
|
||||||
// * http.Client.Do errors are returned directly.
|
// * http.Client.Do errors are returned directly.
|
||||||
func (r *Request) Do() Result {
|
func (r *Request) Do() Result {
|
||||||
if r.throttle != nil {
|
r.tryThrottle()
|
||||||
r.throttle.Accept()
|
|
||||||
}
|
|
||||||
|
|
||||||
var result Result
|
var result Result
|
||||||
err := r.request(func(req *http.Request, resp *http.Response) {
|
err := r.request(func(req *http.Request, resp *http.Response) {
|
||||||
@ -835,9 +847,7 @@ func (r *Request) Do() Result {
|
|||||||
|
|
||||||
// DoRaw executes the request but does not process the response body.
|
// DoRaw executes the request but does not process the response body.
|
||||||
func (r *Request) DoRaw() ([]byte, error) {
|
func (r *Request) DoRaw() ([]byte, error) {
|
||||||
if r.throttle != nil {
|
r.tryThrottle()
|
||||||
r.throttle.Accept()
|
|
||||||
}
|
|
||||||
|
|
||||||
var result Result
|
var result Result
|
||||||
err := r.request(func(req *http.Request, resp *http.Response) {
|
err := r.request(func(req *http.Request, resp *http.Response) {
|
||||||
|
Loading…
Reference in New Issue
Block a user