Skip to content

Commit

Permalink
Rate limit the warning logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorian Jaminais-Grellier committed Feb 24, 2023
1 parent 096b511 commit ea19e8b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion clientpool/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"fmt"
"sync/atomic"
"time"

"github.com/reddit/baseplate.go/log"
"golang.org/x/time/rate"
)

type channelPool struct {
Expand Down Expand Up @@ -36,6 +38,7 @@ func NewChannelPool(ctx context.Context, requiredInitialClients, bestEffortIniti

var lastAttemptErr error
pool := make(chan Client, maxClients)
chatty := rate.NewLimiter(rate.Every(2*time.Second), 1)

for i := 0; i < requiredInitialClients; {
if ctxErr := ctx.Err(); ctxErr != nil {
Expand All @@ -59,7 +62,9 @@ func NewChannelPool(ctx context.Context, requiredInitialClients, bestEffortIniti
i++
} else {
lastAttemptErr = err
log.Warnf("clientpool: error creating required client (will retry): %w", err)
if chatty.Allow() {
log.Warnf("clientpool: error creating required client (will retry): %w", err)
}
}
}
lastAttemptErr = nil
Expand Down

0 comments on commit ea19e8b

Please sign in to comment.