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

ekump/upgrade to rubocop 1.50.0 #3147

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,4 @@ Style/WordArray:

# `!!` is the de facto way in Ruby to cast an Object to boolean.
Style/DoubleNegation:
Enabled: false
Enabled: false
4 changes: 4 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,7 @@ Style/FrozenStringLiteralComment:
Metrics/BlockNesting:
Exclude:
- 'lib/datadog/appsec/configuration/settings.rb'

Style/YodaCondition:
Exclude:
- 'spec/support/platform_helpers.rb'
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ else
end

if RUBY_VERSION >= '2.6.0'
gem 'rubocop', '~> 1.34.0', require: false
# 1.50 is the last version to support Ruby 2.6
gem 'rubocop', '~> 1.50.0', require: false
gem 'rubocop-packaging', '~> 0.5.2', require: false
gem 'rubocop-performance', '~> 1.9', require: false
gem 'rubocop-rspec', '~> 2.2', require: false
# 2.20 is the last version to support Ruby 2.6
gem 'rubocop-rspec', ['~> 2.20', '< 2.21'], require: false
end

# Optional extensions
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/core/configuration/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def options_hash
end

def reset_options!
options.values.each(&:reset)
options.each_value(&:reset)
end

private
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def initialize(*_)
# Datadog features are sending to the Agent or backend.
# @default `DD_TRACE_DEBUG` environment variable, otherwise `false`
# @return [Boolean]
# rubocop:disable Lint/RedundantRequireStatement
option :debug do |o|
o.env Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED
o.default false
Expand All @@ -109,6 +110,7 @@ def initialize(*_)
require 'pp' if enabled
end
end
# rubocop:enable Lint/RedundantRequireStatement

# Internal {Datadog::Statsd} metrics collection.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/profiling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def self.enabled?
end

