Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 26b8fa6

Browse files
authored
Log less when elastic is down (#1477)
This PR limits error logs when elastic is not available.
1 parent 5b118a9 commit 26b8fa6

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

cmd/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ require (
9090
golang.org/x/sync v0.11.0 // indirect
9191
golang.org/x/sys v0.30.0 // indirect
9292
golang.org/x/text v0.22.0 // indirect
93+
golang.org/x/time v0.12.0 // indirect
9394
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
9495
google.golang.org/grpc v1.66.2 // indirect
9596
google.golang.org/protobuf v1.36.1 // indirect

cmd/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
252252
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
253253
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
254254
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
255+
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
256+
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
255257
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
256258
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
257259
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=

platform/frontend_connectors/dispatcher.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/QuesmaOrg/quesma/platform/v2/core/diag"
2525
"github.com/QuesmaOrg/quesma/platform/v2/core/routes"
2626
"github.com/QuesmaOrg/quesma/platform/v2/core/tracing"
27+
"golang.org/x/time/rate"
2728
"io"
2829
"net/http"
2930
"strings"
@@ -85,6 +86,8 @@ type Dispatcher struct {
8586

8687
debugInfoCollector diag.DebugInfoCollector
8788
phoneHomeAgent diag.PhoneHomeClient
89+
90+
elasticSearchErrorRateLimiter *rate.Limiter
8891
}
8992

9093
func (r *Dispatcher) SetDependencies(deps quesma_api.Dependencies) {
@@ -98,9 +101,10 @@ func NewDispatcher(config *config.QuesmaConfiguration) *Dispatcher {
98101
requestProcessors = append(requestProcessors, quesma_api.NewTraceIdPreprocessor())
99102

100103
return &Dispatcher{
101-
Config: config,
102-
RequestPreprocessors: requestProcessors,
103-
HttpClient: client,
104+
Config: config,
105+
RequestPreprocessors: requestProcessors,
106+
HttpClient: client,
107+
elasticSearchErrorRateLimiter: rate.NewLimiter(rate.Every(20*time.Second), 5),
104108
}
105109
}
106110

@@ -495,8 +499,23 @@ func (r *Dispatcher) sendHttpRequest(ctx context.Context, address string, origin
495499

496500
resp, err := r.HttpClient.Do(req)
497501
if err != nil {
498-
logger.ErrorWithCtxAndReason(ctx, "No network connection").
499-
Msgf("Error sending request: %v", err)
502+
503+
var shouldLogError bool
504+
505+
// we're rate limiting errors that are related to network issues only
506+
if strings.Contains(err.Error(), "dial") {
507+
if r.elasticSearchErrorRateLimiter != nil && r.elasticSearchErrorRateLimiter.Allow() {
508+
shouldLogError = true
509+
}
510+
} else {
511+
shouldLogError = true
512+
}
513+
514+
if shouldLogError {
515+
logger.ErrorWithCtxAndReason(ctx, "No network connection").
516+
Msgf("Error sending request: %v", err)
517+
}
518+
500519
return nil, err
501520
}
502521

platform/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ require (
3838
github.com/ucarion/urlpath v0.0.0-20200424170820-7ccc79b76bbb
3939
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8
4040
golang.org/x/oauth2 v0.27.0
41+
golang.org/x/time v0.12.0
4142
vitess.io/vitess v0.21.2
4243
)
4344

platform/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
259259
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
260260
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
261261
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
262+
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
263+
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
262264
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
263265
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
264266
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=

0 commit comments

Comments
 (0)