Commit 827c01b1 authored by Tiago Botelho's avatar Tiago Botelho

Add the ability to add values to Metric events

parent 12d7d9fd
......@@ -5,8 +5,12 @@ class StuckImportJobsWorker
IMPORT_JOBS_EXPIRATION = 15.hours.to_i
def perform
mark_projects_without_jid_as_failed!
mark_projects_with_jid_as_failed!
values = {
projects_without_jid_count: mark_projects_without_jid_as_failed!,
projects_with_jid_count: mark_projects_with_jid_as_failed!
}
Gitlab::Metrics.add_event_with_values(:stuck_import_jobs, values)
end
private
......
......@@ -132,9 +132,11 @@ module Gitlab
#
# See `Gitlab::Metrics::Transaction#add_event` for more details.
def add_event(*args)
trans = current_transaction
current_transaction&.add_event(*args)
end
trans&.add_event(*args)
def add_event_with_values(*args)
current_transaction&.add_event_with_values(*args)
end
# Returns the prefix to use for the name of a series.
......
......@@ -66,8 +66,12 @@ module Gitlab
# event_name - The name of the event (e.g. "git_push").
# tags - A set of tags to attach to the event.
def add_event(event_name, tags = {})
add_event_with_values(event_name, {}, tags)
end
def add_event_with_values(event_name, values, tags = {})
@metrics << Metric.new(EVENT_SERIES,
{ count: 1 },
{ count: 1 }.merge(values),
{ event: event_name }.merge(tags),
:event)
end
......
......@@ -161,6 +161,30 @@ describe Gitlab::Metrics::Transaction do
end
end
describe '#add_event_with_values' do
it 'adds a metric' do
transaction.add_event_with_values(:meow, {})
expect(transaction.metrics[0]).to be_an_instance_of(Gitlab::Metrics::Metric)
end
it 'tracks values for every event' do
transaction.add_event_with_values(:meow, { number: 10 })
metric = transaction.metrics[0]
expect(metric.values).to eq(count: 1, number: 10)
end
it 'allows tracking of custom tags' do
transaction.add_event_with_values(:meow, {}, animal: 'cat')
metric = transaction.metrics[0]
expect(metric.tags).to eq(event: :meow, animal: 'cat')
end
end
describe '#add_event' do
it 'adds a metric' do
transaction.add_event(:meow)
......
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