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

[confmap] Unify behavior of ${env:ENV} and ${ENV} #10161

Open
mx-psi opened this issue May 15, 2024 · 5 comments
Open

[confmap] Unify behavior of ${env:ENV} and ${ENV} #10161

mx-psi opened this issue May 15, 2024 · 5 comments
Assignees
Labels
area:confmap priority:p2 Medium release:required-for-ga Must be resolved before GA release

Comments

@mx-psi
Copy link
Member

mx-psi commented May 15, 2024

As decided on #9854, we want to unify the behavior of ${env:ENV} and ${ENV}. Currently, each has a different behavior: the ${ENV} syntax does not do any YAML parsing, while the ${env:ENV} syntax does parse the contents as YAML. We want to unify both and make them have the same behavior, described in RFC #9854.

One approach for this is to have some 'default' confmap provider used by the ${..} syntax, and control what provider is used (a expandconverter provider or the env provider) through a feature gate.

cc @TylerHelmuth

@mx-psi mx-psi added release:required-for-ga Must be resolved before GA release priority:p2 Medium area:confmap labels May 15, 2024
@TylerHelmuth TylerHelmuth changed the title [confmap] Unify behavior of ${env:ENV} and ${ENV}` [confmap] Unify behavior of ${env:ENV} and ${ENV} May 15, 2024
@TylerHelmuth
Copy link
Member

TylerHelmuth commented May 16, 2024

@mx-psi I see a couple approaches.

  1. Allow envprovider to expand ${env:} and ${}. This is conceptually simple, but I think breaks some logic in resolver.expandValue that requires providers to have an schema so it can identify which provider to use.
  2. Allow resolver.expandValue to expand ${} as an env var when it doesn't contain a uri (basically do env var expansion here). This is doable, but would mean duplicating the yaml parsing logic and logging logic (which means adding a Logger to the ResolverSettings) from the envprovide.
  3. Leave expandconverter in place, but restrict it to only allowing ${} and add yaml parsing.
  4. Create the concept of a "default" provider that is used by the Resolver when no schema is set. This would be a new field on the ResolverSettings. For our collector instances we'd set the default to be the envprovider. The envprovider would need to be updated to not error when no schema is provided.

I've experimented with 2 and think it would be workable. It would take care of this issue and #8215 at once. It did feel a little messy but there are probably ways to share code between the 2 places.

I would also be ok with option 4, as it provides a lot of flexibility.

Option 3 is pretty simple as well.

@TylerHelmuth TylerHelmuth self-assigned this May 16, 2024
@evan-bradley
Copy link
Contributor

Option 4 feels the cleanest to me. I think we should do it without the awareness of any of the Providers by prepending the default schema to the URI when the URI is given to the Provider, like the Resolver currently does with files passed to config arguments. If we provide this option, we may also want to consider whether to make it configurable for the command line flags

@TylerHelmuth
Copy link
Member

I think we should do it without the awareness of any of the Providers by prepending the default schema to the URI when the URI is given to the Provider

Ya that would work. I don't love the idea of messing with the incoming values, but if we already have precedence I can be ok with it.

If we provide this option, we may also want to consider whether to make it configurable for the command line flags

I think this is an option, but not required for 1.0

@mx-psi
Copy link
Member Author

mx-psi commented May 17, 2024

Agreed that option 4 feels like the cleanest. If we go with (4), for now I don't think we need to make this configurable anywhere other than the Go API, but we can open the door to make this configurable in the future by end-users

@TylerHelmuth
Copy link
Member

If we go with (4), for now I don't think we need to make this configurable anywhere other than the Go API, but we can open the door to make this configurable in the future by end-users

Agreed. I'll start work on option 4. I try to do this and #7111 in one.

codeboten pushed a commit that referenced this issue May 29, 2024
#### Description
This PR adds support for expanding `${}` syntax when no schema is
provided by allowing Resolver to use a default provider.

In a followup PR I'll update otelcol with a feature gate that allow
switching between a default envProvider and the expandconverter.

#### Link to tracking issue
Related to
#10161
Related to
#7111

#### Testing
Added unit tests

#### Documentation
Added godoc strings

---------

Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:confmap priority:p2 Medium release:required-for-ga Must be resolved before GA release
Projects
Status: In Progress
Development

No branches or pull requests

3 participants