Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Use environment variables when error is strict - #731

Open
lahiguera wants to merge 5 commits into
stripe:masterfrom
lahiguera:read_config_environment_variables
Open

Use environment variables when error is strict#731
lahiguera wants to merge 5 commits into
stripe:masterfrom
lahiguera:read_config_environment_variables

Conversation

@lahiguera

Copy link
Copy Markdown

Summary

Fix minor bug in readConfig function when checking the error of
unmarshalSemiStrictly.

Motivation

This will allow us to use a configuration that has an unmarshalling
strict error, i.e. when the configuration have unknown fields, and
the validate-config and validate-config-strict command-line
flags are both false.

Test plan

Automated testing.

Rollout/monitoring/revert plan

None

** Summary **

Fix minor bug in readConfig function when cheking the error of
unmarshalSemiStrictly.

** Motivation **

This will allow us to use a configuration that has an unmarshalling
strict error, i.e. when the configuration have unknown fields, and
the validate-config and validate-config-strict command-line flags
are both false.

** Test plan **

Automated testing.

** Rollout/monitoring/revert plan **

None
@lahiguera
lahiguera force-pushed the read_config_environment_variables branch from 623023e to ede34b6 Compare July 1, 2019 16:14
@stripe-ci

Copy link
Copy Markdown

Gerald Rule: Copy Observability on Veneur, Unilog, Falconer pull requests

cc @stripe/observability
@stripe/observability-stripe

@lahiguera
lahiguera requested a review from asf-stripe January 23, 2020 18:18

@asf-stripe asf-stripe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this looks good (and good catch on the error variable mismatch!) but I'm a little worried about the env vars. Cc @aditya-stripe/@ChimeraCoder to make sure I'm worrying over nothing (:

Comment thread config_parse.go
unmarshalErr := unmarshalSemiStrictly(bts, &c)
if unmarshalErr != nil {
if _, ok := err.(*UnknownConfigKeys); !ok {
if _, ok := unmarshalErr.(*UnknownConfigKeys); !ok {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oufff, that's a good catch!

Comment thread config_test.go

func TestReadBadConfig_EnvVarsAreNotRead(t *testing.T) {
os.Setenv("VENEUR_HOSTNAME", "cux")
defer os.Unsetenv("VENEUR_HOSTNAME")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hm, I'm mildly worried about setting and unsetting environment variables in tests that could run parallel with other things (even though you don't use t.Parallel() here) - couldn't find envconfig testing recommendations either, but I guess it's probably fine as long as we never parallelize.

Cc @aditya-stripe for a second opinion

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for reviewing this!

Environment variables are in effect global variables, and these IMO should be accessed only from the most exterior layer of the app, and then passed as arguments to more interior layers. Having a package with "constants" might be helpful if we don't want to "pollute" the signatures of the functions. In Go I know this cannot be enforced at compile time since consts are only for values known at compile time, but an alternative would be having functions instead that return the desired environment variables values. It's just an idea :)

@lahiguera
lahiguera requested a review from asf-stripe March 13, 2020 16:56
@asf-stripe
asf-stripe requested review from aditya-stripe and removed request for asf-stripe March 17, 2020 16:26
@asf-stripe

Copy link
Copy Markdown
Contributor

Handing this over to aditya! (:

@CLAassistant

CLAassistant commented Aug 6, 2020

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@lahiguera
lahiguera requested a review from asf-stripe September 7, 2020 14:19
@asf-stripe
asf-stripe removed their request for review November 9, 2020 17:29
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.

5 participants