Skip to content

Commit

Permalink
Rename batching configuration (#5236)
Browse files Browse the repository at this point in the history
Match the BatchProcessor and name these decls "batch*."
  • Loading branch information
MrAlias committed Apr 19, 2024
1 parent ed2e2b0 commit 94eb27f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
24 changes: 12 additions & 12 deletions sdk/log/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type BatchProcessor struct {
// separate goroutine dedicated to the export. This asynchronous behavior
// allows the poll goroutine to maintain accurate interval polling.
//
// __BatchProcessor__ __Poll Goroutine__ __Export Goroutine__
// ___BatchProcessor____ __Poll Goroutine__ __Export Goroutine__
// || || || || || ||
// || ********** || || || || ********** ||
// || Records=>* OnEmit * || || | - ticker || || * export * ||
Expand Down Expand Up @@ -100,7 +100,7 @@ type BatchProcessor struct {
//
// All of the exporter's methods are called synchronously.
func NewBatchProcessor(exporter Exporter, opts ...BatchProcessorOption) *BatchProcessor {
cfg := newBatchingConfig(opts)
cfg := newBatchConfig(opts)
if exporter == nil {
// Do not panic on nil export.
exporter = defaultNoopExporter
Expand Down Expand Up @@ -330,15 +330,15 @@ func (q *queue) Flush() []Record {
return out
}

type batchingConfig struct {
type batchConfig struct {
maxQSize setting[int]
expInterval setting[time.Duration]
expTimeout setting[time.Duration]
expMaxBatchSize setting[int]
}

func newBatchingConfig(options []BatchProcessorOption) batchingConfig {
var c batchingConfig
func newBatchConfig(options []BatchProcessorOption) batchConfig {
var c batchConfig
for _, o := range options {
c = o.apply(c)
}
Expand Down Expand Up @@ -374,12 +374,12 @@ func newBatchingConfig(options []BatchProcessorOption) batchingConfig {

// BatchProcessorOption applies a configuration to a [BatchProcessor].
type BatchProcessorOption interface {
apply(batchingConfig) batchingConfig
apply(batchConfig) batchConfig
}

type batchingOptionFunc func(batchingConfig) batchingConfig
type batchOptionFunc func(batchConfig) batchConfig

func (fn batchingOptionFunc) apply(c batchingConfig) batchingConfig {
func (fn batchOptionFunc) apply(c batchConfig) batchConfig {
return fn(c)
}

Expand All @@ -393,7 +393,7 @@ func (fn batchingOptionFunc) apply(c batchingConfig) batchingConfig {
// passed, 2048 will be used.
// The default value is also used when the provided value is less than one.
func WithMaxQueueSize(size int) BatchProcessorOption {
return batchingOptionFunc(func(cfg batchingConfig) batchingConfig {
return batchOptionFunc(func(cfg batchConfig) batchConfig {
cfg.maxQSize = newSetting(size)
return cfg
})
Expand All @@ -408,7 +408,7 @@ func WithMaxQueueSize(size int) BatchProcessorOption {
// passed, 1s will be used.
// The default value is also used when the provided value is less than one.
func WithExportInterval(d time.Duration) BatchProcessorOption {
return batchingOptionFunc(func(cfg batchingConfig) batchingConfig {
return batchOptionFunc(func(cfg batchConfig) batchConfig {
cfg.expInterval = newSetting(d)
return cfg
})
Expand All @@ -423,7 +423,7 @@ func WithExportInterval(d time.Duration) BatchProcessorOption {
// passed, 30s will be used.
// The default value is also used when the provided value is less than one.
func WithExportTimeout(d time.Duration) BatchProcessorOption {
return batchingOptionFunc(func(cfg batchingConfig) batchingConfig {
return batchOptionFunc(func(cfg batchConfig) batchConfig {
cfg.expTimeout = newSetting(d)
return cfg
})
Expand All @@ -439,7 +439,7 @@ func WithExportTimeout(d time.Duration) BatchProcessorOption {
// passed, 512 will be used.
// The default value is also used when the provided value is less than one.
func WithExportMaxBatchSize(size int) BatchProcessorOption {
return batchingOptionFunc(func(cfg batchingConfig) batchingConfig {
return batchOptionFunc(func(cfg batchConfig) batchConfig {
cfg.expMaxBatchSize = newSetting(size)
return cfg
})
Expand Down
20 changes: 10 additions & 10 deletions sdk/log/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"go.opentelemetry.io/otel/log"
)

func TestNewBatchingConfig(t *testing.T) {
func TestNewBatchConfig(t *testing.T) {
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {
t.Log(err)
}))
Expand All @@ -27,11 +27,11 @@ func TestNewBatchingConfig(t *testing.T) {
name string
envars map[string]string
options []BatchProcessorOption
want batchingConfig
want batchConfig
}{
{
name: "Defaults",
want: batchingConfig{
want: batchConfig{
maxQSize: newSetting(dfltMaxQSize),
expInterval: newSetting(dfltExpInterval),
expTimeout: newSetting(dfltExpTimeout),
Expand All @@ -46,7 +46,7 @@ func TestNewBatchingConfig(t *testing.T) {
WithExportTimeout(time.Hour),
WithExportMaxBatchSize(2),
},
want: batchingConfig{
want: batchConfig{
maxQSize: newSetting(10),
expInterval: newSetting(time.Microsecond),
expTimeout: newSetting(time.Hour),
Expand All @@ -61,7 +61,7 @@ func TestNewBatchingConfig(t *testing.T) {
envarExpTimeout: strconv.Itoa(1000),
envarExpMaxBatchSize: strconv.Itoa(1),
},
want: batchingConfig{
want: batchConfig{
maxQSize: newSetting(10),
expInterval: newSetting(100 * time.Millisecond),
expTimeout: newSetting(1000 * time.Millisecond),
Expand All @@ -76,7 +76,7 @@ func TestNewBatchingConfig(t *testing.T) {
WithExportTimeout(-1 * time.Hour),
WithExportMaxBatchSize(-2),
},
want: batchingConfig{
want: batchConfig{
maxQSize: newSetting(dfltMaxQSize),
expInterval: newSetting(dfltExpInterval),
expTimeout: newSetting(dfltExpTimeout),
Expand All @@ -91,7 +91,7 @@ func TestNewBatchingConfig(t *testing.T) {
envarExpTimeout: "-1",
envarExpMaxBatchSize: "-1",
},
want: batchingConfig{
want: batchConfig{
maxQSize: newSetting(dfltMaxQSize),
expInterval: newSetting(dfltExpInterval),
expTimeout: newSetting(dfltExpTimeout),
Expand All @@ -113,7 +113,7 @@ func TestNewBatchingConfig(t *testing.T) {
WithExportTimeout(time.Hour),
WithExportMaxBatchSize(2),
},
want: batchingConfig{
want: batchConfig{
maxQSize: newSetting(3),
expInterval: newSetting(time.Microsecond),
expTimeout: newSetting(time.Hour),
Expand All @@ -126,7 +126,7 @@ func TestNewBatchingConfig(t *testing.T) {
WithMaxQueueSize(1),
WithExportMaxBatchSize(10),
},
want: batchingConfig{
want: batchConfig{
maxQSize: newSetting(1),
expInterval: newSetting(dfltExpInterval),
expTimeout: newSetting(dfltExpTimeout),
Expand All @@ -140,7 +140,7 @@ func TestNewBatchingConfig(t *testing.T) {
for key, value := range tc.envars {
t.Setenv(key, value)
}
assert.Equal(t, tc.want, newBatchingConfig(tc.options))
assert.Equal(t, tc.want, newBatchConfig(tc.options))
})
}
}
Expand Down

0 comments on commit 94eb27f

Please sign in to comment.