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] Fix for unset env var setting non-string field. #10950

Merged

Conversation

TylerHelmuth
Copy link
Member

@TylerHelmuth TylerHelmuth commented Aug 22, 2024

Description

Still working on making a new test for this scenario, but all existing tests pass.

Link to tracking issue

Fixes #10949

Testing

Manual testing showed the bug resolved, but I'd still like to get an e2e test to check it.

@TylerHelmuth
Copy link
Member Author

This doesn't work, the reflected default value ends up being used instead of the config's default value. I think we'd need sampling_initial to be unset if the env var is not set in order to properly merge in the default value.

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.87%. Comparing base (17b39d1) to head (776fefa).
Report is 1 commits behind head on main.

Files Patch % Lines
confmap/confmap.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10950      +/-   ##
==========================================
- Coverage   91.88%   91.87%   -0.01%     
==========================================
  Files         411      411              
  Lines       19327    19330       +3     
==========================================
+ Hits        17759    17760       +1     
- Misses       1218     1219       +1     
- Partials      350      351       +1     

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

@TylerHelmuth
Copy link
Member Author

TylerHelmuth commented Aug 22, 2024

Maybe that is ok?

In the string situation the value would be getting set to "" which would also override any default string value. So

exporters:
  debug:
    verbosity: ${env:UNSET_VAR}

would be seen as

exporters:
  debug:
    verbosity: ""

Not

exporters:
  debug:
    verbosity: "basic"

We log a warning when an unset env var is detected.

@TylerHelmuth TylerHelmuth reopened this Aug 22, 2024
@TylerHelmuth
Copy link
Member Author

I've confirmed that prior to this regression the unset env var would result in the field being set with the type's default value, not the default value from CreateDefaultConfig. So this PR should be a return to that behavior.

Copy link
Member

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

LGTM, is there any way we can reproduce the panic in a unit test?

@mx-psi
Copy link
Member

mx-psi commented Aug 26, 2024

This test in confmap/internal/e2e/types_test.go panics in main but passes on this PR:

func TestIssue10949_UnsetVar(t *testing.T) {
	resolver := NewResolver(t, "types_expand.yaml")
	conf, err := resolver.Resolve(context.Background())
	require.NoError(t, err)

	var cfg TargetConfig[int]
	err = conf.Unmarshal(&cfg)
	require.NoError(t, err)
	require.Equal(t, 0, cfg.Field)
}

(edit: Also tested on 1c96225 (last commit before the panic happens) and confirmed that this the behavior we had before)

Could you add this/something like this as a test?

@TylerHelmuth TylerHelmuth marked this pull request as ready for review August 26, 2024 13:30
@TylerHelmuth TylerHelmuth requested review from a team and atoulme August 26, 2024 13:30
@TylerHelmuth
Copy link
Member Author

@mx-psi added, thank you!

@mx-psi mx-psi merged commit e375da4 into open-telemetry:main Aug 26, 2024
49 of 66 checks passed
@github-actions github-actions bot added this to the next release milestone Aug 26, 2024
@TylerHelmuth TylerHelmuth deleted the confmap-fix-non-string-nil-case branch August 26, 2024 15:03
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.

Collector panics on startup for non-nilable config options with unset environment variable
2 participants