Skip to content

Commit c9f80c2

Browse files
committed
addressed feedback
1 parent e464ca7 commit c9f80c2

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
golang 1.24.0
1+
golang 1.24.2
22
protoc 25.1
33
protoc-gen-go-grpc 1.3.0
44
golangci-lint 1.64.8

pkg/beholder/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func NewGRPCClient(cfg Config, otlploggrpcNew otlploggrpcFactory) (*Client, erro
9797
}
9898
if cfg.LogRetryConfig != nil {
9999
// NOTE: By default, the retry is enabled in the OTel SDK
100-
opts = append(opts, otlploggrpc.WithRetry(otlploggrpc.RetryConfig{
100+
opts = append(opts, otlploggrpc.With(otlploggrpc.RetryConfig{
101101
Enabled: cfg.LogRetryConfig.Enabled(),
102102
InitialInterval: cfg.LogRetryConfig.GetInitialInterval(),
103103
MaxInterval: cfg.LogRetryConfig.GetMaxInterval(),
@@ -332,7 +332,7 @@ func newTracerProvider(config Config, resource *sdkresource.Resource, creds cred
332332
}
333333
if config.TraceRetryConfig != nil {
334334
// NOTE: By default, the retry is enabled in the OTel SDK
335-
exporterOpts = append(exporterOpts, otlptracegrpc.WithRetry(otlptracegrpc.RetryConfig{
335+
exporterOpts = append(exporterOpts, otlptracegrpc.With(otlptracegrpc.RetryConfig{
336336
Enabled: config.TraceRetryConfig.Enabled(),
337337
InitialInterval: config.TraceRetryConfig.GetInitialInterval(),
338338
MaxInterval: config.TraceRetryConfig.GetMaxInterval(),
@@ -372,7 +372,7 @@ func newMeterProvider(config Config, resource *sdkresource.Resource, creds crede
372372
}
373373
if config.MetricRetryConfig != nil {
374374
// NOTE: By default, the retry is enabled in the OTel SDK
375-
opts = append(opts, otlpmetricgrpc.WithRetry(otlpmetricgrpc.RetryConfig{
375+
opts = append(opts, otlpmetricgrpc.With(otlpmetricgrpc.RetryConfig{
376376
Enabled: config.MetricRetryConfig.Enabled(),
377377
InitialInterval: config.MetricRetryConfig.GetInitialInterval(),
378378
MaxInterval: config.MetricRetryConfig.GetMaxInterval(),

pkg/beholder/httpclient.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func NewHTTPClient(cfg Config, otlploghttpNew otlploghttpFactory) (*Client, erro
6363
}
6464
if cfg.LogRetryConfig != nil {
6565
// NOTE: By default, the retry is enabled in the OTel SDK
66-
opts = append(opts, otlploghttp.WithRetry(otlploghttp.RetryConfig{
66+
opts = append(opts, otlploghttp.With(otlploghttp.RetryConfig{
6767
Enabled: cfg.LogRetryConfig.Enabled(),
6868
InitialInterval: cfg.LogRetryConfig.GetInitialInterval(),
6969
MaxInterval: cfg.LogRetryConfig.GetMaxInterval(),
@@ -196,7 +196,7 @@ func newHTTPTracerProvider(config Config, resource *sdkresource.Resource, tlsCon
196196
}
197197
if config.TraceRetryConfig != nil {
198198
// NOTE: By default, the retry is enabled in the OTel SDK
199-
exporterOpts = append(exporterOpts, otlptracehttp.WithRetry(otlptracehttp.RetryConfig{
199+
exporterOpts = append(exporterOpts, otlptracehttp.With(otlptracehttp.RetryConfig{
200200
Enabled: config.TraceRetryConfig.Enabled(),
201201
InitialInterval: config.TraceRetryConfig.GetInitialInterval(),
202202
MaxInterval: config.TraceRetryConfig.GetMaxInterval(),
@@ -241,7 +241,7 @@ func newHTTPMeterProvider(config Config, resource *sdkresource.Resource, tlsConf
241241
}
242242
if config.MetricRetryConfig != nil {
243243
// NOTE: By default, the retry is enabled in the OTel SDK
244-
opts = append(opts, otlpmetrichttp.WithRetry(otlpmetrichttp.RetryConfig{
244+
opts = append(opts, otlpmetrichttp.With(otlpmetrichttp.RetryConfig{
245245
Enabled: config.MetricRetryConfig.Enabled(),
246246
InitialInterval: config.MetricRetryConfig.GetInitialInterval(),
247247
MaxInterval: config.MetricRetryConfig.GetMaxInterval(),

pkg/utils/retry/retry.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"github.com/smartcontractkit/chainlink-common/pkg/logger"
1212
)
1313

14-
// CtxKeyTracingID is the context key for tracing ID
1514
type ctxKey string
1615

17-
const CtxKeyTracingID ctxKey = "tracingID"
16+
// CtxKeyRetryID is the context key for tracing ID
17+
const CtxKeyRetryID ctxKey = "retryID"
1818

1919
// Exponential backoff (default) is used to handle retries with increasing wait times in case of errors
2020
var BackoffStrategyDefault = backoff.Backoff{
@@ -23,18 +23,18 @@ var BackoffStrategyDefault = backoff.Backoff{
2323
Factor: 2,
2424
}
2525

26-
// WithRetryStrategy applies a retry strategy to a given function.
27-
func WithRetryStrategy[R any](ctx context.Context, lggr logger.Logger, strategy backoff.Backoff, fn func(ctx context.Context) (R, error)) (R, error) {
26+
// WithStrategy applies a retry strategy to a given function.
27+
func WithStrategy[R any](ctx context.Context, lggr logger.Logger, strategy backoff.Backoff, fn func(ctx context.Context) (R, error)) (R, error) {
2828
// Generate a new tracing ID if not present, used to track retries
29-
tracingID, ok := ctx.Value(CtxKeyTracingID).(string)
29+
retryID, ok := ctx.Value(CtxKeyRetryID).(string)
3030
if !ok {
31-
tracingID = uuid.New().String()
31+
retryID = uuid.New().String()
3232
// Add the generated tracing ID to the context (as it was not already present)
33-
ctx = context.WithValue(ctx, CtxKeyTracingID, tracingID)
33+
ctx = context.WithValue(ctx, CtxKeyRetryID, retryID)
3434
}
3535

3636
// Track the number of retries
37-
numRetries := 0
37+
numRetries := int(strategy.Attempt())
3838
for {
3939
result, err := fn(ctx)
4040
if err == nil {
@@ -43,19 +43,19 @@ func WithRetryStrategy[R any](ctx context.Context, lggr logger.Logger, strategy
4343

4444
wait := strategy.Duration()
4545
message := fmt.Sprintf("Failed to execute function, retrying in %s ...", wait)
46-
lggr.Warnw(message, "wait", wait, "numRetries", numRetries, "tracingID", tracingID, "err", err)
46+
lggr.Warnw(message, "wait", wait, "numRetries", numRetries, "retryID", retryID, "err", err)
4747

4848
select {
4949
case <-ctx.Done():
50-
return result, fmt.Errorf("context done while executing function {tracingID=%s, numRetries=%d}: %w", tracingID, numRetries, ctx.Err())
50+
return result, fmt.Errorf("context done while executing function {retryID=%s, numRetries=%d}: %w", retryID, numRetries, ctx.Err())
5151
case <-time.After(wait):
5252
numRetries++
5353
// Continue with the next retry
5454
}
5555
}
5656
}
5757

58-
// WithRetry applies a default retry strategy to a given function.
59-
func WithRetry[R any](ctx context.Context, lggr logger.Logger, fn func(ctx context.Context) (R, error)) (R, error) {
60-
return WithRetryStrategy(ctx, lggr, BackoffStrategyDefault, fn)
58+
// With applies a default retry strategy to a given function.
59+
func With[R any](ctx context.Context, lggr logger.Logger, fn func(ctx context.Context) (R, error)) (R, error) {
60+
return WithStrategy(ctx, lggr, BackoffStrategyDefault, fn)
6161
}

pkg/utils/retry/retry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestWithRetry(t *testing.T) {
109109
ctx, cancel := context.WithTimeout(ctx, tt.timeout)
110110
defer cancel()
111111

112-
result, err := WithRetry(ctx, lggr, tt.fn)
112+
result, err := With(ctx, lggr, tt.fn)
113113
if tt.errMsg != "" {
114114
require.Error(t, err)
115115
require.Contains(t, err.Error(), tt.errMsg)

0 commit comments

Comments
 (0)