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

Update core configuration to use env and type options #2988

Merged
merged 7 commits into from
Jul 26, 2023

Conversation

GustavoCaso
Copy link
Member

@GustavoCaso GustavoCaso commented Jul 21, 2023

What does this PR do?

This code has been extracted from #2970 to facilitate the review process.

This PR focus on updating our current settings options to use env and type new functionality #2983

The only addition outside of updating the settings is making sure the default value gets duplicated before setting it a118dbd

There has been a discussion rather than duplicating. We should make sure that it is frozen to avoid unwanted changes to the value. #2970 (comment)
That change would be done on a separate PR

Motivation

Additional Notes

How to test the change?

@github-actions github-actions bot added ci-app CI product for test suite instrumentation core Involves Datadog core libraries integrations Involves tracing integrations tracing labels Jul 21, 2023
@GustavoCaso GustavoCaso force-pushed the update-configurationto-use-env-and-type-options branch from 68b041f to 2ee5597 Compare July 21, 2023 14:34
@GustavoCaso GustavoCaso force-pushed the update-configurationto-use-env-and-type-options branch 4 times, most recently from 526ebfd to a118dbd Compare July 24, 2023 10:47
@GustavoCaso GustavoCaso marked this pull request as ready for review July 24, 2023 10:53
@GustavoCaso GustavoCaso requested a review from a team July 24, 2023 10:53
@GustavoCaso GustavoCaso marked this pull request as draft July 24, 2023 10:55
@GustavoCaso GustavoCaso marked this pull request as ready for review July 24, 2023 11:01
@GustavoCaso GustavoCaso force-pushed the update-configurationto-use-env-and-type-options branch from a118dbd to ce03d19 Compare July 24, 2023 11:05
@@ -35,10 +41,26 @@ class Settings < Contrib::Configuration::Settings
end

option :error_status_codes do |o|
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 haven't add the type to the error_status_code option, because in the tests the values used are Array and Range. I didn't wanted to change the backend logic for :array on this PR. So I will leave the decision to adding the type to the original author of this integration

@@ -35,10 +41,26 @@ class Settings < Contrib::Configuration::Settings
end

option :error_status_codes do |o|
Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -35,10 +41,26 @@ class Settings < Contrib::Configuration::Settings
end

option :error_status_codes do |o|
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. 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.

It's in mega good shape! I left a few small notes, and I think after looking into them/discussing them, this is good to go.

One additional note: when running the specs manually I'm seeing a bunch of

/lib/datadog/core/configuration/options.rb:27: warning: instance variable @settings_name not initialized

I think this happens for top-level groups (e.g. c.agent) that don't get to have a custom class. I think the fix is as simple as settings_name = defined?(@settings_name) && @settings_name, as we do in a few other places in the codebase.

lib/datadog/core/configuration/option.rb Outdated Show resolved Hide resolved
lib/datadog/core/diagnostics/environment_logger.rb Outdated Show resolved Hide resolved
option :error_handler, experimental_default_proc: Tracing::SpanOperation::Events::DEFAULT_ON_ERROR
option :error_handler do |o|
o.type :proc
o.experimental_default_proc(&Tracing::SpanOperation::Events::DEFAULT_ON_ERROR)
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR -- but are we're ready to make a decision on the experimental_default_proc?

E.g. do we want to keep it as-is for now (probably rename it), or do you still have plans to change/remove it?

Copy link
Member Author

Choose a reason for hiding this comment

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

For now, no plans to remove it. We should rename it to default_proc 😄

Copy link
Member

Choose a reason for hiding this comment

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

Ack! Created https://github.com/DataDog/ruby-guild/issues/29 to record it (Datadog-only link)

o.lazy
o.type :float
o.env Ext::ENV_ANALYTICS_SAMPLE_RATE
o.default 1.0
end

option :quantize, default: {}
Copy link
Member

Choose a reason for hiding this comment

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

