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 a NewConfigProvider that uses options for settings, and does input validation #4936

Merged
merged 4 commits into from
Apr 11, 2022

Conversation

bogdandrutu
Copy link
Member

@bogdandrutu bogdandrutu commented Mar 1, 2022

This is a fork of #4762

Also, deprecates service.MustNewConfigProvider and service.MustNewDefaultConfigProviderin favor of service.NewConfigProvider.

Signed-off-by: Bogdan Drutu [email protected]

@bogdandrutu bogdandrutu requested review from a team and mx-psi March 1, 2022 23:28
@codecov
Copy link

codecov bot commented Mar 1, 2022

Codecov Report

Merging #4936 (9601c47) into main (95b976f) will decrease coverage by 0.04%.
The diff coverage is 87.93%.

@@            Coverage Diff             @@
##             main    #4936      +/-   ##
==========================================
- Coverage   90.33%   90.29%   -0.05%     
==========================================
  Files         185      185              
  Lines       11000    11041      +41     
==========================================
+ Hits         9937     9969      +32     
- Misses        837      844       +7     
- Partials      226      228       +2     
Impacted Files Coverage Δ
service/config_provider.go 90.22% <85.10%> (-4.12%) ⬇️
service/command.go 80.76% <100.00%> (-1.59%) ⬇️
model/internal/generated_log.go 96.71% <0.00%> (+0.06%) ⬆️

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 95b976f...9601c47. Read the comment docs.

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 like this NewConfigProvider more than the current one. I left some comments

service/collector.go Outdated Show resolved Hide resolved
service/config_provider.go Outdated Show resolved Hide resolved
service/config_provider.go Outdated Show resolved Hide resolved
service/config_provider_test.go Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Mar 18, 2022
@bogdandrutu bogdandrutu force-pushed the GH-4730-0.45 branch 3 times, most recently from d5ff8df to 9761e5a Compare March 21, 2022 09:11
@bogdandrutu bogdandrutu removed the Stale label Mar 21, 2022
CHANGELOG.md Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2022

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Apr 5, 2022
@bogdandrutu bogdandrutu removed the Stale label Apr 5, 2022
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 5, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation: This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.

Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 5, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation: This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.

Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 5, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation: This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.

Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 5, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation: This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.

Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 5, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation: This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.

Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 5, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation:

* This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.
* During the review of another PR, this was mentioned as something some approvers/maintainers were concerned about what to do with this package. See open-telemetry#4608 (review)
Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 5, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation:

* This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.
* During the review of another PR, this was mentioned as something some approvers/maintainers were concerned about what to do with this package. See open-telemetry#4608 (review)
Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my suggestions. Just one comment in the discussion w/ @Aneurysm9 & @mx-psi. It would be good to agree on the way to move forward.

service/config_provider.go Outdated Show resolved Hide resolved
Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

LGTM, the only contention point seems to be about calling WithConfigMapConverters multiple times. Once that is sorted out, either by returning an error on the second call or by using a settings object instead of options, this would be ready to be merged.

service/config_provider.go Outdated Show resolved Hide resolved
service/config_provider.go Show resolved Hide resolved
@bogdandrutu bogdandrutu force-pushed the GH-4730-0.45 branch 3 times, most recently from 6b71755 to ea7c2b4 Compare April 8, 2022 16:49
),
}))
cfgSet := NewDefaultConfigProviderSettings()
cfgSet.Locations = []string{
Copy link
Member

Choose a reason for hiding this comment

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

I didn't know this before, but I prefer this so much more than the previous iteration.

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Overall I like this a lot. Just a question and a couple of nits

service/config_provider.go Show resolved Hide resolved
service/config_provider.go Outdated Show resolved Hide resolved
Unmarshaler configunmarshaler.ConfigUnmarshaler
}

func newDefaultConfigProviderSettings() ConfigProviderSettings {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm probably missing this somewhere, but as a user is there a way for me to obtain the defaults from outside this package? I'm thinking of the case where someone may only want to override the locations but not the default providers/converters

Copy link
Member Author

Choose a reason for hiding this comment

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

I think, if we go with the same model as the Factories for components, we should not have any "defaults" every distribution will pick their "defaults" that they commit to support. All the components that we use in the "default" config are also public, so a distro can emulate the same if this is what they want.

@bogdandrutu bogdandrutu force-pushed the GH-4730-0.45 branch 2 times, most recently from 422a3d2 to 46ce4bf Compare April 8, 2022 23:20
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.

Using a struct resolves the ambiguity of repeating an option, I only have two nits but otherwise LGTM

service/config_provider.go Outdated Show resolved Hide resolved
Comment on lines +34 to +44
var err error
cfgSet := newDefaultConfigProviderSettings()
cfgSet.Locations = getConfigFlag()
// Append the "overwrite properties converter" as the first converter.
cfgSet.MapConverters = append(
[]config.MapConverterFunc{overwritepropertiesmapconverter.New(getSetFlag())},
cfgSet.MapConverters...)
set.ConfigProvider, err = NewConfigProvider(cfgSet)
if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

This and the collector_windows code are the same, should we extract it to a function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do in a separate PR.

@bogdandrutu bogdandrutu merged commit cd5df21 into open-telemetry:main Apr 11, 2022
@bogdandrutu bogdandrutu deleted the GH-4730-0.45 branch April 11, 2022 16:05
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 11, 2022
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 11, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation:

* This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.
* During the review of another PR, this was mentioned as something some approvers/maintainers were concerned about what to do with this package. See open-telemetry#4608 (review)
Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
bogdandrutu added a commit that referenced this pull request Apr 11, 2022
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 14, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation:

* This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.
* During the review of another PR, this was mentioned as something some approvers/maintainers were concerned about what to do with this package. See open-telemetry#4608 (review)
Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Apr 14, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation:

* This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.
* During the review of another PR, this was mentioned as something some approvers/maintainers were concerned about what to do with this package. See open-telemetry#4608 (review)
Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
bogdandrutu added a commit that referenced this pull request Apr 15, 2022
Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of #4936 do not offer ability to configure ConfigUnmarshaler.

Motivation:

* This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.
* During the review of another PR, this was mentioned as something some approvers/maintainers were concerned about what to do with this package. See #4608 (review)
Updates #4605

Signed-off-by: Bogdan Drutu <[email protected]>
Nicholaswang pushed a commit to Nicholaswang/opentelemetry-collector that referenced this pull request Jun 7, 2022
…t validation (open-telemetry#4936)

* Change deprecated NewConfigProvider to use options and do input validation

Signed-off-by: Bogdan Drutu <[email protected]>

* Revert deprecation of WithConfigUnmarshaler

Signed-off-by: Bogdan Drutu <[email protected]>

* Change to use settings for the ConfigProvider

Signed-off-by: Bogdan Drutu <[email protected]>

* Update service/config_provider.go

Co-authored-by: Alex Boten <[email protected]>
Nicholaswang pushed a commit to Nicholaswang/opentelemetry-collector that referenced this pull request Jun 7, 2022
Nicholaswang pushed a commit to Nicholaswang/opentelemetry-collector that referenced this pull request Jun 7, 2022
…try#5151)

Folllowup:

* When the deprecated funcs/types are removed the internal package can be moved to service/internal.
* Part of open-telemetry#4936 do not offer ability to configure ConfigUnmarshaler.

Motivation:

* This package is removed because with the latest addition of the `service.ConfigProvider` the usecase to change the unmarshaled config.Config can be achieved by wrapping/implementing that interface, so no clear use-case for this. In the future we can expose it again if we have good reasons.
* During the review of another PR, this was mentioned as something some approvers/maintainers were concerned about what to do with this package. See open-telemetry#4608 (review)
Updates open-telemetry#4605

Signed-off-by: Bogdan Drutu <[email protected]>
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.

5 participants