Commit 0b0eddca authored by Sean McGivern's avatar Sean McGivern

Merge branch '333671-fix-double-count-sidekiq-queue-events' into 'master'

Fix double counting Sidekiq queue events [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!64322
parents 98d7e528 7eeb0632
......@@ -15,6 +15,7 @@ module Gitlab
# worker_class can either be the string or class of the worker being enqueued.
worker_class = worker_class.safe_constantize if worker_class.respond_to?(:safe_constantize)
labels = create_labels(worker_class, queue, job)
labels[:scheduling] = job.key?('at') ? 'delayed' : 'immediate'
@metrics.fetch(ENQUEUED).increment(labels, 1)
......
......@@ -3,11 +3,12 @@
require 'spec_helper'
RSpec.describe Gitlab::SidekiqMiddleware::ClientMetrics do
let(:enqueued_jobs_metric) { double('enqueued jobs metric', increment: true) }
shared_examples "a metrics middleware" do
context "with mocked prometheus" do
let(:enqueued_jobs_metric) { double('enqueued jobs metric', increment: true) }
before do
labels[:scheduling] = 'immediate'
allow(Gitlab::Metrics).to receive(:counter).with(described_class::ENQUEUED, anything).and_return(enqueued_jobs_metric)
end
......@@ -32,4 +33,35 @@ RSpec.describe Gitlab::SidekiqMiddleware::ClientMetrics do
end
it_behaves_like 'metrics middleware with worker attribution'
context 'when mounted' do
before do
stub_const('TestWorker', Class.new)
TestWorker.class_eval do
include Sidekiq::Worker
def perform(*args)
end
end
allow(Gitlab::Metrics).to receive(:counter).and_return(Gitlab::Metrics::NullMetric.instance)
allow(Gitlab::Metrics).to receive(:counter).with(described_class::ENQUEUED, anything).and_return(enqueued_jobs_metric)
end
context 'when scheduling jobs for immediate execution' do
it 'increments enqueued jobs metric with scheduling label set to immediate' do
expect(enqueued_jobs_metric).to receive(:increment).with(a_hash_including(scheduling: 'immediate'), 1)
Sidekiq::Testing.inline! { TestWorker.perform_async }
end
end
context 'when scheduling jobs for future execution' do
it 'increments enqueued jobs metric with scheduling label set to delayed' do
expect(enqueued_jobs_metric).to receive(:increment).with(a_hash_including(scheduling: 'delayed'), 1)
Sidekiq::Testing.inline! { TestWorker.perform_in(1.second) }
end
end
end
end
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