Commit 30a4bb66 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Fix sidekiq middleware tests

parent 043545de
module Gitlab
module Metrics
class SidekiqTransaction
class SidekiqTransaction < Transaction
def initialize(worker_class)
super()
@worker_class = worker_class
end
protected
def labels
{ controller: worker.class.name, action: 'perform' }
{ controller: @worker_class.name, action: 'perform' }
end
end
end
......
module Gitlab
module Metrics
# Class for storing metrics information of a single transaction.
class BaseTransaction
class Transaction
# base labels shared among all transactions
BASE_LABELS = { controller: nil, action: nil }.freeze
......@@ -131,8 +131,6 @@ module Gitlab
"#{labels[:controller]}##{labels[:action]}" if labels && !labels.empty?
end
protected
def self.metric_transaction_duration_seconds
@metric_transaction_duration_seconds ||= Gitlab::Metrics.histogram(
:gitlab_transaction_duration_seconds,
......
module Gitlab
module Metrics
class WebTransaction < BaseTransaction
class WebTransaction < Transaction
CONTROLLER_KEY = 'action_controller.instance'.freeze
ENDPOINT_KEY = 'api.endpoint'.freeze
......
......@@ -6,7 +6,7 @@ describe Gitlab::Metrics::SidekiqMiddleware do
def run(worker, message)
expect(Gitlab::Metrics::Transaction).to receive(:new)
.with('TestWorker#perform')
.with(worker.class)
.and_call_original
expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:set)
......@@ -18,21 +18,22 @@ describe Gitlab::Metrics::SidekiqMiddleware do
end
describe '#call' do
it 'tracks the transaction' do
worker = double(:worker, class: double(:class, name: 'TestWorker'))
let(:test_worker_class) { double(:class, name: 'TestWorker') }
let(:worker) { double(:worker, class: test_worker_class) }
it 'reports correct action based on worker class' do
end
it 'tracks the transaction' do
run(worker, message)
end
it 'tracks the transaction (for messages without `enqueued_at`)' do
worker = double(:worker, class: double(:class, name: 'TestWorker'))
run(worker, {})
end
it 'tracks any raised exceptions' do
worker = double(:worker, class: double(:class, name: 'TestWorker'))
expect_any_instance_of(Gitlab::Metrics::Transaction)
.to receive(:run).and_raise(RuntimeError)
......@@ -45,18 +46,5 @@ describe Gitlab::Metrics::SidekiqMiddleware do
expect { middleware.call(worker, message, :test) }
.to raise_error(RuntimeError)
end
it 'tags the metrics accordingly' do
tags = { one: 1, two: 2 }
worker = double(:worker, class: double(:class, name: 'TestWorker'))
allow(worker).to receive(:metrics_tags).and_return(tags)
tags.each do |tag, value|
expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:add_tag)
.with(tag, value)
end
run(worker, message)
end
end
end
......@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::Metrics::Subscribers::RailsCache do
let(:env) { {} }
let(:transaction) { Gitlab::Metrics::Transaction.new(env) }
let(:transaction) { Gitlab::Metrics::WebTransaction.new(env) }
let(:subscriber) { described_class.new }
let(:event) { double(:event, duration: 15.2) }
......
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