Commit 39ac6acb authored by Pawel Chojnacki's avatar Pawel Chojnacki

Fix Active record and transaction specs

parent 38fbd25b
......@@ -101,7 +101,7 @@ module Gitlab
# tags - A set of tags to attach to the event.
def add_event(event_name, tags = {})
self.class.metric_event_counter(event_name, tags).increment(tags.merge(labels))
@metrics << Metric.new(EVENT_SERIES, { count: 1 }, tags, :event)
@metrics << Metric.new(EVENT_SERIES, { count: 1 }, tags.merge(event: event_name), :event)
end
# Returns a MethodCall object for the given name.
......
require 'spec_helper'
describe Gitlab::Metrics::Instrumentation do
let(:transaction) { Gitlab::Metrics::Transaction.new }
let(:env) { {} }
let(:transaction) { Gitlab::Metrics::Transaction.new(env) }
before do
@dummy = Class.new do
......
require 'spec_helper'
describe Gitlab::Metrics::Subscribers::ActiveRecord do
let(:transaction) { Gitlab::Metrics::Transaction.new }
let(:env) { {} }
let(:transaction) { Gitlab::Metrics::Transaction.new(env) }
let(:subscriber) { described_class.new }
let(:event) do
double(:event, duration: 0.2,
double(:event, duration: 2,
payload: { sql: 'SELECT * FROM users WHERE id = 10' })
end
......@@ -20,16 +21,24 @@ describe Gitlab::Metrics::Subscribers::ActiveRecord do
end
describe 'with a current transaction' do
it 'observes sql_duration metric' do
expect(subscriber).to receive(:current_transaction)
.at_least(:once)
.and_return(transaction)
expect(described_class.metric_sql_duration_seconds).to receive(:observe).with({}, 0.002)
subscriber.sql(event)
end
it 'increments the :sql_duration value' do
expect(subscriber).to receive(:current_transaction)
.at_least(:once)
.and_return(transaction)
expect(transaction).to receive(:increment)
.with(:sql_duration, 0.2)
.with(:sql_duration, 2, false)
expect(transaction).to receive(:increment)
.with(:sql_count, 1)
.with(:sql_count, 1, false)
subscriber.sql(event)
end
......
require 'spec_helper'
describe Gitlab::Metrics::Transaction do
let(:transaction) { described_class.new }
let(:env) { {} }
let(:transaction) { described_class.new(env) }
describe '#duration' do
it 'returns the duration of a transaction in seconds' do
......@@ -48,7 +49,7 @@ describe Gitlab::Metrics::Transaction do
describe '#method_call_for' do
it 'returns a MethodCall' do
method = transaction.method_call_for('Foo#bar')
method = transaction.method_call_for('Foo#bar', :Foo, '#bar')
expect(method).to be_an_instance_of(Gitlab::Metrics::MethodCall)
end
......@@ -119,7 +120,7 @@ describe Gitlab::Metrics::Transaction do
end
it 'adds the action as a tag for every metric' do
transaction.action = 'Foo#bar'
allow(transaction).to receive(:labels).and_return(controller: 'Foo', action: 'bar')
transaction.track_self
hash = {
......@@ -136,7 +137,8 @@ describe Gitlab::Metrics::Transaction do
end
it 'does not add an action tag for events' do
transaction.action = 'Foo#bar'
allow(transaction).to receive(:labels).and_return(controller: 'Foo', action: 'bar')
transaction.add_event(:meow)
hash = {
......
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