Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Avoid global configuration overriding all #655

Merged
merged 1 commit into from
Mar 29, 2018

Conversation

rakyll
Copy link
Contributor

@rakyll rakyll commented Mar 28, 2018

It will be more common for the users to tweak a few
settings rather than all.

Rename SetConfig to ApplyConfig and only
override the non-zero values.

@rakyll
Copy link
Contributor Author

rakyll commented Mar 28, 2018

/cc @savaki

trace/config.go Outdated
// ApplyConfig applies changes to the global tracing configuration.
//
// Fields not provided in the given config is going to be preserved.
func ApplyConfig(cfg Config) {
if cfg.DefaultSampler == nil {
cfg.DefaultSampler = newDefaultSampler()
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you don't want to reinstall the default, you want to keep the previous value. Maybe worth having a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@semistrict
Copy link
Contributor

Nice!

trace/config.go Outdated
func SetConfig(cfg Config) {
// ApplyConfig applies changes to the global tracing configuration.
//
// Fields not provided in the given config is going to be preserved.
Copy link
Member

Choose a reason for hiding this comment

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

Minor typo:
s/is going to/are going to/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

func TestApplyZeroConfig(t *testing.T) {
cfg := config
ApplyConfig(Config{})
if got, want := reflect.ValueOf(config.DefaultSampler).Pointer(), reflect.ValueOf(cfg.DefaultSampler).Pointer(); got != want {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, what is this testing for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whether config.DefaultSampler and cfg.DefaultSampler pointing to the same pointer.

It will be more common for the users to tweak a few
settings rather than all.

Rename SetConfig to ApplyConfig and only
override the non-zero values.
@rakyll rakyll merged commit 7630269 into census-instrumentation:master Mar 29, 2018
@rakyll rakyll deleted the applyconf branch March 29, 2018 00:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants