Skip to content

Commit

Permalink
allow BatchTimeout to be overriden on the libhoney Transmission (#509)
Browse files Browse the repository at this point in the history
This PR allows for the BatchTimeout to be configured for refinery rather than explicitly using DefaultBatchTimeout from libhoney
* allow BatchTimeout to be overridden on the libhoney Transmission
* add an example of modifying BatchTimeout in config_complete.toml
  • Loading branch information
leviwilson authored Sep 14, 2022
1 parent 6302d37 commit 8142980
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/refinery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func main() {
upstreamClient, err := libhoney.NewClient(libhoney.ClientConfig{
Transmission: &transmission.Honeycomb{
MaxBatchSize: c.GetMaxBatchSize(),
BatchTimeout: libhoney.DefaultBatchTimeout,
BatchTimeout: c.GetBatchTimeout(),
MaxConcurrentBatches: libhoney.DefaultMaxConcurrentBatches,
PendingWorkCapacity: uint(c.GetUpstreamBufferSize()),
UserAgentAddition: userAgentAddition,
Expand All @@ -156,7 +156,7 @@ func main() {
peerClient, err := libhoney.NewClient(libhoney.ClientConfig{
Transmission: &transmission.Honeycomb{
MaxBatchSize: c.GetMaxBatchSize(),
BatchTimeout: libhoney.DefaultBatchTimeout,
BatchTimeout: c.GetBatchTimeout(),
MaxConcurrentBatches: libhoney.DefaultMaxConcurrentBatches,
PendingWorkCapacity: uint(c.GetPeerBufferSize()),
UserAgentAddition: userAgentAddition,
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ type Config interface {
// complete before sending it, to allow stragglers to arrive
GetSendDelay() (time.Duration, error)

// GetBatchTimeout returns how often to send off batches in seconds
GetBatchTimeout() time.Duration

// GetTraceTimeout is how long to wait before sending a trace even if it's
// not complete. This should be longer than the longest expected trace
// duration.
Expand Down
9 changes: 9 additions & 0 deletions config/file_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type configContents struct {
Sampler string `validate:"required,oneof= DeterministicSampler DynamicSampler EMADynamicSampler RulesBasedSampler TotalThroughputSampler"`
Metrics string `validate:"required,oneof= prometheus honeycomb"`
SendDelay time.Duration `validate:"required"`
BatchTimeout time.Duration
TraceTimeout time.Duration `validate:"required"`
MaxBatchSize uint `validate:"required"`
SendTicker time.Duration `validate:"required"`
Expand Down Expand Up @@ -135,6 +136,7 @@ func NewConfig(config, rules string, errorCallback func(error)) (Config, error)
c.SetDefault("Collector", "InMemCollector")
c.SetDefault("Metrics", "honeycomb")
c.SetDefault("SendDelay", 2*time.Second)
c.SetDefault("BatchTimeout", libhoney.DefaultBatchTimeout)
c.SetDefault("TraceTimeout", 60*time.Second)
c.SetDefault("MaxBatchSize", 500)
c.SetDefault("SendTicker", 100*time.Millisecond)
Expand Down Expand Up @@ -710,6 +712,13 @@ func (f *fileConfig) GetSendDelay() (time.Duration, error) {
return f.conf.SendDelay, nil
}

func (f *fileConfig) GetBatchTimeout() time.Duration {
f.mux.RLock()
defer f.mux.RUnlock()

return f.conf.BatchTimeout
}

func (f *fileConfig) GetTraceTimeout() (time.Duration, error) {
f.mux.RLock()
defer f.mux.RUnlock()
Expand Down
8 changes: 8 additions & 0 deletions config/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type MockConfig struct {
GetPrometheusMetricsConfigVal PrometheusMetricsConfig
GetSendDelayErr error
GetSendDelayVal time.Duration
GetBatchTimeoutVal time.Duration
GetTraceTimeoutErr error
GetTraceTimeoutVal time.Duration
GetMaxBatchSizeVal uint
Expand Down Expand Up @@ -258,6 +259,13 @@ func (m *MockConfig) GetSendDelay() (time.Duration, error) {
return m.GetSendDelayVal, m.GetSendDelayErr
}

func (m *MockConfig) GetBatchTimeout() time.Duration {
m.Mux.RLock()
defer m.Mux.RUnlock()

return m.GetBatchTimeoutVal
}

func (m *MockConfig) GetTraceTimeout() (time.Duration, error) {
m.Mux.RLock()
defer m.Mux.RUnlock()
Expand Down
5 changes: 5 additions & 0 deletions config_complete.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ HoneycombAPI = "https://api.honeycomb.io"
# Eligible for live reload.
SendDelay = "2s"

# BatchTimeout dictates how frequently to send unfulfilled batches. By default
# this will use the DefaultBatchTimeout in libhoney as its value, which is 100ms.
# Eligible for live reload.
BatchTimeout = "1s"

# TraceTimeout is a long timer; it represents the outside boundary of how long
# to wait before sending an incomplete trace. Normally traces are sent when the
# root span arrives. Sometimes the root span never arrives (due to crashes or
Expand Down

0 comments on commit 8142980

Please sign in to comment.