Skip to content

Commit

Permalink
Freakynoblegas/reject invalid queue size exporterhelper (#4799)
Browse files Browse the repository at this point in the history
* Added Validate method to QueueSettings struct

* Minor update to queue setting's error message

Co-authored-by: Pablo Baeyens <[email protected]>

Co-authored-by: Pablo Baeyens <[email protected]>
  • Loading branch information
FreakyNobleGas and mx-psi authored Feb 8, 2022
1 parent cf00b30 commit 48c402d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions exporter/exporterhelper/queued_retry_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
13 changes: 13 additions & 0 deletions exporter/exporterhelper/queued_retry_inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions exporter/exporterhelper/queued_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions exporter/otlpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

0 comments on commit 48c402d

Please sign in to comment.