mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-06 01:20:40 +00:00
client-go: add metric to count retries
Kubernetes-commit: b6c369f5c90bbef8058b3d44949f4e815dd6607f
This commit is contained in:
committed by
Kubernetes Publisher
parent
f457a57d6d
commit
d2388d199c
@@ -2991,6 +2991,7 @@ type withRateLimiterBackoffManagerAndMetrics struct {
|
||||
metrics.ResultMetric
|
||||
calculateBackoffSeq int64
|
||||
calculateBackoffFn func(i int64) time.Duration
|
||||
metrics.RetryMetric
|
||||
|
||||
invokeOrderGot []string
|
||||
sleepsGot []string
|
||||
@@ -3027,6 +3028,14 @@ func (lb *withRateLimiterBackoffManagerAndMetrics) Increment(ctx context.Context
|
||||
}
|
||||
}
|
||||
|
||||
func (lb *withRateLimiterBackoffManagerAndMetrics) IncrementRetry(ctx context.Context, code, _, _ string) {
|
||||
// we are interested in the request context that is marked by this test
|
||||
if marked, ok := ctx.Value(retryTestKey).(bool); ok && marked {
|
||||
lb.invokeOrderGot = append(lb.invokeOrderGot, "RequestRetry.IncrementRetry")
|
||||
lb.statusCodesGot = append(lb.statusCodesGot, code)
|
||||
}
|
||||
}
|
||||
|
||||
func (lb *withRateLimiterBackoffManagerAndMetrics) Do() {
|
||||
lb.invokeOrderGot = append(lb.invokeOrderGot, "Client.Do")
|
||||
}
|
||||
@@ -3072,13 +3081,17 @@ func testRetryWithRateLimiterBackoffAndMetrics(t *testing.T, key string, doFunc
|
||||
"Client.Do",
|
||||
|
||||
// it's a success, so do the following:
|
||||
// - call metrics and update backoff parameters
|
||||
// count the result metric, and since it's a retry,
|
||||
// count the retry metric, and then update backoff parameters.
|
||||
"RequestResult.Increment",
|
||||
"RequestRetry.IncrementRetry",
|
||||
"BackoffManager.UpdateBackoff",
|
||||
}
|
||||
statusCodesWant := []string{
|
||||
// first attempt (A): we count the result metric only
|
||||
"500",
|
||||
"200",
|
||||
// final attempt (B): we count the result metric, and the retry metric
|
||||
"200", "200",
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -3192,10 +3205,13 @@ func testRetryWithRateLimiterBackoffAndMetrics(t *testing.T, key string, doFunc
|
||||
// to override as well, and we want tests to be able to run in
|
||||
// parallel then we will need to provide a way for tests to
|
||||
// register/deregister their own metric inerfaces.
|
||||
old := metrics.RequestResult
|
||||
oldRequestResult := metrics.RequestResult
|
||||
oldRequestRetry := metrics.RequestRetry
|
||||
metrics.RequestResult = interceptor
|
||||
metrics.RequestRetry = interceptor
|
||||
defer func() {
|
||||
metrics.RequestResult = old
|
||||
metrics.RequestResult = oldRequestResult
|
||||
metrics.RequestRetry = oldRequestRetry
|
||||
}()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
Reference in New Issue
Block a user