Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress reconnection logs #260

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (o *ovsdbClient) connect(ctx context.Context, reconnect bool) error {
if len(connectErrors) == 1 {
return connectErrors[0]
}
combined := []string{}
var combined []string
for _, e := range connectErrors {
combined = append(combined, e.Error())
}
Expand Down Expand Up @@ -1000,6 +1000,7 @@ func (o *ovsdbClient) handleDisconnectNotification() {
if o.options.reconnect && !o.shutdown {
o.rpcClient = nil
o.rpcMutex.Unlock()
suppressionCounter := 1
connect := func() error {
// need to ensure deferredUpdates is cleared on every reconnect attempt
for _, db := range o.databases {
Expand All @@ -1012,8 +1013,14 @@ func (o *ovsdbClient) handleDisconnectNotification() {
defer cancel()
err := o.connect(ctx, true)
if err != nil {
o.logger.V(2).Error(err, "failed to reconnect")
if suppressionCounter < 5 {
o.logger.V(2).Error(err, "failed to reconnect")
} else if suppressionCounter == 5 {
o.logger.V(2).Error(err, "reconnect has failed 5 times, suppressing logging "+
"for future attempts")
}
}
suppressionCounter++
return err
}
o.logger.V(3).Info("connection lost, reconnecting", "endpoint", o.activeEndpoint)
Expand Down
2 changes: 1 addition & 1 deletion client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func WithLeaderOnly(leaderOnly bool) Option {

// WithReconnect tells the client to automatically reconnect when
// disconnected. The timeout is used to construct the context on
// each call to Connect, while backoff dicates the backoff
// each call to Connect, while backoff dictates the backoff
// algorithm to use
func WithReconnect(timeout time.Duration, backoff backoff.BackOff) Option {
return func(o *options) error {
Expand Down