Commit 9f95ff0d authored by Yorick Peterse's avatar Yorick Peterse

Track location information as tags

This allows the information to be displayed when using certain functions
(e.g. top()) as well as making it easier to aggregate on a per file
basis.
parent d0352e66
......@@ -16,10 +16,10 @@ module Gitlab
private
def track(event)
path = relative_path(event.payload[:identifier])
values = values_for(event)
tags = tags_for(event)
current_transaction.add_metric(SERIES, values, path: path)
current_transaction.add_metric(SERIES, values, tags)
end
def relative_path(path)
......@@ -27,16 +27,21 @@ module Gitlab
end
def values_for(event)
values = { duration: event.duration }
{ duration: event.duration }
end
def tags_for(event)
path = relative_path(event.payload[:identifier])
tags = { view: path }
file, line = Metrics.last_relative_application_frame
if file and line
values[:file] = file
values[:line] = line
tags[:file] = file
tags[:line] = line
end
values
tags
end
def current_transaction
......
......@@ -13,25 +13,30 @@ module Gitlab
def sql(event)
return unless current_transaction
sql = ObfuscatedSQL.new(event.payload[:sql]).to_s
values = values_for(event)
tags = tags_for(event)
current_transaction.add_metric(SERIES, values, sql: sql)
current_transaction.add_metric(SERIES, values, tags)
end
private
def values_for(event)
values = { duration: event.duration }
{ duration: event.duration }
end
def tags_for(event)
sql = ObfuscatedSQL.new(event.payload[:sql]).to_s
tags = { sql: sql }
file, line = Metrics.last_relative_application_frame
if file and line
values[:file] = file
values[:line] = line
tags[:file] = file
tags[:line] = line
end
values
tags
end
def current_transaction
......
......@@ -21,10 +21,15 @@ describe Gitlab::Metrics::Subscribers::ActionView do
describe '#render_template' do
it 'tracks rendering of a template' do
values = { duration: 2.1, file: 'app/views/x.html.haml', line: 4 }
values = { duration: 2.1 }
tags = {
view: 'app/views/x.html.haml',
file: 'app/views/x.html.haml',
line: 4
}
expect(transaction).to receive(:add_metric).
with(described_class::SERIES, values, path: 'app/views/x.html.haml')
with(described_class::SERIES, values, tags)
subscriber.render_template(event)
end
......
......@@ -19,11 +19,12 @@ describe Gitlab::Metrics::Subscribers::ActiveRecord do
describe '#sql' do
it 'tracks the execution of a SQL query' do
values = { duration: 0.2, file: 'app/models/foo.rb', line: 4 }
sql = 'SELECT * FROM users WHERE id = ?'
values = { duration: 0.2 }
tags = { sql: sql, file: 'app/models/foo.rb', line: 4 }
expect(transaction).to receive(:add_metric).
with(described_class::SERIES, values, sql: sql)
with(described_class::SERIES, values, tags)
subscriber.sql(event)
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