Commit e947123d authored by Sean McGivern's avatar Sean McGivern

Use monotonic time in Redis instrumentation

Redis calls are very fast so clock skew is unlikely to be an issue, but
we should still use the better method of measuring time.
parent b93992b0
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
APDEX_EXCLUDE = %w[brpop blpop brpoplpush bzpopmin bzpopmax xread xreadgroup].freeze APDEX_EXCLUDE = %w[brpop blpop brpoplpush bzpopmin bzpopmax xread xreadgroup].freeze
def call(*args, &block) def call(*args, &block)
start = Time.now # must come first so that 'start' is always defined start = Gitlab::Metrics::System.monotonic_time # must come first so that 'start' is always defined
instrumentation_class.instance_count_request instrumentation_class.instance_count_request
instrumentation_class.redis_cluster_validate!(args.first) instrumentation_class.redis_cluster_validate!(args.first)
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
instrumentation_class.instance_count_exception(ex) instrumentation_class.instance_count_exception(ex)
raise ex raise ex
ensure ensure
duration = Time.now - start duration = Gitlab::Metrics::System.monotonic_time - start
unless APDEX_EXCLUDE.include?(command_from_args(args)) unless APDEX_EXCLUDE.include?(command_from_args(args))
instrumentation_class.instance_observe_duration(duration) instrumentation_class.instance_observe_duration(duration)
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
end end
def drop_jobs!(search_metadata, timeout:) def drop_jobs!(search_metadata, timeout:)
start_time = Gitlab::Metrics::System.monotonic_time start_time = monotonic_time
completed = true completed = true
deleted_jobs = 0 deleted_jobs = 0
...@@ -62,7 +62,11 @@ module Gitlab ...@@ -62,7 +62,11 @@ module Gitlab
end end
def timeout_exceeded?(start_time, timeout) def timeout_exceeded?(start_time, timeout)
(Gitlab::Metrics::System.monotonic_time - start_time) > timeout (monotonic_time - start_time) > timeout
end
def monotonic_time
Gitlab::Metrics::System.monotonic_time
end end
end end
end end
...@@ -31,7 +31,7 @@ RSpec.describe Gitlab::SidekiqQueue, :clean_gitlab_redis_queues do ...@@ -31,7 +31,7 @@ RSpec.describe Gitlab::SidekiqQueue, :clean_gitlab_redis_queues do
context 'when the queue is not processed in time' do context 'when the queue is not processed in time' do
before do before do
allow(Gitlab::Metrics::System).to receive(:monotonic_time).and_return(1, 2, 12) allow(sidekiq_queue).to receive(:monotonic_time).and_return(1, 2, 12)
end end
it 'returns a non-completion flag, the number of jobs deleted, and the remaining queue size' do it 'returns a non-completion flag, the number of jobs deleted, and the remaining queue size' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment