Skip to content

Commit

Permalink
Introduce retry mechanism for SyslogEmitter with exponential backoff
Browse files Browse the repository at this point in the history
 - Add a constant for maximum retries
 - Wrap the SyslogEmitter writer with a RetryWriter to handle retries with exponential backoff
 - Update tests to expect a RetryWriter instead of a TLSWriter or TCPWriter
  • Loading branch information
bonzofenix committed Sep 3, 2024
1 parent b4a1816 commit d127490
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/autoscaler/metricsforwarder/forwarder/syslog_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/egress/syslog"
)

const maxRetries int = 22

type SyslogEmitter struct {
logger lager.Logger
writer egress.WriteCloser
Expand Down Expand Up @@ -78,8 +80,19 @@ func NewSyslogEmitter(logger lager.Logger, conf *config.Config) (MetricForwarder
)
}

retryWriter, err := syslog.NewRetryWriter(
binding,
syslog.ExponentialDuration,
maxRetries,
writer,
)

if err != nil {
return nil, err
}

return &SyslogEmitter{
writer: writer,
writer: retryWriter,
logger: logger,
}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var _ = Describe("SyslogEmitter", func() {
})

It("Writer should be TLS", func() {
Expect(emitter.(*forwarder.SyslogEmitter).GetWriter()).To(BeAssignableToTypeOf(&syslog.TLSWriter{}))
Expect(emitter.(*forwarder.SyslogEmitter).GetWriter()).To(BeAssignableToTypeOf(&syslog.RetryWriter{}))
})
})

Expand All @@ -122,7 +122,7 @@ var _ = Describe("SyslogEmitter", func() {
})

It("Writer should be TCP", func() {
Expect(emitter.(*forwarder.SyslogEmitter).GetWriter()).To(BeAssignableToTypeOf(&syslog.TCPWriter{}))
Expect(emitter.(*forwarder.SyslogEmitter).GetWriter()).To(BeAssignableToTypeOf(&syslog.RetryWriter{}))
})
})
})
Expand Down

0 comments on commit d127490

Please sign in to comment.