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

NH-69750: change trigger_tracing_mode to symbol #100

Merged
merged 14 commits into from
Jan 11, 2024
Merged

NH-69750: change trigger_tracing_mode to symbol #100

merged 14 commits into from
Jan 11, 2024

Conversation

xuan-cao-swi
Copy link
Contributor

Description

Change the trigger_tracing_mode from string to symbol (e.g. :enabled/:disabled)

@xuan-cao-swi xuan-cao-swi requested a review from a team as a code owner January 2, 2024 20:09
@xuan-cao-swi xuan-cao-swi requested a review from cheempz January 3, 2024 15:11
@@ -51,7 +51,7 @@
class TraceInfo
attr_reader :tracestring, :trace_id, :span_id, :trace_flags, :do_log

REGEXP = /^(?<tracestring>(?<version>[a-f0-9]{2})-(?<trace_id>[a-f0-9]{32})-(?<span_id>[a-f0-9]{16})-(?<flags>[a-f0-9]{2}))$/.freeze
REGEXP = /^(?<tracestring>(?<version>[a-f0-9]{2})-(?<trace_id>[a-f0-9]{32})-(?<span_id>[a-f0-9]{16})-(?<flags>[a-f0-9]{2}))$/.freeze # rubocop:disable Style/RedundantFreeze

Check warning

Code scanning / Rubocop

Checks for rubocop:disable comments that can be removed. Note: this cop is not disabled when disabling all cops. It must be explicitly disabled.

Lint/RedundantCopDisableDirective: Unnecessary disabling of `Style/RedundantFreeze`.
@@ -107,7 +107,7 @@
marginalia_job["class"] if marginalia_job.respond_to?(:[])
end

DEFAULT_LINES_TO_IGNORE_REGEX = %r{\.rvm|/ruby/gems/|vendor/|marginalia|rbenv|monitor\.rb.*mon_synchronize}.freeze
DEFAULT_LINES_TO_IGNORE_REGEX = %r{\.rvm|/ruby/gems/|vendor/|marginalia|rbenv|monitor\.rb.*mon_synchronize}.freeze # rubocop:disable Style/RedundantFreeze

Check warning

Code scanning / Rubocop

Checks for rubocop:disable comments that can be removed. Note: this cop is not disabled when disabling all cops. It must be explicitly disabled.

Lint/RedundantCopDisableDirective: Unnecessary disabling of `Style/RedundantFreeze`.
@xuan-cao-swi xuan-cao-swi requested a review from a team January 5, 2024 19:05
Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

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

Nice refactoring @xuan-cao-swi! Getting close, please see my comments.

@xuan-cao-swi xuan-cao-swi requested a review from cheempz January 10, 2024 22:07
Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

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

Thanks @xuan-cao-swi, the refactoring LGTM but diving more into tests is making me really wonder about our treatment of logging level (which is great that you added tests for, it's an important aspect of our library and we definitely want to get it right). Can you investigate?

_(SolarWindsAPM::Config[:dummy_key]).must_equal true
end

it 'with nil env, config env true, use default false, should be true' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, I think this test is only meaningful if the env var is set, i.e. ENV['DUMMY_KEY'] = 'false'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

it 'debug_level is in the range' do
SolarWindsAPM::Config[:debug_level] = 1
SolarWindsAPM::Config.set_log_level
_(SolarWindsAPM.logger.level).must_equal 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, why is the log level 3 if we're setting what looks to be a valid level of 1?
Also just noticed

SolarWindsAPM::Config[:debug_level] = 3 unless (-1..6).cover?(SolarWindsAPM::Config[:debug_level])
has valid levels -1 through 6, while our customer doc has 0 through 6--which is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think customer doc is correct.

ENV['SW_APM_DEBUG_LEVEL'] = '3'
SolarWindsAPM::Config[:debug_level] = 1
SolarWindsAPM::Config.set_log_level
_(SolarWindsAPM.logger.level).must_equal 1
Copy link
Contributor

Choose a reason for hiding this comment

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

The test says env var should override but the result looks the opposite, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When SW_APM_DEBUG_LEVEL = 3, the mapping will result the SolarWindsAPM.logger.level to 1.
If SolarWindsAPM::Config[:debug_level] = 1 (and empty SW_APM_DEBUG_LEVEL), then the mapping will result the SolarWindsAPM.logger.level to 3.

ENV['SW_APM_DEBUG_LEVEL'] = '7'
SolarWindsAPM::Config[:debug_level] = 1
SolarWindsAPM::Config.set_log_level
_(SolarWindsAPM.logger.level).must_equal 0
Copy link
Contributor

Choose a reason for hiding this comment

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

If the provided value is invalid, we can go two ways--but neither should result in a very mysterious setting of log level to 0.

  • First approach: stop at first source of config, i.e. env var. since its value is invalid, fallback to default.
  • Second approach: continue to evaluate other source of config, i.e. config file, and use its value if valid else fallback to default.

ENV.delete('SW_APM_DEBUG_LEVEL')
end

it 'env var override config but out of range by less than 0' do
Copy link
Contributor

Choose a reason for hiding this comment

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

I am honestly very confused and mystified by the range verification... you might be too based on the comment in line 217? Can this logic be cleaned up to actually make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, inherited set_log_level function is kind confusing. I will make it clear

end
end

describe 'general checking on []=' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Really appreciate this test suite--the checking of defaults on application startup, and typical customer overrides via env var.

Comment on lines 269 to 271
describe 'test transaction_settings' do
# test is in transaction_settings_test.rb
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't seem useful, consider removing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@xuan-cao-swi xuan-cao-swi requested a review from cheempz January 11, 2024 17:36
@cheempz
Copy link
Contributor

cheempz commented Jan 11, 2024

Thanks for the response @xuan-cao-swi, yes taking a closer look I realize now that the debug level configuration option is being used to internally set the Ruby Logger level. IMHO it would be clearer if the Ruby Logger constants like ERROR, WARN were used, and that the tests verified:

  • the customer-visible debug level configuration option
    • default value
    • env var > config file
    • invalid value handling
  • mapping of debug level configuration to Ruby Logger level

@@ -68,11 +74,37 @@ def self.config_from_env
end

def self.set_log_level
SolarWindsAPM::Config[:debug_level] = 3 unless (-1..6).cover?(SolarWindsAPM::Config[:debug_level])
log_level = (ENV['SW_APM_DEBUG_LEVEL'] || SolarWindsAPM::Config[:debug_level] || 3).to_i
SolarWindsAPM.logger.level = LOGGER_LEVEL_MAPPING[log_level] || 1 # default log level info
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question, can we use the Ruby Logger constant INFO insteadn of 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@xuan-cao-swi xuan-cao-swi requested a review from cheempz January 11, 2024 19:07
Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the revisits @xuan-cao-swi! Much better foundations for the config logic and will come in handy when we upgrade to the new liboboe that has debug log level changes!

@xuan-cao-swi xuan-cao-swi merged commit cbf3c31 into main Jan 11, 2024
@xuan-cao-swi xuan-cao-swi deleted the NH-69750 branch January 11, 2024 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants