Skip to content
Snippets Groups Projects
Commit bd9f86bb authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Use separate series for Rails/Sidekiq transactions

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