@sarahchen6 Maybe worth adding a type here as a follow-up PR to Gustavo's?

spec/datadog/ci/configuration/settings_spec.rb Outdated Show resolved Hide resolved
spec/datadog/core/configuration/settings_spec.rb Outdated Show resolved Hide resolved
spec/datadog/tracing/configuration/settings_spec.rb Outdated Show resolved Hide resolved
lib/datadog/tracing/configuration/settings.rb Outdated Show resolved Hide resolved
Comment on lines 35 to 38
o.on_set do |value|
# Update ActionPack analytics too
Datadog.configuration.tracing[:action_pack][:analytics_enabled] = value
Datadog.configuration.tracing[:action_pack][:analytics_enabled] = value unless value.nil?
end
Copy link
Member

Choose a reason for hiding this comment

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

It's subtle, but since both this setting, as well as the action_pack setting allow nil, I think perhaps that unless value.nil? is perhaps not the best idea (because in a way, nil previously meant "disable everything" and now only means "disable only rails".

In practice in most cases it'll be equivalent, but my thinking is, why change it, if we can keep the exact same previous behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 00b1168

On a private Zoom call, we also discussed that rails and action_pack supporting nil for analytics_enabled is weird and that we should use a boolean value instead.

That change should be done on a separate PR

lib/datadog/core/configuration/settings.rb Outdated Show resolved Hide resolved
@GustavoCaso GustavoCaso force-pushed the update-configurationto-use-env-and-type-options branch from ce03d19 to 1e31049 Compare July 25, 2023 14:10
Comment on lines -405 to +416
Datadog.logger.warn { "#{Tracing::Configuration::Ext::ClientIp::ENV_DISABLED} environment variable is deprecated, found set to #{disabled}, use #{Tracing::Configuration::Ext::ClientIp::ENV_ENABLED}=#{!disabled}" }
Datadog::Core.log_deprecation do
"#{Tracing::Configuration::Ext::ClientIp::ENV_DISABLED} environment variable is deprecated, use #{Tracing::Configuration::Ext::ClientIp::ENV_ENABLED} instead."
end
Copy link
Member

Choose a reason for hiding this comment

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

👍

option :writer_options, default: ->(_i) { {} }
# @return [Hash]
option :writer_options do |o|
o.type :hash
Copy link
Member

Choose a reason for hiding this comment

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

This was changed to not nillable, but after inspecting our codebase, this change has no impact as the default {} is accepted everywhere nil would.

option :trace_flush do |o|
o.default { nil }
end
option :trace_flush
Copy link
Member

Choose a reason for hiding this comment

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

When nothing is configured like this, is the type nillable?

Copy link
Member

@ivoanjo ivoanjo Jul 26, 2023

Choose a reason for hiding this comment

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

When there's no type, the validation is disabled completely (https://github.com/DataDog/dd-trace-rb/blob/master/lib/datadog/core/configuration/option.rb#L237) so it's a bit different from nillable (because nillable is a modifier after you select a specific type)

Copy link
Member

@marcotc marcotc left a comment

Choose a reason for hiding this comment

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

Nothing really blocking this, awesome job!

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!

For future PRs, I'd suggest not force-pushing after the first review is posted, as it makes it hard to see what has changed between revisions.

I'm the "trust, but verify" kinda person so I always like to give a look to the overall diff to try to spot new accidental issues, and this makes it hard to know if the older commits have changed :)

lib/datadog/core/configuration/settings.rb Show resolved Hide resolved
@GustavoCaso GustavoCaso merged commit 242c247 into master Jul 26, 2023
162 checks passed
@GustavoCaso GustavoCaso deleted the update-configurationto-use-env-and-type-options branch July 26, 2023 13:14
@github-actions github-actions bot added this to the 1.13.0 milestone Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-app CI product for test suite instrumentation core Involves Datadog core libraries integrations Involves tracing integrations tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants