From 467f3c580b6d035b12019d9d6f55dbe60fcd0e5a Mon Sep 17 00:00:00 2001 From: Arseniy Klempner Date: Tue, 15 Oct 2024 17:34:57 -0700 Subject: [PATCH] fix: add option to log when appending error --- lib/common/errors.go | 4 ++-- telemetry/server.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/common/errors.go b/lib/common/errors.go index 0c12df9..10d86f8 100644 --- a/lib/common/errors.go +++ b/lib/common/errors.go @@ -23,8 +23,8 @@ func NewMetricErrors(logger *zap.Logger) *MetricErrors { } } -func (me *MetricErrors) Append(id int, err string) { - if me.logger != nil { +func (me *MetricErrors) Append(id int, err string, skipLogging ...bool) { + if me.logger != nil && (len(skipLogging) == 0 || !skipLogging[0]) { me.logger.Error(err) } me.mutex.Lock() diff --git a/telemetry/server.go b/telemetry/server.go index 4e4109e..f9f462a 100644 --- a/telemetry/server.go +++ b/telemetry/server.go @@ -243,7 +243,7 @@ func (s *Server) createWakuTelemetry(w http.ResponseWriter, r *http.Request) { } if err := pushFilter.Put(s.DB); err != nil { if strings.Contains(err.Error(), "duplicate key value violates unique constraint") { - errorDetails.Append(data.Id, "Error saving lightpush/filter metric: Duplicate key value violates unique constraint") + errorDetails.Append(data.Id, "Error saving lightpush/filter metric: Duplicate key value violates unique constraint", true) continue } errorDetails.Append(data.Id, fmt.Sprintf("Error saving lightpush/filter metric: %v", err))