Skip to content

Commit 25c8b88

Browse files
p-datadogvpellan
authored andcommitted
Enable standard for most of the remaining files in the codebase (#4936)
1 parent bb74fd7 commit 25c8b88

21 files changed

+185
-184
lines changed

.rubocop.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ AllCops:
2323
- "vendor/bundle/**/*"
2424
- "spec/datadog/tracing/contrib/grpc/support/gen/**/*.rb" # Skip protoc autogenerated code
2525
- spec/**/*
26+
- Rakefile
27+
- "*.gemspec"
28+
- benchmarks/**/*
29+
- lib-injection/**/*
30+
- ext/**/*
31+
- yard/**/*
32+
- Gemfile
2633
NewCops: disable # Don't allow new cops to be enabled implicitly.
2734
SuggestExtensions: false # Stop pushing suggestions constantly.
2835

.standard_todo.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@ ignore:
1717
# character. To avoid being too directive, I would let comments go loose.
1818
- Layout/LeadingCommentSpace
1919

20-
# This disables standardrb for the rest of dd-trace-rb
21-
# except those products: profiling, appsec.
22-
- datadog.gemspec
23-
- Rakefile
20+
# This disables standardrb for third-party and generated code.
2421
- appraisal/**/**
25-
- benchmarks/**/**
2622
- gemfiles/**/**
2723
- integration/**/**
28-
- lib-injection/**/**
2924
- lib/datadog/**/vendor/**/*

Rakefile

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ namespace :test do
4040

4141
candidates.each_key do |group|
4242
env = if group.empty?
43-
{}
44-
else
45-
gemfile = AppraisalConversion.to_bundle_gemfile(group)
46-
{ 'BUNDLE_GEMFILE' => gemfile }
47-
end
43+
{}
44+
else
45+
gemfile = AppraisalConversion.to_bundle_gemfile(group)
46+
{'BUNDLE_GEMFILE' => gemfile}
47+
end
4848
command = "bundle check || bundle install && bundle exec rake #{spec_task}"
4949
command += "'[#{spec_arguments}]'" if spec_arguments
5050

@@ -67,15 +67,15 @@ desc 'Run RSpec'
6767
namespace :spec do
6868
# REMINDER: If adding a new task here, make sure also add it to the `Matrixfile`
6969
task all: [:main, :benchmark, :custom_cop,
70-
:graphql, :graphql_unified_trace_patcher, :graphql_trace_patcher, :graphql_tracing_patcher,
71-
:rails, :railsredis, :railsredis_activesupport, :railsactivejob,
72-
:elasticsearch, :http, :redis, :sidekiq, :sinatra, :hanami, :hanami_autoinstrument,
73-
:profiling, :crashtracking, :error_tracking, :process_discovery, :stable_config]
70+
:graphql, :graphql_unified_trace_patcher, :graphql_trace_patcher, :graphql_tracing_patcher,
71+
:rails, :railsredis, :railsredis_activesupport, :railsactivejob,
72+
:elasticsearch, :http, :redis, :sidekiq, :sinatra, :hanami, :hanami_autoinstrument,
73+
:profiling, :crashtracking, :error_tracking, :process_discovery, :stable_config]
7474

