diff --git a/exporter/exporterhelper/queued_retry_experimental.go b/exporter/exporterhelper/queued_retry_experimental.go index 1949f23b2b4..9663c833c58 100644 --- a/exporter/exporterhelper/queued_retry_experimental.go +++ b/exporter/exporterhelper/queued_retry_experimental.go @@ -62,6 +62,19 @@ func DefaultQueueSettings() QueueSettings { } } +// Validate checks if the QueueSettings configuration is valid +func (qCfg *QueueSettings) Validate() error { + if !qCfg.Enabled { + return nil + } + + if qCfg.QueueSize <= 0 { + return fmt.Errorf("queue size must be positive") + } + + return nil +} + var ( errNoStorageClient = errors.New("no storage client extension found") errMultipleStorageClients = errors.New("multiple storage extensions found") diff --git a/exporter/exporterhelper/queued_retry_inmemory.go b/exporter/exporterhelper/queued_retry_inmemory.go index b83c571ee6a..e7e7937ce2c 100644 --- a/exporter/exporterhelper/queued_retry_inmemory.go +++ b/exporter/exporterhelper/queued_retry_inmemory.go @@ -57,6 +57,19 @@ func DefaultQueueSettings() QueueSettings { } } +// Validate checks if the QueueSettings configuration is valid +func (qCfg *QueueSettings) Validate() error { + if !qCfg.Enabled { + return nil + } + + if qCfg.QueueSize <= 0 { + return fmt.Errorf("queue size must be positive") + } + + return nil +} + type queuedRetrySender struct { fullName string cfg QueueSettings diff --git a/exporter/exporterhelper/queued_retry_test.go b/exporter/exporterhelper/queued_retry_test.go index eb4e72e9365..1fcd7c9ac16 100644 --- a/exporter/exporterhelper/queued_retry_test.go +++ b/exporter/exporterhelper/queued_retry_test.go @@ -368,6 +368,18 @@ func TestNoCancellationContext(t *testing.T) { assert.True(t, d.IsZero()) } +func TestQueueSettings_Validate(t *testing.T) { + qCfg := DefaultQueueSettings() + assert.NoError(t, qCfg.Validate()) + + qCfg.QueueSize = 0 + assert.EqualError(t, qCfg.Validate(), "queue size must be positive") + + // Confirm Validate doesn't return error with invalid config when feature is disabled + qCfg.Enabled = false + assert.NoError(t, qCfg.Validate()) +} + type mockErrorRequest struct { baseRequest } diff --git a/exporter/otlpexporter/config.go b/exporter/otlpexporter/config.go index 4b561e66bbc..f336c57e4c3 100644 --- a/exporter/otlpexporter/config.go +++ b/exporter/otlpexporter/config.go @@ -15,6 +15,8 @@ package otlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexporter" import ( + "fmt" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/exporter/exporterhelper" @@ -34,5 +36,9 @@ var _ config.Exporter = (*Config)(nil) // Validate checks if the exporter configuration is valid func (cfg *Config) Validate() error { + if err := cfg.QueueSettings.Validate(); err != nil { + return fmt.Errorf("queue settings has invalid configuration: %w", err) + } + return nil }