private_class_method def self.replace_noop_allocation_count
def self.allocation_count # rubocop:disable Lint/DuplicateMethods, Lint/NestedMethodDefinition (On purpose!)
def self.allocation_count # rubocop:disable Lint/NestedMethodDefinition (On purpose!)
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_allocation_count
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/utils/quantization/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ def obfuscate_query(query, options = {})
(?:"|%22) # closing '"' at end of value
)
|(?: # other common secret values
bearer(?:\s|%20)+[a-z0-9._\-]+
bearer(?:\s|%20)+[a-z0-9._-]+
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The regex changes are just removing redundant escape characters

|token(?::|%3A)[a-z0-9]{13}
|gh[opsu]_[0-9a-zA-Z]{36}
|ey[I-L](?:[\w=-]|%3D)+\.ey[I-L](?:[\w=-]|%3D)+(?:\.(?:[\w.+/=-]|%3D|%2F|%2B)+)?
|-{5}BEGIN(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY-{5}[^\-]+-{5}END(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY(?:-{5})?(?:\n|%0A)?
|-{5}BEGIN(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY-{5}[^-]+-{5}END(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY(?:-{5})?(?:\n|%0A)?
|(?:ssh-(?:rsa|dss)|ecdsa-[a-z0-9]+-[a-z0-9]+)(?:\s|%20)*(?:[a-z0-9/.+]|%2F|%5C|%2B){100,}(?:=|%3D)*(?:(?:\s+)[a-z0-9._-]+)?
)
}ix.freeze
Expand Down
8 changes: 2 additions & 6 deletions spec/datadog/appsec/remote_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,7 @@
context 'unsupported key' do
let(:data) do
{
'unsupported' => {

}
'unsupported' => {}
}
end

Expand Down Expand Up @@ -452,9 +450,7 @@
context 'without rules_data information' do
let(:data) do
{
'other_key' => {

}
'other_key' => {}
}
end

Expand Down
3 changes: 1 addition & 2 deletions spec/datadog/profiling/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,8 @@ def stack_frame_to_function_id(backtrace_location)
is_expected.to have(4).items

# All but last are unique
(0..-2).each do |i|
3.times do |i|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ivoanjo wanted to bring this to your attention. (0..-2).each never executes.

Copy link
Member

Choose a reason for hiding this comment

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

Oh wow, thanks for spotting it! The good news is -- this test is only for the old profiler codepath, that is off by default and no customers should be using anymore.

The new profiler has similar specs, but in different files, and doesn't have this bug as far as I can spot it.

(The old profiler, along with this file are going to be deleted in Q4; I've mostly been finishing up a few other features before I come and remove all of this.)

stack_sample = stack_samples[i]

expect(sample[i].to_h).to eq(
location_id: stack_sample.frames.collect { |f| stack_frame_to_location_id(f) },
value: [stack_sample.cpu_time_interval_ns, stack_sample.wall_time_interval_ns],
Expand Down
4 changes: 1 addition & 3 deletions spec/datadog/tracing/contrib/aws/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,7 @@
end

let(:responses) do
{ create_topic: {

} }
{ create_topic: {} }
end

it_behaves_like 'schema version span'
Expand Down
12 changes: 6 additions & 6 deletions spec/datadog/tracing/contrib/rails/rails_active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def perform(test_retry: false, test_discard: false)
expect(span.name).to eq('active_job.enqueue')
expect(span.resource).to eq('ExampleJob')
expect(span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter')
expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/)
expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/)
expect(span.get_tag('active_job.job.queue')).to eq('mice')
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT))
.to eq('active_job')
Expand All @@ -97,7 +97,7 @@ def perform(test_retry: false, test_discard: false)
expect(span.name).to eq('active_job.enqueue')
expect(span.resource).to eq('ExampleJob')
expect(span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter')
expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/)
expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/)
expect(span.get_tag('active_job.job.queue')).to eq('mice')
expect(span.get_tag('active_job.job.scheduled_at').to_time).to be_within(1).of(scheduled_at)
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT))
Expand All @@ -117,7 +117,7 @@ def perform(test_retry: false, test_discard: false)
expect(span.name).to eq('active_job.perform')
expect(span.resource).to eq('ExampleJob')
expect(span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter')
expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/)
expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/)
expect(span.get_tag('active_job.job.queue')).to eq('elephants')
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT))
.to eq('active_job')
Expand All @@ -140,7 +140,7 @@ def perform(test_retry: false, test_discard: false)
expect(enqueue_retry_span.name).to eq('active_job.enqueue_retry')
expect(enqueue_retry_span.resource).to eq('ExampleJob')
expect(enqueue_retry_span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter')
expect(enqueue_retry_span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/)
expect(enqueue_retry_span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/)
expect(enqueue_retry_span.get_tag('active_job.job.queue')).to eq('elephants')
expect(enqueue_retry_span.get_tag('active_job.job.error')).to eq('JobRetryError')
expect(enqueue_retry_span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT))
Expand All @@ -159,7 +159,7 @@ def perform(test_retry: false, test_discard: false)
expect(retry_stopped_span.name).to eq('active_job.retry_stopped')
expect(retry_stopped_span.resource).to eq('ExampleJob')
expect(retry_stopped_span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter')
expect(retry_stopped_span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/)
expect(retry_stopped_span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/)
expect(retry_stopped_span.get_tag('active_job.job.queue')).to eq('elephants')
expect(retry_stopped_span.get_tag('active_job.job.error')).to eq('JobRetryError')
expect(retry_stopped_span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT))
Expand All @@ -183,7 +183,7 @@ def perform(test_retry: false, test_discard: false)
expect(span.name).to eq('active_job.discard')
expect(span.resource).to eq('ExampleJob')
expect(span.get_tag('active_job.adapter')).to eq('ActiveJob::QueueAdapters::InlineAdapter')
expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f\-]{32}/)
expect(span.get_tag('active_job.job.id')).to match(/[0-9a-f-]{32}/)
expect(span.get_tag('active_job.job.queue')).to eq('elephants')
expect(span.get_tag('active_job.job.error')).to eq('JobDiscardError')
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT))
Expand Down
8 changes: 5 additions & 3 deletions spec/support/platform_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'os'

module PlatformHelpers
Expand All @@ -6,15 +8,15 @@ module PlatformHelpers
# Ruby runtime engines

def mri?
RUBY_ENGINE == 'ruby'.freeze
RUBY_ENGINE == 'ruby'
end

def jruby?
RUBY_ENGINE == 'jruby'.freeze
RUBY_ENGINE == 'jruby'
end

def truffleruby?
RUBY_ENGINE == 'truffleruby'.freeze
RUBY_ENGINE == 'truffleruby'
end

def engine_version
Expand Down
Loading