7575
desc '' # "Explicitly hiding from `rake -T`"
7676
RSpec::Core::RakeTask.new(:main) do |t, args|
7777
t.pattern = 'spec/**/*_spec.rb'
78-
t.exclude_pattern = 'spec/**/{appsec/integration,contrib,benchmark,redis,auto_instrument,opentelemetry,profiling,crashtracking,error_tracking,rubocop}/**/*_spec.rb,'\
78+
t.exclude_pattern = 'spec/**/{appsec/integration,contrib,benchmark,redis,auto_instrument,opentelemetry,profiling,crashtracking,error_tracking,rubocop}/**/*_spec.rb,' \
7979
' spec/**/{auto_instrument,opentelemetry,process_discovery,stable_config}_spec.rb, spec/datadog/gem_packaging_spec.rb'
8080
t.rspec_opts = args.to_a.join(' ')
8181
end
@@ -120,7 +120,7 @@ namespace :spec do
120120
desc '' # "Explicitly hiding from `rake -T`"
121121
RSpec::Core::RakeTask.new(:rails) do |t, args|
122122
t.pattern = 'spec/datadog/tracing/contrib/rails/**/*_spec.rb'
123-
t.exclude_pattern = 'spec/datadog/tracing/contrib/rails/**/*{active_job,disable_env,redis_cache,auto_instrument,'\
123+
t.exclude_pattern = 'spec/datadog/tracing/contrib/rails/**/*{active_job,disable_env,redis_cache,auto_instrument,' \
124124
'semantic_logger}*_spec.rb'
125125
t.rspec_opts = args.to_a.join(' ')
126126
end
@@ -325,7 +325,7 @@ namespace :spec do
325325
desc '' # "Explicitly hiding from `rake -T`"
326326
RSpec::Core::RakeTask.new(:main) do |t, args|
327327
t.pattern = 'spec/datadog/appsec/**/*_spec.rb'
328-
t.exclude_pattern = 'spec/datadog/appsec/**/{integration,contrib,auto_instrument}/**/*_spec.rb,'\
328+
t.exclude_pattern = 'spec/datadog/appsec/**/{integration,contrib,auto_instrument}/**/*_spec.rb,' \
329329
' spec/datadog/appsec/**/{auto_instrument,autoload}_spec.rb'
330330
t.rspec_opts = args.to_a.join(' ')
331331
end
@@ -357,7 +357,7 @@ namespace :spec do
357357
end
358358
end
359359

360-
task appsec: [:'appsec:all']
360+
task appsec: [:"appsec:all"]
361361

362362
namespace :di do
363363
# Datadog DI integrations
@@ -424,7 +424,7 @@ namespace :spec do
424424
Rake::Task[:all].prerequisite_tasks.each { |t| t.enhance([:compile_native_extensions]) }
425425
end
426426

427-
task profiling: [:'profiling:all']
427+
task profiling: [:"profiling:all"]
428428
end
429429

430430
if defined?(RuboCop::RakeTask)
@@ -441,11 +441,11 @@ namespace :coverage do
441441
task :report do
442442
require 'simplecov'
443443

444-
resultset_files = Dir["#{ENV.fetch('COVERAGE_DIR', 'coverage')}/.resultset.json"] +
445-
Dir["#{ENV.fetch('COVERAGE_DIR', 'coverage')}/versions/**/.resultset.json"]
444+
resultset_files = Dir["#{ENV.fetch("COVERAGE_DIR", "coverage")}/.resultset.json"] +
445+
Dir["#{ENV.fetch("COVERAGE_DIR", "coverage")}/versions/**/.resultset.json"]
446446

447447
SimpleCov.collate resultset_files do
448-
coverage_dir "#{ENV.fetch('COVERAGE_DIR', 'coverage')}/report"
448+
coverage_dir "#{ENV.fetch("COVERAGE_DIR", "coverage")}/report"
449449
formatter SimpleCov::Formatter::HTMLFormatter
450450
end
451451
end
@@ -455,11 +455,11 @@ namespace :coverage do
455455
require 'simplecov'
456456
require_relative 'spec/support/simplecov_fix'
457457

