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] Profiling: Minor cleanup to error messages #3979

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Oct 7, 2024

What does this PR do?

This PR does a very small refactoring to the tests and code in the profiler to print errors when talking to the backend.

Motivation:

In Ruby 3.4, the printing of arrays is being slightly tweaked, and so our tests started failing.

Regardless of that change sticking or being reverted (it does seem like it could cause a bit of annoyance across the ecosystem), I've decided to simplify a bit our code to provide our own printing rather than rely on the Ruby defaults, and thus work everywhere.

Also I decided to remove the specs for
HttpTransport#config_without_api_key since it's only used internally for error printing (which did not use to be the case!).

Additional Notes:

There's a few more things not working on Ruby head due to changes in rubygems/bundler, but I'll handle those separately.

How to test the change?

This change includes test coverage.

In Ruby 3.4, the printing of arrays is being slightly tweaked, and
so our tests started failing.

Regardless of that change sticking or being reverted (it does seem
like it could cause a bit of annoyance across the ecosystem), I've
decided to simplify a bit our code to provide our own printing rather
than rely on the Ruby defaults, and thus work everywhere.

Also I decided to remove the specs for
`HttpTransport#config_without_api_key` since it's only used
internally for error printing (which did not use to be the case!).
@ivoanjo ivoanjo requested a review from a team as a code owner October 7, 2024 14:30
@ivoanjo ivoanjo added dev/refactor Involves refactoring existing components profiling Involves Datadog profiling dev/internal Other internal work that does not need to be included in the changelog labels Oct 7, 2024
@@ -139,7 +139,7 @@ def do_export(
end

def config_without_api_key
[exporter_configuration[0..1]].to_h
"#{exporter_configuration[0]}: #{exporter_configuration[1]}"
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
"#{exporter_configuration[0]}: #{exporter_configuration[1]}"
"#{exporter_configuration.first}: #{exporter_configuration[1]}"
Improve readability with first (...read more)

This rule encourages the use of first and last methods over array indexing to access the first and last elements of an array, respectively. The primary reason behind this rule is to improve code readability. Using first and last makes it immediately clear that you are accessing the first or last element of the array, which might not be immediately obvious with array indexing, especially for developers who are new to Ruby.

The use of these methods also helps to make your code more idiomatic, which is a crucial aspect of writing effective Ruby code. Idiomatic code is easier to read, understand, and maintain. It also tends to be more efficient, as idioms often reflect patterns that are optimized for the language.

To adhere to this rule, replace the use of array indexing with first or last methods when you want to access the first and last elements of an array. For instance, instead of arr[0] use arr.first and instead of arr[-1] use arr.last. However, note that this rule should be applied only when reading values. When modifying the first or last elements, array indexing should still be used. For example, arr[0] = 'new_value' and arr[-1] = 'new_value'.

View in Datadog  Leave us feedback  Documentation

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.87%. Comparing base (12b5808) to head (dcf347e).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3979   +/-   ##
=======================================
  Coverage   97.86%   97.87%           
=======================================
  Files        1313     1313           
  Lines       78369    78356   -13     
  Branches     3888     3888           
=======================================
- Hits        76695    76688    -7     
+ Misses       1674     1668    -6     

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

@pr-commenter
Copy link

pr-commenter bot commented Oct 7, 2024

Benchmarks

Benchmark execution time: 2024-10-07 15:11:38

Comparing candidate commit dcf347e in PR branch ivoanjo/fix-profiler-specs-ruby-head with baseline commit 12b5808 in branch master.

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

@ivoanjo ivoanjo merged commit 272a75c into master Oct 7, 2024
252 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/fix-profiler-specs-ruby-head branch October 7, 2024 15:46
@github-actions github-actions bot added this to the 2.4.0 milestone Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev/internal Other internal work that does not need to be included in the changelog dev/refactor Involves refactoring existing components profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants