Use separate series for Rails/Sidekiq transactions
This removes the need for tagging all metrics with a "process_type" tag.
This commit is contained in:
parent
55ed6e1c96
commit
bd9f86bb8a
|
@ -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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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')
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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 }
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue