Commit 49ce6812 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'osw-client-metrics-middleware-fix' into 'master'

Adjust client middleware metrics Counter

See merge request gitlab-org/gitlab!23515
parents ccd0962a 25184845
......@@ -9,8 +9,10 @@ module Gitlab
@metrics = init_metrics
end
def call(worker, _job, queue, _redis_pool)
labels = create_labels(worker.class, queue)
def call(worker_class, _job, queue, _redis_pool)
# 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)
@metrics.fetch(ENQUEUED).increment(labels, 1)
......
......@@ -10,7 +10,7 @@ module Gitlab
def create_labels(worker_class, queue)
labels = { queue: queue.to_s, latency_sensitive: FALSE_LABEL, external_dependencies: FALSE_LABEL, feature_category: "", boundary: "" }
return labels unless worker_class.include? WorkerAttributes
return labels unless worker_class && worker_class.include?(WorkerAttributes)
labels[:latency_sensitive] = bool_as_label(worker_class.latency_sensitive_worker?)
labels[:external_dependencies] = bool_as_label(worker_class.worker_has_external_dependencies?)
......
......@@ -21,13 +21,19 @@ describe Gitlab::SidekiqMiddleware::ClientMetrics do
describe '#call' do
it 'yields block' do
expect { |b| subject.call(worker, job, :test, double, &b) }.to yield_control.once
expect { |b| subject.call(worker_class, job, :test, double, &b) }.to yield_control.once
end
it 'increments enqueued jobs metric' do
it 'increments enqueued jobs metric with correct labels when worker is a string of the class' do
expect(enqueued_jobs_metric).to receive(:increment).with(labels, 1)
subject.call(worker, job, :test, double) { nil }
subject.call(worker_class.to_s, job, :test, double) { nil }
end
it 'increments enqueued jobs metric with correct labels' do
expect(enqueued_jobs_metric).to receive(:increment).with(labels, 1)
subject.call(worker_class, job, :test, double) { nil }
end
end
end
......@@ -46,7 +52,7 @@ describe Gitlab::SidekiqMiddleware::ClientMetrics do
context "when workers are attributed" do
def create_attributed_worker_class(latency_sensitive, external_dependencies, resource_boundary, category)
Class.new do
klass = Class.new do
include Sidekiq::Worker
include WorkerAttributes
......@@ -55,6 +61,7 @@ describe Gitlab::SidekiqMiddleware::ClientMetrics do
worker_resource_boundary resource_boundary unless resource_boundary == :unknown
feature_category category unless category.nil?
end
stub_const("TestAttributedWorker", klass)
end
let(:latency_sensitive) { false }
......
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