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

[NO-TICKET] Apply more of standardrb autoformatter to profiler files #3844

Merged
merged 7 commits into from
Aug 14, 2024

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Aug 14, 2024

What does this PR do?

In #3801 we adopted standardrb for the profiler. At the time, I left a few cops disabled:

This is because fixing each of these cops will create a LOT of diff noise. Thus, I've explicitly not included them in this PR, and plan to fix them separately, in smaller PRs, so we can still sanely review the diff on this PR.

This is the first of those smaller PRs that can be reviewed sanely.

Motivation:

Fully adopt standardrb for profiling.

Additional Notes:

The autofix to remove begin/end creates a lot of diff noise. I recommend reviewing this PR without whitespace as it's easier to spot the change.

How to test the change?

This PR does not change any behaviors, so existing test coverage being green is the thing to aim for :)

@ivoanjo ivoanjo requested review from a team as code owners August 14, 2024 14:30
@github-actions github-actions bot added the profiling Involves Datadog profiling label Aug 14, 2024

flush_and_wait
interrupted = false
rescue Exception => e # rubocop:disable Lint/RescueException
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

Suggested change
rescue Exception => e # rubocop:disable Lint/RescueException
rescue StandardError => e # rubocop:disable Lint/RescueException
Do not rescue the Exception class (...read more)

The rule "Do not rescue the Exception class" is a crucial practice in Ruby programming for handling exceptions. The Exception class is the root of Ruby's exception hierarchy, so when you rescue Exception, you're potentially catching and handling severe system errors that Ruby itself is trying to bubble up. These could be fundamental issues like memory overflows and syntax errors, which could cause the program to behave unexpectedly or even crash.

Rescuing the Exception class can lead to major problems in debugging since it can hide the true nature of the error and its source. It makes it harder to pinpoint where and why the error occurred. This can lead to significant delays in identifying and resolving coding issues.

Instead of rescuing the Exception class, it is better to rescue more specific error classes or use StandardError which is the superclass for most error types. For instance, if you're expecting possible nil values, use rescue NoMethodError. This allows Ruby to handle severe system errors appropriately and ensures that you're only rescuing the errors you expect. This practice makes your code safer, more predictable, and easier to maintain and debug.

View in Datadog  Leave us feedback  Documentation

)
end
Datadog.logger.debug('IdleSamplingHelper thread stopping cleanly')
rescue Exception => e # rubocop:disable Lint/RescueException
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

Suggested change
rescue Exception => e # rubocop:disable Lint/RescueException
rescue StandardError => e # rubocop:disable Lint/RescueException
Do not rescue the Exception class (...read more)

The rule "Do not rescue the Exception class" is a crucial practice in Ruby programming for handling exceptions. The Exception class is the root of Ruby's exception hierarchy, so when you rescue Exception, you're potentially catching and handling severe system errors that Ruby itself is trying to bubble up. These could be fundamental issues like memory overflows and syntax errors, which could cause the program to behave unexpectedly or even crash.

Rescuing the Exception class can lead to major problems in debugging since it can hide the true nature of the error and its source. It makes it harder to pinpoint where and why the error occurred. This can lead to significant delays in identifying and resolving coding issues.

Instead of rescuing the Exception class, it is better to rescue more specific error classes or use StandardError which is the superclass for most error types. For instance, if you're expecting possible nil values, use rescue NoMethodError. This allows Ruby to handle severe system errors appropriately and ensures that you're only rescuing the errors you expect. This practice makes your code safer, more predictable, and easier to maintain and debug.

View in Datadog  Leave us feedback  Documentation

self.class._native_sampling_loop(self)

Datadog.logger.debug('CpuAndWallTimeWorker thread stopping cleanly')
rescue Exception => e # rubocop:disable Lint/RescueException
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

Suggested change
rescue Exception => e # rubocop:disable Lint/RescueException
rescue StandardError => e # rubocop:disable Lint/RescueException
Do not rescue the Exception class (...read more)

The rule "Do not rescue the Exception class" is a crucial practice in Ruby programming for handling exceptions. The Exception class is the root of Ruby's exception hierarchy, so when you rescue Exception, you're potentially catching and handling severe system errors that Ruby itself is trying to bubble up. These could be fundamental issues like memory overflows and syntax errors, which could cause the program to behave unexpectedly or even crash.

Rescuing the Exception class can lead to major problems in debugging since it can hide the true nature of the error and its source. It makes it harder to pinpoint where and why the error occurred. This can lead to significant delays in identifying and resolving coding issues.

Instead of rescuing the Exception class, it is better to rescue more specific error classes or use StandardError which is the superclass for most error types. For instance, if you're expecting possible nil values, use rescue NoMethodError. This allows Ruby to handle severe system errors appropriately and ensures that you're only rescuing the errors you expect. This practice makes your code safer, more predictable, and easier to maintain and debug.

View in Datadog  Leave us feedback  Documentation


flush_and_wait
interrupted = false
rescue Exception => e # rubocop:disable Lint/RescueException
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

Suggested change
rescue Exception => e # rubocop:disable Lint/RescueException
rescue StandardError => e # rubocop:disable Lint/RescueException
Do not rescue the Exception class (...read more)

The rule "Do not rescue the Exception class" is a crucial practice in Ruby programming for handling exceptions. The Exception class is the root of Ruby's exception hierarchy, so when you rescue Exception, you're potentially catching and handling severe system errors that Ruby itself is trying to bubble up. These could be fundamental issues like memory overflows and syntax errors, which could cause the program to behave unexpectedly or even crash.

Rescuing the Exception class can lead to major problems in debugging since it can hide the true nature of the error and its source. It makes it harder to pinpoint where and why the error occurred. This can lead to significant delays in identifying and resolving coding issues.

