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

[docs/rfc] RFC about environment variables #9854

Merged
merged 13 commits into from
Apr 30, 2024

Conversation

Copy link

codecov bot commented Mar 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.70%. Comparing base (65cdb18) to head (90db1c0).
Report is 37 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9854      +/-   ##
==========================================
- Coverage   91.95%   91.70%   -0.25%     
==========================================
  Files         357      358       +1     
  Lines       16501    16543      +42     
==========================================
- Hits        15173    15171       -2     
- Misses       1000     1045      +45     
+ Partials      328      327       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mx-psi mx-psi added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Mar 27, 2024
@mx-psi mx-psi marked this pull request as ready for review April 3, 2024 10:24
@mx-psi mx-psi requested a review from a team as a code owner April 3, 2024 10:24
@mx-psi mx-psi requested a review from Aneurysm9 April 3, 2024 10:24
Copy link
Member Author

@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.

Self-reviewing to start some threads about topics I want to discuss

docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
Comment on lines 199 to 200
When an invalid identifier is found, a warning log is emitted, and the
string is kept as-is.
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 am undecided about this, I feel like we should fail in some cases but I am not sure about which. open-telemetry/opentelemetry-specification/issues/3981 has some more discussion about this

Copy link
Member

Choose a reason for hiding this comment

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

I agree with aligning with the configuration spec and I hope that ends up being failing. I think failing fast is a clearer outcome for the user.

For users that mis-typed the env var name, keeping the string verbatim could mean an unintuitive error caused by the unwanted string. If we fail immediately we can log a clear error message that will be easier to troubleshoot.

If the user needs an illegal string like ${env:this-is-illegal} they can use the escape to make it exact: $${env:this-is-illegal}.

To summarize: using the env var syntax is a request to parse an env var - if the provided env var cannot be parsed we should fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

@TylerHelmuth The one edge case here is ${1} from open-telemetry/opentelemetry-collector-contrib/issues/9984. Should we fail in that case and force uses to use escaping syntax?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since that is what we currently do and it seems impossible to detect all kinds of syntaxes past or future that would overlap with this, I have changed this to an error on 3f05467

Copy link
Member

Choose a reason for hiding this comment

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

@mx-psi I feel like since ${1} corresponds with the regex it should be expanded. If users need the literal ${1} can they do $${1}?

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 feel like since ${1} corresponds with the regex it should be expanded

I think we are on the same page, but to be clear 1 is not a valid identifier per the 'desired behavior' section (valid identifiers need to start with underscore or ASCII alphabetic characters), so it should not be expanded, but rather raise an error.

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, then we are on the same page, I just got the outcome wrong. My opinion is the ${1} should fail and if users need that literal string they should escape: $${1}.

This prevents us from having any edge cases with our unwrap syntax while keeping all functionality available.

Copy link
Member

Choose a reason for hiding this comment

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

@mx-psi where in the spec do we need to raise this issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tyler and I discussed this offline but for the benefit of anybody else keeping track of this: this is being discussed on open-telemetry/opentelemetry-specification/pull/4002

docs/rfcs/env-vars.md Show resolved Hide resolved
| `0123` | string | 0123 | 83 | 0123 | 0123 |
| `0xdeadbeef` | string | 0xdeadbeef | 3735928559 | 0xdeadbeef | 0xdeadbeef |
| `"0123"` | string | "0123" | 0123 | 0123 | 0123 |
| `!!str 0123` | string | !!str 0123 | 0123 | 0123 | 0123 |
Copy link
Member Author

Choose a reason for hiding this comment

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

For 'Desired behavior, inline string field' here, the behavior of the File Configuration SDK would be to set !!str 0123. I think this is a rare edge case, but as written it would set 0123 since the AsString method would not return the original representation

Copy link
Contributor

Choose a reason for hiding this comment

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

For 'Desired behavior, inline string field' here, the behavior of the File Configuration SDK would be to set !!str 0123.

