Skip to content

Commit

Permalink
fix: add basic validation in otlphttpexporter
Browse files Browse the repository at this point in the history
  • Loading branch information
anupamdalmia10 committed Feb 14, 2022
1 parent 97ffae5 commit 19df779
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions exporter/otlphttpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package otlphttpexporter // import "go.opentelemetry.io/collector/exporter/otlphttpexporter"

import (
"fmt"

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand All @@ -41,5 +43,8 @@ var _ config.Exporter = (*Config)(nil)

// Validate checks if the exporter configuration is valid
func (cfg *Config) Validate() error {
if cfg.Endpoint == "" && cfg.TracesEndpoint == "" && cfg.MetricsEndpoint == "" && cfg.LogsEndpoint == "" {
return fmt.Errorf("at least one endpoint must be specified")
}
return nil
}
2 changes: 1 addition & 1 deletion exporter/otlphttpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestLoadConfig(t *testing.T) {
factories.Exporters[typeStr] = factory
cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories)

require.NoError(t, err)
require.Error(t, err)
require.NotNil(t, cfg)

e0 := cfg.Exporters[config.NewComponentID(typeStr)]
Expand Down

0 comments on commit 19df779

Please sign in to comment.