Commit bd9f86bb authored by Yorick Peterse's avatar Yorick Peterse

Use separate series for Rails/Sidekiq transactions

This removes the need for tagging all metrics with a "process_type" tag.
parent 55ed6e1c
......@@ -19,8 +19,7 @@ module Gitlab
{
series: @series,
tags: @tags.merge(
hostname: Metrics.hostname,
process_type: Sidekiq.server? ? 'sidekiq' : 'rails'
hostname: Metrics.hostname
),
values: @values,
timestamp: @created_at.to_i * 1_000_000_000
......
......@@ -4,6 +4,8 @@ module Gitlab
class RackMiddleware
CONTROLLER_KEY = 'action_controller.instance'
SERIES = 'rails_transactions'
def initialize(app)
@app = app
end
......@@ -30,7 +32,7 @@ module Gitlab
end
def transaction_from_env(env)
trans = Transaction.new
trans = Transaction.new(SERIES)
trans.add_tag(:request_method, env['REQUEST_METHOD'])
trans.add_tag(:request_uri, env['REQUEST_URI'])
......
......@@ -4,8 +4,10 @@ module Gitlab
#
# This middleware is intended to be used as a server-side middleware.
class SidekiqMiddleware
SERIES = 'sidekiq_transactions'
def call(worker, message, queue)
trans = Transaction.new
trans = Transaction.new(SERIES)
begin
trans.run { yield }
......
......@@ -4,8 +4,6 @@ module Gitlab
class Transaction
THREAD_KEY = :_gitlab_metrics_transaction
SERIES = 'transactions'
attr_reader :uuid, :tags
def self.current
......@@ -13,7 +11,8 @@ module Gitlab
end
# name - The name of this transaction as a String.
def initialize
def initialize(series)
@series = series
@metrics = []
@uuid = SecureRandom.uuid
......@@ -55,7 +54,7 @@ module Gitlab
end
def track_self
add_metric(SERIES, { duration: duration }, @tags)
add_metric(@series, { duration: duration }, @tags)
end
def submit
......
require 'spec_helper'
describe Gitlab::Metrics::Instrumentation do
let(:transaction) { Gitlab::Metrics::Transaction.new }
let(:transaction) { Gitlab::Metrics::Transaction.new('rspec') }
before do
@dummy = Class.new do
......
......@@ -39,7 +39,6 @@ describe Gitlab::Metrics::Metric do
expect(hash[:tags]).to be_an_instance_of(Hash)
expect(hash[:tags][:hostname]).to be_an_instance_of(String)
expect(hash[:tags][:process_type]).to be_an_instance_of(String)
end
it 'includes the values' do
......
......@@ -15,7 +15,7 @@ describe Gitlab::Metrics::SidekiqMiddleware do
describe '#tag_worker' do
it 'adds the worker class and action to the transaction' do
trans = Gitlab::Metrics::Transaction.new
trans = Gitlab::Metrics::Transaction.new('rspec')
worker = double(:worker, class: double(:class, name: 'TestWorker'))
expect(trans).to receive(:add_tag).with(:action, 'TestWorker#perform')
......
require 'spec_helper'
describe Gitlab::Metrics::Subscribers::ActionView do
let(:transaction) { Gitlab::Metrics::Transaction.new }
let(:transaction) { Gitlab::Metrics::Transaction.new('rspec') }
let(:subscriber) { described_class.new }
......
require 'spec_helper'
describe Gitlab::Metrics::Transaction do
let(:transaction) { described_class.new }
let(:transaction) { described_class.new('rspec') }
describe '#duration' do
it 'returns the duration of a transaction in seconds' do
......@@ -58,7 +58,7 @@ describe Gitlab::Metrics::Transaction do
describe '#track_self' do
it 'adds a metric for the transaction itself' do
expect(transaction).to receive(:add_metric).
with(described_class::SERIES, { duration: transaction.duration }, {})
with('rspec', { duration: transaction.duration }, {})
transaction.track_self
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