diff options
| author | KubeEdge Bot <48982446+kubeedge-bot@users.noreply.github.com> | 2024-07-11 10:16:54 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-11 10:16:54 +0800 |
| commit | 530bedfb151c4d1ac226c14a332fde59c7f2266c (patch) | |
| tree | 3ec616656344be9013c26929e03347bb12c35c82 /vendor/github.com/googleapis/gax-go/v2/call_option.go | |
| parent | Merge pull request #5545 from luomengY/automated-cherry-pick-of-#5467-upstrea... (diff) | |
| parent | update k8s version to v1.27.15 in CI (diff) | |
| download | kubeedge-530bedfb151c4d1ac226c14a332fde59c7f2266c.tar.gz | |
Merge pull request #5699 from Shelley-BaoYue/bump-k8s-v1.27.15
Bump k8s from v1.27.7 to v1.27.15
Diffstat (limited to 'vendor/github.com/googleapis/gax-go/v2/call_option.go')
| -rw-r--r-- | vendor/github.com/googleapis/gax-go/v2/call_option.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/github.com/googleapis/gax-go/v2/call_option.go b/vendor/github.com/googleapis/gax-go/v2/call_option.go index 425a7668d..e09200556 100644 --- a/vendor/github.com/googleapis/gax-go/v2/call_option.go +++ b/vendor/github.com/googleapis/gax-go/v2/call_option.go @@ -30,9 +30,11 @@ package gax import ( + "errors" "math/rand" "time" + "google.golang.org/api/googleapi" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -119,6 +121,41 @@ func (r *boRetryer) Retry(err error) (time.Duration, bool) { return 0, false } +// OnHTTPCodes returns a Retryer that retries if and only if +// the previous attempt returns a googleapi.Error whose status code is stored in +// cc. Pause times between retries are specified by bo. +// +// bo is only used for its parameters; each Retryer has its own copy. +func OnHTTPCodes(bo Backoff, cc ...int) Retryer { + codes := make(map[int]bool, len(cc)) + for _, c := range cc { + codes[c] = true + } + + return &httpRetryer{ + backoff: bo, + codes: codes, + } +} + +type httpRetryer struct { + backoff Backoff + codes map[int]bool +} + +func (r *httpRetryer) Retry(err error) (time.Duration, bool) { + var gerr *googleapi.Error + if !errors.As(err, &gerr) { + return 0, false + } + + if r.codes[gerr.Code] { + return r.backoff.Pause(), true + } + + return 0, false +} + // Backoff implements exponential backoff. The wait time between retries is a // random value between 0 and the "retry period" - the time between retries. The // retry period starts at Initial and increases by the factor of Multiplier @@ -173,6 +210,21 @@ func (o grpcOpt) Resolve(s *CallSettings) { s.GRPC = o } +type pathOpt struct { + p string +} + +func (p pathOpt) Resolve(s *CallSettings) { + s.Path = p.p +} + +// WithPath applies a Path override to the HTTP-based APICall. +// +// This is for internal use only. +func WithPath(p string) CallOption { + return &pathOpt{p: p} +} + // WithGRPCOptions allows passing gRPC call options during client creation. func WithGRPCOptions(opt ...grpc.CallOption) CallOption { return grpcOpt(append([]grpc.CallOption(nil), opt...)) @@ -186,4 +238,7 @@ type CallSettings struct { // CallOptions to be forwarded to GRPC. GRPC []grpc.CallOption + + // Path is an HTTP override for an APICall. + Path string } |