458-
versions = Dir["#{ENV.fetch('COVERAGE_DIR', 'coverage')}/versions/*"].map { |f| File.basename(f) }
458+
versions = Dir["#{ENV.fetch("COVERAGE_DIR", "coverage")}/versions/*"].map { |f| File.basename(f) }
459459
versions.map do |version|
460460
puts "Generating report for: #{version}"
461-
SimpleCov.collate Dir["#{ENV.fetch('COVERAGE_DIR', 'coverage')}/versions/#{version}/**/.resultset.json"] do
462-
coverage_dir "#{ENV.fetch('COVERAGE_DIR', 'coverage')}/report/versions/#{version}"
461+
SimpleCov.collate Dir["#{ENV.fetch("COVERAGE_DIR", "coverage")}/versions/#{version}/**/.resultset.json"] do
462+
coverage_dir "#{ENV.fetch("COVERAGE_DIR", "coverage")}/report/versions/#{version}"
463463
formatter SimpleCov::Formatter::HTMLFormatter
464464
end
465465
end

benchmarks/benchmarks_ips_patch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module JobReporter
44
def report(name, *args, **opts, &block)
5-
caller_path = caller_locations.first.path
5+
caller_path = caller_locations(1..1).first.path
66
prefix = File.basename(caller_path).sub(/_.*\z/, '')
77
name = "#{prefix} - #{name}"
88
# Older Rubies (e.g. 2.5) do not permit passing *args and &block

benchmarks/di_instrument.rb

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
1-
=begin
2-
3-
"Instrumentation" part of Dynamic Instrumentation benchmarks.
4-
5-
Typical result:
6-
7-
Comparison:
8-
no instrumentation: 589490.0 i/s
9-
method instrumentation - cleared: 545807.2 i/s - 1.08x slower
10-
line instrumentation - cleared: 539686.5 i/s - 1.09x slower
11-
no instrumentation - again: 535761.0 i/s - 1.10x slower
12-
method instrumentation: 129159.5 i/s - 4.56x slower
13-
line instrumentation - targeted: 128848.6 i/s - 4.58x slower
14-
line instrumentation: 10771.7 i/s - 54.73x slower
15-
16-
Targeted line and method instrumentations have similar performance at
17-
about 25% of baseline. Note that the instrumented method is fairly
18-
small and probably runs very quickly by itself, so while this is not the
19-
worst possible case for instrumentation (that would be an empty method),
20-
likely the vast majority of real world uses of DI would have way expensive
21-
target code and the relative overhead of instrumentation will be significantly
22-
lower than it is in this benchmark.
23-
24-
Untargeted line instrumentation is extremely slow, too slow to be usable.
25-
26-
In theory, after instrumentation is removed, performance should return to
27-
the baseline. We are currently observing about a 6-10% performance loss.
28-
Two theories for why this is so:
29-
1. Some overhead remains in the code - to be investigated.
30-
2. The benchmarks were run on a laptop, and during the benchmarking
31-
process the CPU is heating up and it can't turbo to the same speeds at
32-
the end of the run as it can at the beginning. Meaning the observed 6-10%
33-
slowdown at the end is an environmental issue and not an implementation
34-
problem.
35-
36-
=end
1+
#
2+
# "Instrumentation" part of Dynamic Instrumentation benchmarks.
3+
#
4+
# Typical result:
5+
#
6+
# Comparison:
7+
# no instrumentation: 589490.0 i/s
8+
# method instrumentation - cleared: 545807.2 i/s - 1.08x slower
9+
# line instrumentation - cleared: 539686.5 i/s - 1.09x slower
10+
# no instrumentation - again: 535761.0 i/s - 1.10x slower
11+
# method instrumentation: 129159.5 i/s - 4.56x slower
12+
# line instrumentation - targeted: 128848.6 i/s - 4.58x slower
13+
# line instrumentation: 10771.7 i/s - 54.73x slower
14+
#
15+
# Targeted line and method instrumentations have similar performance at
16+
# about 25% of baseline. Note that the instrumented method is fairly
17+
# small and probably runs very quickly by itself, so while this is not the
18+
# worst possible case for instrumentation (that would be an empty method),
19+
# likely the vast majority of real world uses of DI would have way expensive
20+
# target code and the relative overhead of instrumentation will be significantly
21+
# lower than it is in this benchmark.
22+
#
23+
# Untargeted line instrumentation is extremely slow, too slow to be usable.
24+
#
25+
# In theory, after instrumentation is removed, performance should return to
26+
# the baseline. We are currently observing about a 6-10% performance loss.
27+
# Two theories for why this is so:
28+
# 1. Some overhead remains in the code - to be investigated.
29+
# 2. The benchmarks were run on a laptop, and during the benchmarking
30+
# process the CPU is heating up and it can't turbo to the same speeds at
31+
# the end of the run as it can at the beginning. Meaning the observed 6-10%
32+
# slowdown at the end is an environmental issue and not an implementation
33+
# problem.
34+
#
3735

