Skip to content
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

Merged
merged 1 commit into from
Apr 12, 2021

Conversation

mxiamxia
Copy link
Member

@mxiamxia mxiamxia commented Apr 7, 2021

Description:
Extend previous PR - #2856. Add validatable interface to config.processor | extension | exporter. And add the config validation in config.Validate()

Next
Implement the empty Validate() func in component Config. For at least the core component we want to release stable.

Link to tracking Issue:
#2541

@mxiamxia mxiamxia requested a review from a team April 7, 2021 05:37
@codecov
Copy link

codecov bot commented Apr 7, 2021

Codecov Report

Merging #2898 (b8d0446) into main (c5ddd09) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
config/config.go 100.00% <100.00%> (ø)
config/exporter.go 100.00% <100.00%> (ø)
config/extension.go 100.00% <100.00%> (ø)
config/processor.go 100.00% <100.00%> (ø)
exporter/fileexporter/config.go 100.00% <100.00%> (ø)
exporter/jaegerexporter/config.go 100.00% <100.00%> (ø)
exporter/kafkaexporter/config.go 100.00% <100.00%> (ø)
exporter/loggingexporter/config.go 100.00% <100.00%> (ø)
exporter/opencensusexporter/config.go 100.00% <100.00%> (ø)
exporter/otlpexporter/config.go 100.00% <100.00%> (ø)
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5ddd09...b8d0446. Read the comment docs.

@mxiamxia mxiamxia force-pushed the comp-validate branch 4 times, most recently from b30c848 to 4a6a25e Compare April 7, 2021 06:19
Copy link
Member

@mx-psi mx-psi left a 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move

if expCfg.Endpoint == "" {
// TODO: Improve error message, see #215
err := fmt.Errorf(
"%q config requires a non-empty \"endpoint\"",
expCfg.Name())
return nil, err
}
into the validation function.

Comment on lines +38 to +40
func (cfg *Config) Validate() error {
return nil
}
Copy link
Member

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:

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these here

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for endpoint here

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check endpoint here

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check endpoint here

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check endpoint here

if zc.Endpoint == "" {
// TODO https://github.com/open-telemetry/opentelemetry-collector/issues/215
return nil, errors.New("exporter config requires a non-empty 'endpoint'")
}

@mxiamxia
Copy link
Member Author

mxiamxia commented Apr 8, 2021

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.

Thanks for commenting. I will create a separate PR to move those common sense config validations into its Validate() func.

tigrannajaryan pushed a commit to open-telemetry/opentelemetry-collector-contrib that referenced this pull request Apr 8, 2021
…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
@bogdandrutu bogdandrutu merged commit 1ca65c8 into open-telemetry:main Apr 12, 2021
pmatyjasek-sumo pushed a commit to pmatyjasek-sumo/opentelemetry-collector-contrib that referenced this pull request Apr 28, 2021
…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
hughesjj pushed a commit to hughesjj/opentelemetry-collector that referenced this pull request Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants