-
Notifications
You must be signed in to change notification settings - Fork 375
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
[EXPERIMENTAL] Add env_var
and deprecated_env_var
configuration options
#2936
[EXPERIMENTAL] Add env_var
and deprecated_env_var
configuration options
#2936
Conversation
env_var
and deprecated_env_var
configuration options
c9f4ec8
to
56b8128
Compare
env_var 'DD_TRACE_ENABLED', type: :bool
env_var 'DD_TRACE_HEADER_STYLES', type: :array
# Alternatively...
env_var 'DD_TRACE_HEADER_STYLES', type: Array |
56b8128
to
7166995
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few notes :)
Overall I don't have very strong thoughts in terms of this option vs what we had before (e.g. I'm not convinced this one is better, but also not convinced it's worse, just different).
o.env_var 'DD_APPSEC_ENABLED' | ||
o.default DEFAULT_APPSEC_ENABLED | ||
o.setter do |value| | ||
val_to_bool(value) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll preface my comment by saying that I'm aware we're trading off between several upsides and downsides, so we may not be able to do everything for every use case.
That said, it seems to me a bit weird that we're generalizing the coercion we used to have only for environment variables (which are forced to be strings) and applying it to when users set things as code.
For instance in master (e.g. without this PR), we never forced any types. So you could do this (which doesn't make a lot of sense, hang on):
[2] pry(main)> Datadog.configuration.profiling.enabled
=> false
[3] pry(main)> Datadog.configure { |c| c.profiling.enabled = "????potato" }
# ...
[4] pry(main)> Datadog.configuration.profiling.enabled
=> "????potato"
With this PR, the "????potato" gets coerced:
[2] pry(main)> Datadog.configuration.profiling.enabled
=> false
[3] pry(main)> Datadog.configure { |c| c.profiling.enabled = "????potato" }
# ...
[4] pry(main)> Datadog.configuration.profiling.enabled
=> false
My claim is that neither of these makes a lot of sense, but that the new behavior seems to be "legitimizing" and erasing the bad input by coercing it into something that is what we expected.
Aka -- whereas in environment variables I think we're making the right choice for the conversion, it seems weird to me that we'd try to force anything that I pass in there into a string and then a boolean, rather than complaining back at the user "hey, you really sure you want to give me this random object as an input for this setting?"
TL;DR: I'm not sure that we should use the same coercion code (e.g. setter
) for values from environment variables vs something set as code.
Now, we have enough info in the DSL to realize when a value is coming in from an environment variable vs set by users, so we could make use of that to have separate code paths for them (maybe? just a suggestion).
o.default 30.0 | ||
o.setter do |value| | ||
val_to_float(value, 30.0) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: It seems a bit weird to repeat the default in the setter as well. Perhaps it should get it as an argument? (Or have a way to ask it?)
o.env_var Profiling::Ext::ENV_MAX_FRAMES | ||
o.setter do |value| | ||
val_to_int(value, 400) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Following the other changes, should the default here be set as well?
o.env_var Core::Environment::Ext::ENV_SERVICE | ||
o.default { Core::Environment::Ext::FALLBACK_SERVICE_NAME } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this default be updated to not use a block? (There's other defaults in this PR inside a block, maybe worth revisiting as well?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent of this PR is not to modify existing default blocks. Once we merge the PR that removes lazy
as a option, we can have a PR that goes over the defaults values that should not be a block.
@@ -51,14 +53,13 @@ def self.extended(base) | |||
# otherwise `['Datadog','b3multi','b3']`. | |||
# @return [Array<String>] | |||
option :propagation_extract_style do |o| | |||
o.default do | |||
o.deprecated_env_var Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_EXTRACT_OLD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have counted them wrong, but it seems to me we're adding deprecated_env_var
to support only 2 configuration settings -- this one and ENV_PROPAGATION_STYLE_INJECT_OLD
.
It seems a lot of work for only these two use-cases... Could we perhaps use custom logic on the setter
or somewhere else to avoid having the configuration system need to support this?
7166995
to
611ccb6
Compare
a851a80
to
4308a92
Compare
1b3e22a
to
fe3e77c
Compare
fe3e77c
to
7b5f9da
Compare
7b5f9da
to
d7d7684
Compare
cee2d00
to
7d699ac
Compare
ad94836
to
2b60d26
Compare
I noticed that calling `SafeDup.frozen_or_dup({a: :b})` on ruby 3.2 would break; because it tries to call `+(-){a: :b}` which doesn't work. I had to ensure the `SafeDup` module worked for all objects. I decided to extract that work into a separate PR to ease the work of reviewing. The method `frozen_or_dup` and `frozen_dup` for ruby 2.3 and forward only expect to receive String values. This could lead to future errors. By checking if the value is a String we can warranty the same behaviour for all kinds of objects Also, I added some extract refimients to be able to call `#dup` on `true, false, 1, 1.0` values.
ce13f2c
to
fcac996
Compare
6bc29ea
to
fba3922
Compare
Close in favour of #2970 |
What does this PR do?
I'm exploring trying to try solve some problems from a private discussion about how to track the configuration option using the ENV variable or the fallback.
The PR explores adding
env_var
anddeprecatated_env_var
as configuration options. Those options would be used to fetch the value from ENV. If the values are present, we treat them as being set programmatically by the customer. That way, we can later use theusing_default?
method to know if a configuration is using the default value or the one set by the customer.I had to refactor the functions
env_to_*
intoval_to_*
, since they no longer deal with ENV variables. The methods still live underCore::Environment::VariableHelpers
; that namespace is wrong.The intent of the PR is for people to see the approach and comment on anything they would change or miss.
If people like this addition, I will address all the missing and failing specs and any feedback from comments. Finish adding
o.default
to some settingsMotivation
Additional Notes
How to test the change?