From 1c25b60040308711f24bb86840c1a19d04632db1 Mon Sep 17 00:00:00 2001 From: Donal Hurley Date: Mon, 10 Jun 2024 16:51:08 +0100 Subject: [PATCH] Fix metrics reporter retry logic (#700) --- sdk/client/metric_reporter.go | 14 +++++++++++--- .../nginx/agent/sdk/v2/client/metric_reporter.go | 14 +++++++++++--- .../nginx/agent/sdk/v2/client/metric_reporter.go | 14 +++++++++++--- .../nginx/agent/sdk/v2/client/metric_reporter.go | 14 +++++++++++--- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/sdk/client/metric_reporter.go b/sdk/client/metric_reporter.go index bfb26365aa..0bedeedd8a 100644 --- a/sdk/client/metric_reporter.go +++ b/sdk/client/metric_reporter.go @@ -116,6 +116,8 @@ func (r *metricReporter) createClient() error { r.channel = channel r.eventsChannel = eventsChannel + r.isRetrying = false + return nil } @@ -165,12 +167,12 @@ func (r *metricReporter) Send(ctx context.Context, message Message) error { } if r.channel == nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Channel Send", errors.New("metric service stream client not created yet")) } if err := r.channel.Send(report); err != nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Channel Send", err) } @@ -191,7 +193,7 @@ func (r *metricReporter) Send(ctx context.Context, message Message) error { } if err := r.eventsChannel.Send(report); err != nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Events Channel Send", err) } @@ -259,3 +261,9 @@ func (r *metricReporter) handleGrpcError(messagePrefix string, err error) error return err } + +func (r *metricReporter) setIsRetrying(value bool) { + r.retryLock.Lock() + defer r.retryLock.Unlock() + r.isRetrying = value +} diff --git a/test/integration/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go b/test/integration/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go index bfb26365aa..0bedeedd8a 100644 --- a/test/integration/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go +++ b/test/integration/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go @@ -116,6 +116,8 @@ func (r *metricReporter) createClient() error { r.channel = channel r.eventsChannel = eventsChannel + r.isRetrying = false + return nil } @@ -165,12 +167,12 @@ func (r *metricReporter) Send(ctx context.Context, message Message) error { } if r.channel == nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Channel Send", errors.New("metric service stream client not created yet")) } if err := r.channel.Send(report); err != nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Channel Send", err) } @@ -191,7 +193,7 @@ func (r *metricReporter) Send(ctx context.Context, message Message) error { } if err := r.eventsChannel.Send(report); err != nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Events Channel Send", err) } @@ -259,3 +261,9 @@ func (r *metricReporter) handleGrpcError(messagePrefix string, err error) error return err } + +func (r *metricReporter) setIsRetrying(value bool) { + r.retryLock.Lock() + defer r.retryLock.Unlock() + r.isRetrying = value +} diff --git a/test/performance/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go b/test/performance/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go index bfb26365aa..0bedeedd8a 100644 --- a/test/performance/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go +++ b/test/performance/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go @@ -116,6 +116,8 @@ func (r *metricReporter) createClient() error { r.channel = channel r.eventsChannel = eventsChannel + r.isRetrying = false + return nil } @@ -165,12 +167,12 @@ func (r *metricReporter) Send(ctx context.Context, message Message) error { } if r.channel == nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Channel Send", errors.New("metric service stream client not created yet")) } if err := r.channel.Send(report); err != nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Channel Send", err) } @@ -191,7 +193,7 @@ func (r *metricReporter) Send(ctx context.Context, message Message) error { } if err := r.eventsChannel.Send(report); err != nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Events Channel Send", err) } @@ -259,3 +261,9 @@ func (r *metricReporter) handleGrpcError(messagePrefix string, err error) error return err } + +func (r *metricReporter) setIsRetrying(value bool) { + r.retryLock.Lock() + defer r.retryLock.Unlock() + r.isRetrying = value +} diff --git a/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go b/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go index bfb26365aa..0bedeedd8a 100644 --- a/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go +++ b/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go @@ -116,6 +116,8 @@ func (r *metricReporter) createClient() error { r.channel = channel r.eventsChannel = eventsChannel + r.isRetrying = false + return nil } @@ -165,12 +167,12 @@ func (r *metricReporter) Send(ctx context.Context, message Message) error { } if r.channel == nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Channel Send", errors.New("metric service stream client not created yet")) } if err := r.channel.Send(report); err != nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Channel Send", err) } @@ -191,7 +193,7 @@ func (r *metricReporter) Send(ctx context.Context, message Message) error { } if err := r.eventsChannel.Send(report); err != nil { - r.isRetrying = true + r.setIsRetrying(true) return r.handleGrpcError("Metric Reporter Events Channel Send", err) } @@ -259,3 +261,9 @@ func (r *metricReporter) handleGrpcError(messagePrefix string, err error) error return err } + +func (r *metricReporter) setIsRetrying(value bool) { + r.retryLock.Lock() + defer r.retryLock.Unlock() + r.isRetrying = value +}