Skip to content

fix: Allow overriding env variable names, restore CODER_TELEMETRY #4894

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

Closed
wants to merge 7 commits into from

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Nov 4, 2022

This change allows us to set a custom env for certain flags. Useful when it does not match the deployment config struct 1-to-1.

This also restores the CODER_TELEMETRY name (was changed to CODER_TELEMETRY_ENABLE for the last release or two).

NOTE: This PR is targets #4893 as it builds upon the change there.

The viper automatic env mapping and BindEnv were both creating mappings
like `vip.BindEnv("telemetry", "CODER_TELEMETRY")` which we don't want
since `DeploymentConfig.Telemetry` is a struct housing fields.

For some reason, this was causing `DeploymentConfig.Telemetry.URL` to
**not** be assigned its default value when `CODER_TELEMETRY=false` was
set as an environment variable.

Potentially we would want `"telemetry.enable"` to be mapped to
`"CODER_TELEMETRY"` for simplicity. But that behavior is not changed by
this commit.

Arguably, we could remove `vip.SetEnvPrefix` and `vip.SetEnvKeyReplacer`
as well since we're manually controlling all environment variable names
via `formatEnv`.
@mafredri mafredri force-pushed the mafredri/deployment-config-manual-env branch from 48d852b to 6408959 Compare November 4, 2022 11:04
@mafredri mafredri requested a review from a team as a code owner November 4, 2022 11:04
@mafredri mafredri requested review from presleyp and removed request for a team November 4, 2022 11:04
@deansheather deansheather requested a review from f0ssel November 4, 2022 14:06
Copy link
Contributor

@f0ssel f0ssel left a comment

Choose a reason for hiding this comment

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

I agree this code here would solve this problem, looks great.

What wasn't documented clearly was that we are OK with these breaking changes and planned on documenting them in some sort of release notes. I know @bpmct was aware of the changes, even if this one was missed in the initial pass we knew about it pretty quickly from dogfood breaking.

I'd prefer we just accept the one time breaking changes at this early stage in the product for a system that doesn't need to support exceptions.

@mafredri
Copy link
Member Author

mafredri commented Nov 4, 2022

I agree this code here would solve this problem, looks great.

What wasn't documented clearly was that we are OK with these breaking changes and planned on documenting them in some sort of release notes. I know @bpmct was aware of the changes, even if this one was missed in the initial pass we knew about it pretty quickly from dogfood breaking.

I'd prefer we just accept the one time breaking changes at this early stage in the product for a system that doesn't need to support exceptions.

Ah, I see. I do understand your wish to have no exceptions although I feel it will be a necessity down the line, as the product evolves. At some point we will almost certainly rename or restructure something in the config. At which point being able to override the name (just like with a flag) would be good. We could even turn Env into an array to support multiple or allowing for backwards compat.

A nice added bonus here is that the API will inform the frontend of the name used for the env var. This is something I think we’d want even if we didn’t support renaming envs?

@f0ssel
Copy link
Contributor

f0ssel commented Nov 4, 2022

Ah, I see. I do understand your wish to have no exceptions although I feel it will be a necessity down the line, as the product evolves. At some point we will almost certainly rename or restructure something in the config. At which point being able to override the name (just like with a flag) would be good. We could even turn Env into an array to support multiple or allowing for backwards compat.

A nice added bonus here is that the API will inform the frontend of the name used for the env var. This is something I think we’d want even if we didn’t support renaming envs?

Yup I totally agree we'll probably run into this case I'd just like to wait until then to do so. The conversion from config field to env var is deterministic so the frontend has the information to present to env var currently, even if we we don't explicitly send it back as a field.

Base automatically changed from mafredri/fix-viper-envs to main November 4, 2022 17:47
@mafredri
Copy link
Member Author

mafredri commented Nov 4, 2022

Yup I totally agree we'll probably run into this case I'd just like to wait until then to do so. The conversion from config field to env var is deterministic so the frontend has the information to present to env var currently, even if we we don't explicitly send it back as a field.

Alright, I'll close this down for now then 👍🏻

@mafredri mafredri closed this Nov 4, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 4, 2022
@github-actions github-actions bot deleted the mafredri/deployment-config-manual-env branch May 5, 2023 00:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants