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

Support spaces in environment variable lists #2011

Merged
merged 2 commits into from
May 12, 2022
Merged

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented May 11, 2022

Fixes #1953

This PR adds space-separated list support, in addition to the existing comma-separated list, to environment variable list options.

This brings us up to parity with other traces.

The only application option currently is DD_TAGS.

Initially, I implemented this change to all users of Datadog::Core::Environment::VariableHelpers#env_to_list, but the other use case, DD_PROPAGATION_STYLE_*, has a space in one of its supported values.

Datadog
B3
B3 single header

It wouldn't be possible to configure DD_PROPAGATION_STYLE_INJECT=B3 single header correctly, so I left DD_PROPAGATION_STYLE_* as comma-separated only in this PR.

@marcotc marcotc added the core Involves Datadog core libraries label May 11, 2022
@marcotc marcotc requested a review from a team May 11, 2022 01:27
@marcotc marcotc self-assigned this May 11, 2022
Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

❤️ Thanks A LOT for taking a stab at this. I've had this in my low-prio TODO list for a bunch of weeks now, and always bump it forward for later, so I humbly thank you for actually fixing this and making it better.

values = if value.include?(',') || comma_separated_only
value.split(',')
else
value.split # space splitting is the default
Copy link
Member

Choose a reason for hiding this comment

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

Minor: In the spirit of self-documenting code,

Suggested change
value.split # space splitting is the default
value.split(' ')

is faster to read than reading the comment ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Rubocop yelled at me for having the parameter that matches the default, so I removed it.
I'll add it back.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh Rubocop... That extremely opinionated colleague that we know nothing about :)

# either trailing or leading are trimmed.
#
# Empty entries, after trimmed, are also removed from the result.
def env_to_list(var, default = [], comma_separated_only: false)
Copy link
Member

Choose a reason for hiding this comment

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

Minor: Would it perhaps make sense to make this a required argument, to make callers explicitly think about if they need commas or spaces for separation?

Suggested change
def env_to_list(var, default = [], comma_separated_only: false)
def env_to_list(var, default = [], comma_separated_only:)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

Comment on lines +216 to +220
context '1,2 3' do
let(:env_value) { '1,2 3' }

it { is_expected.to eq(['1', '2 3']) }
end
Copy link
Member

@ivoanjo ivoanjo May 11, 2022

Choose a reason for hiding this comment

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

To be honest, I'm not sure how useful it is to support this, rather than just doing split by space and comma at the same time and be done with it. But it is true that the Python implementation also does some of these hijinks so...

(We're not actually matching the exact hijinks with spaces in python, e.g. (" key: val,key2:val2", {" key": " val", "key2": "val2"}, None),, but again, I'd just go for splitting on both at the same time and not supporting weird mixes).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm following Go's implementation, Java's implementation, and Python's original implementation document (internal doc):

  • Looking for commas, and using comma-separated if so.

I'm trying to match their implementations, to keep consistency, instead of doing what seems more right here.

@marcotc marcotc requested a review from ivoanjo May 11, 2022 20:38
@codecov-commenter
Copy link

Codecov Report

Merging #2011 (23af51b) into master (73ef77c) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2011      +/-   ##
==========================================
- Coverage   97.44%   97.44%   -0.01%     
==========================================
  Files        1016     1016              
  Lines       51474    51499      +25     
==========================================
+ Hits        50160    50184      +24     
- Misses       1314     1315       +1     
Impacted Files Coverage Δ
lib/datadog/core/configuration/settings.rb 100.00% <100.00%> (ø)
lib/datadog/core/environment/variable_helpers.rb 100.00% <100.00%> (ø)
.../datadog/core/environment/variable_helpers_spec.rb 100.00% <100.00%> (ø)
spec/datadog/profiling/ext/forking_spec.rb 99.39% <0.00%> (-0.61%) ⬇️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@marcotc marcotc merged commit cf3cbc5 into master May 12, 2022
@marcotc marcotc deleted the tags-with-spaces branch May 12, 2022 22:39
@github-actions github-actions bot added this to the 1.1.0 milestone May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing support for space-separated DD_TAGS
3 participants