-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add validatable
interface to all the component config
#2898
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2898 +/- ##
==========================================
+ Coverage 91.74% 91.76% +0.01%
==========================================
Files 286 306 +20
Lines 15086 15116 +30
==========================================
+ Hits 13841 13871 +30
Misses 851 851
Partials 394 394
Continue to review full report at Codecov.
|
b30c848
to
4a6a25e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are opportunities for moving existing code into the validation functions to test that the interface makes sense and tidy up the code. I checked just the exporters and found some examples that we can move and left them as inline comments. Not sure if we want to do all of this on this PR or not but I wanted to point it out so that we at least track it somehow.
var _ config.Exporter = (*Config)(nil) | ||
|
||
// Validate checks if the exporter configuration is valid | ||
func (cfg *Config) Validate() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could move
opentelemetry-collector/exporter/jaegerexporter/factory.go
Lines 60 to 66 in 4a6a25e
if expCfg.Endpoint == "" { | |
// TODO: Improve error message, see #215 | |
err := fmt.Errorf( | |
"%q config requires a non-empty \"endpoint\"", | |
expCfg.Name()) | |
return nil, err | |
} |
func (cfg *Config) Validate() error { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe checking if the logging level is valid here? We do something similar on the factory function:
opentelemetry-collector/exporter/loggingexporter/factory.go
Lines 89 to 92 in 4a6a25e
err := (&level).UnmarshalText([]byte(cfg.LogLevel)) | |
if err != nil { | |
return nil, err | |
} |
|
||
// Validate checks if the exporter configuration is valid | ||
func (cfg *Config) Validate() error { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move these here
opentelemetry-collector/exporter/opencensusexporter/opencensus.go
Lines 61 to 68 in c5ddd09
if cfg.Endpoint == "" { | |
return nil, errors.New("OpenCensus exporter cfg requires an Endpoint") | |
} | |
if cfg.NumWorkers <= 0 { | |
return nil, errors.New("OpenCensus exporter cfg requires at least one worker") | |
} | |
|
||
// Validate checks if the exporter configuration is valid | ||
func (cfg *Config) Validate() error { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for endpoint here
opentelemetry-collector/exporter/otlpexporter/otlp.go
Lines 50 to 52 in c5ddd09
if oCfg.Endpoint == "" { | |
return nil, errors.New("OTLP exporter config requires an Endpoint") | |
} |
|
||
// Validate checks if the exporter configuration is valid | ||
func (cfg *Config) Validate() error { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check endpoint here
opentelemetry-collector/exporter/otlphttpexporter/otlp.go
Lines 61 to 66 in c5ddd09
if oCfg.Endpoint != "" { | |
_, err := url.Parse(oCfg.Endpoint) | |
if err != nil { | |
return nil, errors.New("endpoint must be a valid URL") | |
} | |
} |
|
||
// Validate checks if the exporter configuration is valid | ||
func (cfg *Config) Validate() error { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check endpoint here
opentelemetry-collector/exporter/prometheusexporter/prometheus.go
Lines 47 to 50 in c5ddd09
addr := strings.TrimSpace(config.Endpoint) | |
if strings.TrimSpace(config.Endpoint) == "" { | |
return nil, errBlankPrometheusAddress | |
} |
|
||
// Validate checks if the exporter configuration is valid | ||
func (cfg *Config) Validate() error { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check endpoint here
opentelemetry-collector/exporter/zipkinexporter/factory.go
Lines 72 to 75 in c5ddd09
if zc.Endpoint == "" { | |
// TODO https://github.com/open-telemetry/opentelemetry-collector/issues/215 | |
return nil, errors.New("exporter config requires a non-empty 'endpoint'") | |
} |
Thanks for commenting. I will create a separate PR to move those common sense config validations into its |
…fig.Validate from core can get compiled (#3020) As we're adding `validatable` interface to `config.processor | extension | exporter` in core package. `Contrib` package is failed to be built due to the following errors. This PR is to fix the ambiguous Config.Validate errors. ``` exporter/awsemfexporter/factory.go:40:9: cannot use &Config literal (type *Config) as type config.Exporter in return argument: *Config does not implement config.Exporter (wrong type for Validate method) have Validate() want Validate() error extension/observer/k8sobserver/factory.go:64:15: Config.Validate is ambiguous ``` **Link to tracking Issue:** open-telemetry/opentelemetry-collector#2898
…fig.Validate from core can get compiled (open-telemetry#3020) As we're adding `validatable` interface to `config.processor | extension | exporter` in core package. `Contrib` package is failed to be built due to the following errors. This PR is to fix the ambiguous Config.Validate errors. ``` exporter/awsemfexporter/factory.go:40:9: cannot use &Config literal (type *Config) as type config.Exporter in return argument: *Config does not implement config.Exporter (wrong type for Validate method) have Validate() want Validate() error extension/observer/k8sobserver/factory.go:64:15: Config.Validate is ambiguous ``` **Link to tracking Issue:** open-telemetry/opentelemetry-collector#2898
Description:
Extend previous PR - #2856. Add
validatable
interface toconfig.processor | extension | exporter
. And add the config validation inconfig.Validate()
Next
Implement the empty
Validate()
func in componentConfig
. For at least the core component we want to release stable.Link to tracking Issue:
#2541