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

allow BatchTimeout to be overriden on the libhoney Transmission #509

Merged
merged 2 commits into from
Sep 14, 2022
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
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