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
APDEX_EXCLUDE = %w[brpop blpop brpoplpush bzpopmin bzpopmax xread xreadgroup].freeze
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.redis_cluster_validate!(args.first)
......@@ -15,7 +15,7 @@ module Gitlab
instrumentation_class.instance_count_exception(ex)
raise ex
ensure
duration = Time.now - start
duration = Gitlab::Metrics::System.monotonic_time - start
unless APDEX_EXCLUDE.include?(command_from_args(args))
instrumentation_class.instance_observe_duration(duration)
......
......@@ -14,7 +14,7 @@ module Gitlab
end
def drop_jobs!(search_metadata, timeout:)
start_time = Gitlab::Metrics::System.monotonic_time
start_time = monotonic_time
completed = true
deleted_jobs = 0
......@@ -62,7 +62,11 @@ module Gitlab
end
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
......@@ -31,7 +31,7 @@ RSpec.describe Gitlab::SidekiqQueue, :clean_gitlab_redis_queues do
context 'when the queue is not processed in time' 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
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