Can you link to where this is defined? I can't see where this is addressed this outside of declaring a suggested minimum version of the YAML spec.

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 the closest one would be the combo_string_key from https://opentelemetry.io/docs/specs/otel/configuration/file-configuration/#environment-variable-substitution

I take this to mean that the original value passed by the user on the environment variable should be preserved as is when you use expansion inline

Copy link
Member

Choose a reason for hiding this comment

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

I vote we stick with whatever the configuration sig is doing

docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
docs/rfcs/env-vars.md Show resolved Hide resolved
docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
mx-psi and others added 2 commits April 3, 2024 17:21
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
docs/rfcs/env-vars.md Show resolved Hide resolved
Comment on lines 199 to 200
When an invalid identifier is found, a warning log is emitted, and the
string is kept as-is.
Copy link
Member

Choose a reason for hiding this comment

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

I agree with aligning with the configuration spec and I hope that ends up being failing. I think failing fast is a clearer outcome for the user.

For users that mis-typed the env var name, keeping the string verbatim could mean an unintuitive error caused by the unwanted string. If we fail immediately we can log a clear error message that will be easier to troubleshoot.

If the user needs an illegal string like ${env:this-is-illegal} they can use the escape to make it exact: $${env:this-is-illegal}.

To summarize: using the env var syntax is a request to parse an env var - if the provided env var cannot be parsed we should fail.

Copy link
Member

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

LGTM

@mx-psi
Copy link
Member Author

mx-psi commented Apr 16, 2024

Remaining work


The naked syntax supported in BASH is not supported in the Collector.
Escaping is supported by using two dollar signs. Escaping is also
honored for unsupported identifiers like `${1}` (i.e. anything that
Copy link
Member

Choose a reason for hiding this comment

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

Based on our discussion in this thread this sentence should be updated to clarify that ${1} is no supported.

Comment on lines 199 to 200
When an invalid identifier is found, a warning log is emitted, and the
string is kept as-is.
Copy link
Member

Choose a reason for hiding this comment

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

@mx-psi where in the spec do we need to raise this issue?

docs/rfcs/env-vars.md Outdated Show resolved Hide resolved
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
@codeboten
Copy link
Contributor

Remaining work

* [ ]  Decide on [[docs/rfc] RFC about environment variables #9854 (comment)](https://github.com/open-telemetry/opentelemetry-collector/pull/9854#discussion_r1561181980) by raising this on the spec and seeing if we can align on that
  
  * Filed [[configuration] Fail on unsupported identifiers opentelemetry-specification#4002](https://github.com/open-telemetry/opentelemetry-specification/pull/4002)

* [ ]  Decide on [[docs/rfc] RFC about environment variables #9854 (comment)](https://github.com/open-telemetry/opentelemetry-collector/pull/9854#discussion_r1549449041). I am going to try and do a PoC of the confmap behavior to double check what makes more sense

@mx-psi it looks like the spec issue will merge within the next 2 days, is the second issue still blocking this work?

@mx-psi
Copy link
Member Author

mx-psi commented Apr 30, 2024

@codeboten I haven't written a fully working PoC yet. I am fine merging this without the PoC if everybody else is okay with it (it may mean minor changes while we work on implementing this)

@codeboten
Copy link
Contributor

Let's merge this and change it as needed, the spec change was merged 👍🏻

@codeboten codeboten merged commit fe582df into open-telemetry:main Apr 30, 2024
49 checks passed
andrzej-stencel pushed a commit to andrzej-stencel/opentelemetry-collector that referenced this pull request May 27, 2024
**Description:** Adds an RFC about how environment variable resolution
should work
**Link to tracking Issue:** Fixes open-telemetry#9515, relates to:
- open-telemetry#8215
- open-telemetry#8565
- open-telemetry#9162
- open-telemetry#9531 
- open-telemetry#9532

---------

Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
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
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[confmap] Decide on desired behavior for ${..} and ${env:..}
7 participants