Skip to content

Commit c65742e

Browse files
committed
fix timeout issue for older redises
1 parent fa9b814 commit c65742e

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

instrumentation/sidekiq/Appraisals

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
{
4-
'sidekiq-7' => [['sidekiq', '~> 7.0']],
4+
'sidekiq-7.0' => [['sidekiq', '~> 7.0']],
55
'sidekiq-6.5' => [['sidekiq', '>= 6.5', '< 7.0']],
66
'sidekiq-6.0' => [
77
['sidekiq', '>= 6.0', '< 6.5'],
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright The OpenTelemetry Authors
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
module OpenTelemetry
8+
module Instrumentation
9+
module Sidekiq
10+
module Middlewares
11+
module Common
12+
private
13+
14+
def instrumentation
15+
Sidekiq::Instrumentation.instance
16+
end
17+
18+
def instrumentation_config
19+
Sidekiq::Instrumentation.instance.config
20+
end
21+
22+
# Bypasses _all_ enclosed logic unless metrics are enabled
23+
def with_meter(&block)
24+
instrumentation.with_meter(&block)
25+
end
26+
27+
# time an inner block and yield the duration to the given callback
28+
def timed(callback)
29+
return yield unless metrics_enabled?
30+
31+
t0 = monotonic_now
32+
33+
yield.tap do
34+
callback.call(monotonic_now - t0)
35+
end
36+
end
37+
38+
# FIXME: is this a util somewhere
39+
def realtime_now
40+
Process.clock_gettime(Process::CLOCK_REALTIME)
41+
end
42+
43+
def monotonic_now
44+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
45+
end
46+
47+
def tracer
48+
instrumentation.tracer
49+
end
50+
51+
def metrics_enabled?
52+
instrumentation.metrics_enabled?
53+
end
54+
end
55+
end
56+
end
57+
end
58+
end

instrumentation/sidekiq/opentelemetry-instrumentation-sidekiq.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
3232
spec.add_development_dependency 'appraisal', '~> 2.5'
3333
spec.add_development_dependency 'bundler', '~> 2.4'
3434
spec.add_development_dependency 'minitest', '~> 5.0'
35+
spec.add_development_dependency 'minitest-reporters'
3536
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1'
3637
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
3738
spec.add_development_dependency 'rspec-mocks'

instrumentation/sidekiq/test/test_helper.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
require 'active_job'
1111

1212
require 'minitest/autorun'
13+
require 'minitest/reporters'
1314
require 'rspec/mocks/minitest_integration'
1415
require 'sidekiq/testing'
1516

17+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
18+
1619
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('7.0.0')
1720
require 'helpers/mock_loader_for_7.0'
1821
elsif Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('6.5.0')
@@ -21,6 +24,14 @@
2124
require 'helpers/mock_loader'
2225
end
2326

27+
# speed up tests that rely on empty queues
28+
Sidekiq::BasicFetch::TIMEOUT = if Gem.loaded_specs['sidekiq'].version < Gem::Version.new('6.5.0')
29+
# Redis 4.8 has trouble with float timeouts given as positional arguments
30+
1
31+
else
32+
0.1
33+
end
34+
2435
# OpenTelemetry SDK config for testing
2536
EXPORTER = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
2637
span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(EXPORTER)

0 commit comments

Comments
 (0)