Skip to content

Commit

Permalink
Validate that remote write queue settings are not negative (#3213)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyll authored May 18, 2021
1 parent 709d8a8 commit 613df75
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions exporter/prometheusremotewriteexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package prometheusremotewriteexporter

import (
"fmt"

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -63,5 +65,11 @@ var _ config.Exporter = (*Config)(nil)

// Validate checks if the exporter configuration is valid
func (cfg *Config) Validate() error {
if cfg.RemoteWriteQueue.QueueSize < 0 {
return fmt.Errorf("remote write queue size can't be negative")
}
if cfg.RemoteWriteQueue.NumConsumers < 0 {
return fmt.Errorf("remote write consumer number can't be negative")
}
return nil
}
20 changes: 20 additions & 0 deletions exporter/prometheusremotewriteexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,23 @@ func Test_loadConfig(t *testing.T) {
ResourceToTelemetrySettings: exporterhelper.ResourceToTelemetrySettings{Enabled: true},
})
}

func TestNegativeQueueSize(t *testing.T) {
factories, err := componenttest.NopFactories()
assert.NoError(t, err)

factory := NewFactory()
factories.Exporters[typeStr] = factory
_, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "negative_queue_size.yaml"), factories)
assert.Error(t, err)
}

func TestNegativeNumConsumers(t *testing.T) {
factories, err := componenttest.NopFactories()
assert.NoError(t, err)

factory := NewFactory()
factories.Exporters[typeStr] = factory
_, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "negative_num_consumers.yaml"), factories)
assert.Error(t, err)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
receivers:
nop:

processors:
nop:

exporters:
prometheusremotewrite:
endpoint: "localhost:8888"
remote_write_queue:
queue_size: 5
num_consumers: -1

service:
pipelines:
metrics:
receivers: [nop]
processors: [nop]
exporters: [prometheusremotewrite]


Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
receivers:
nop:

processors:
nop:

exporters:
prometheusremotewrite:
endpoint: "localhost:8888"
remote_write_queue:
queue_size: -1
num_consumers: 10

service:
pipelines:
metrics:
receivers: [nop]
processors: [nop]
exporters: [prometheusremotewrite]


0 comments on commit 613df75

Please sign in to comment.