Instead of rescuing the Exception class, it is better to rescue more specific error classes or use StandardError which is the superclass for most error types. For instance, if you're expecting possible nil values, use rescue NoMethodError. This allows Ruby to handle severe system errors appropriately and ensures that you're only rescuing the errors you expect. This practice makes your code safer, more predictable, and easier to maintain and debug.

View in Datadog  Leave us feedback  Documentation

)
end
Datadog.logger.debug('IdleSamplingHelper thread stopping cleanly')
rescue Exception => e # rubocop:disable Lint/RescueException
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

Suggested change
rescue Exception => e # rubocop:disable Lint/RescueException
rescue StandardError => e # rubocop:disable Lint/RescueException
Do not rescue the Exception class (...read more)

The rule "Do not rescue the Exception class" is a crucial practice in Ruby programming for handling exceptions. The Exception class is the root of Ruby's exception hierarchy, so when you rescue Exception, you're potentially catching and handling severe system errors that Ruby itself is trying to bubble up. These could be fundamental issues like memory overflows and syntax errors, which could cause the program to behave unexpectedly or even crash.

Rescuing the Exception class can lead to major problems in debugging since it can hide the true nature of the error and its source. It makes it harder to pinpoint where and why the error occurred. This can lead to significant delays in identifying and resolving coding issues.

Instead of rescuing the Exception class, it is better to rescue more specific error classes or use StandardError which is the superclass for most error types. For instance, if you're expecting possible nil values, use rescue NoMethodError. This allows Ruby to handle severe system errors appropriately and ensures that you're only rescuing the errors you expect. This practice makes your code safer, more predictable, and easier to maintain and debug.

View in Datadog  Leave us feedback  Documentation

self.class._native_sampling_loop(self)

Datadog.logger.debug('CpuAndWallTimeWorker thread stopping cleanly')
rescue Exception => e # rubocop:disable Lint/RescueException
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

Suggested change
rescue Exception => e # rubocop:disable Lint/RescueException
rescue StandardError => e # rubocop:disable Lint/RescueException
Do not rescue the Exception class (...read more)

The rule "Do not rescue the Exception class" is a crucial practice in Ruby programming for handling exceptions. The Exception class is the root of Ruby's exception hierarchy, so when you rescue Exception, you're potentially catching and handling severe system errors that Ruby itself is trying to bubble up. These could be fundamental issues like memory overflows and syntax errors, which could cause the program to behave unexpectedly or even crash.

Rescuing the Exception class can lead to major problems in debugging since it can hide the true nature of the error and its source. It makes it harder to pinpoint where and why the error occurred. This can lead to significant delays in identifying and resolving coding issues.

Instead of rescuing the Exception class, it is better to rescue more specific error classes or use StandardError which is the superclass for most error types. For instance, if you're expecting possible nil values, use rescue NoMethodError. This allows Ruby to handle severe system errors appropriately and ensures that you're only rescuing the errors you expect. This practice makes your code safer, more predictable, and easier to maintain and debug.

View in Datadog  Leave us feedback  Documentation

Copy link
Contributor

@AlexJF AlexJF left a comment

Choose a reason for hiding this comment

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

LGTM! The quote changes in cpu_and_wall_time_worker_spec.rb look partially applied (there are still ' around) and unrelated to the non-ignored rules but since it already adheres to the style we plan to introduce in a subsequent PR I vote we let it be 😄

@pr-commenter
Copy link

pr-commenter bot commented Aug 14, 2024

Benchmarks

Benchmark execution time: 2024-08-14 15:01:29

Comparing candidate commit 52c3b5a in PR branch ivoanjo/profiler-standardrb-todos with baseline commit a589a98 in branch master.

Found 0 performance improvements and 2 performance regressions! Performance is the same for 21 metrics, 2 unstable metrics.

scenario:profiler - sample timeline=false

  • 🟥 throughput [-0.698op/s; -0.666op/s] or [-9.608%; -9.161%]

scenario:profiler - sample+serialize retain_every=10 heap_samples=false heap_size=false heap_sample_every=1 skip_end_gc=false

  • 🟥 throughput [-0.083op/s; -0.067op/s] or [-2.993%; -2.412%]

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 96.58537% with 7 lines in your changes missing coverage. Please review.

Project coverage is 97.83%. Comparing base (a589a98) to head (52c3b5a).

Files Patch % Lines
...tadog/profiling/collectors/idle_sampling_helper.rb 60.00% 2 Missing ⚠️
lib/datadog/profiling/tasks/setup.rb 75.00% 2 Missing ⚠️
...atadog/profiling/collectors/thread_context_spec.rb 96.36% 2 Missing ⚠️
lib/datadog/profiling/scheduler.rb 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3844      +/-   ##
==========================================
- Coverage   97.85%   97.83%   -0.02%     
==========================================
  Files        1264     1264              
  Lines       75737    75725      -12     
  Branches     3729     3729              
==========================================
- Hits        74110    74085      -25     
- Misses       1627     1640      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ivoanjo
Copy link
Member Author

ivoanjo commented Aug 14, 2024

LGTM! The quote changes in cpu_and_wall_time_worker_spec.rb look partially applied (there are still ' around) and unrelated to the non-ignored rules but since it already adheres to the style we plan to introduce in a subsequent PR I vote we let it be 😄

Yes: The autofix was only for quotes in symbols not strings, I'll open up the bigger "make all strings consistent" next :)

@ivoanjo ivoanjo merged commit 7c67ce3 into master Aug 14, 2024
186 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/profiler-standardrb-todos branch August 14, 2024 16:13
@github-actions github-actions bot added this to the 2.3.0 milestone Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants