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

Use environment variables when error is strict #731

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lahiguera
Copy link

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

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
Copy link
Contributor

@asf-stripe asf-stripe left a comment

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 (:

@@ -135,7 +135,7 @@ func readConfig(r io.Reader) (Config, error) {
}
unmarshalErr := unmarshalSemiStrictly(bts, &c)
if unmarshalErr != nil {
if _, ok := err.(*UnknownConfigKeys); !ok {
if _, ok := unmarshalErr.(*UnknownConfigKeys); !ok {
Copy link
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!

@@ -37,6 +37,18 @@ func TestReadBadConfig(t *testing.T) {
assert.Equal(t, c, Config{}, "Parsing invalid config file should return zero struct")
}

func TestReadBadConfig_EnvVarsAreNotRead(t *testing.T) {
os.Setenv("VENEUR_HOSTNAME", "cux")
defer os.Unsetenv("VENEUR_HOSTNAME")
Copy link
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
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
Contributor

Handing this over to aditya! (:

@CLAassistant
Copy link

CLAassistant commented Aug 6, 2020

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