3836
# Used to quickly run benchmark under RSpec as part of the usual test suite, to validate it didn't bitrot
3937
VALIDATE_BENCHMARK_MODE = ENV['VALIDATE_BENCHMARK'] == 'true'
@@ -72,7 +70,7 @@ def test_method_for_line_probe
7270
attr_reader :instrumenter
7371

7472
def logger
75-
@logger ||= Logger.new(STDERR)
73+
@logger ||= Logger.new($stderr)
7674
end
7775

7876
def configure
@@ -92,7 +90,7 @@ def run_benchmark
9290
file, line = m.source_location
9391

9492
Benchmark.ips do |x|
95-
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 }
93+
benchmark_time = VALIDATE_BENCHMARK_MODE ? {time: 0.01, warmup: 0} : {time: 10, warmup: 2}
9694
x.config(
9795
**benchmark_time,
9896
)
@@ -116,7 +114,7 @@ def run_benchmark
116114
end
117115

118116
Benchmark.ips do |x|
119-
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 }
117+
benchmark_time = VALIDATE_BENCHMARK_MODE ? {time: 0.01, warmup: 0} : {time: 10, warmup: 2}
120118
x.config(
121119
**benchmark_time,
122120
)
@@ -159,7 +157,7 @@ def run_benchmark
159157
end
160158

161159
Benchmark.ips do |x|
162-
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 }
160+
benchmark_time = VALIDATE_BENCHMARK_MODE ? {time: 0.01, warmup: 0} : {time: 10, warmup: 2}
163161
x.config(
164162
**benchmark_time,
165163
)
@@ -208,7 +206,7 @@ def run_benchmark
208206
end
209207

210208
Benchmark.ips do |x|
211-
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 }
209+
benchmark_time = VALIDATE_BENCHMARK_MODE ? {time: 0.01, warmup: 0} : {time: 10, warmup: 2}
212210
x.config(
213211
**benchmark_time,
214212
)
@@ -237,7 +235,7 @@ def run_benchmark
237235
calls = 0
238236

239237
Benchmark.ips do |x|
240-
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 }
238+
benchmark_time = VALIDATE_BENCHMARK_MODE ? {time: 0.01, warmup: 0} : {time: 10, warmup: 2}
241239
x.config(
242240
**benchmark_time,
243241
)
@@ -257,7 +255,7 @@ def run_benchmark
257255
end
258256

259257
Benchmark.ips do |x|
260-
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 }
258+
benchmark_time = VALIDATE_BENCHMARK_MODE ? {time: 0.01, warmup: 0} : {time: 10, warmup: 2}
261259
x.config(
262260
**benchmark_time,
263261
)
@@ -277,7 +275,7 @@ def run_benchmark
277275
end
278276

279277
Benchmark.ips do |x|
280-
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 }
278+
benchmark_time = VALIDATE_BENCHMARK_MODE ? {time: 0.01, warmup: 0} : {time: 10, warmup: 2}
281279
x.config(
282280
**benchmark_time,
283281
)
@@ -289,9 +287,7 @@ def run_benchmark
289287
x.save! 'di-instrument-results.json' unless VALIDATE_BENCHMARK_MODE
290288
x.compare!
291289
end
292-
293290
end
294-
295291
end
296292

297293
puts "Current pid is #{Process.pid}"

0 commit comments

Comments
 (0)