summaryrefslogtreecommitdiff
path: root/lib/gitlab/metrics/transaction.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-01-11 16:51:01 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2016-01-11 16:51:01 +0100
commit35b501f30ae9e121151ad6a2140d036e5ef3b0f5 (patch)
tree9d6e05cdb918bec61c1452e78a3e612a2fabe877 /lib/gitlab/metrics/transaction.rb
parentf41b535ced0cdddb67661bdb0a6216216dc6b89c (diff)
downloadgitlab-ce-35b501f30ae9e121151ad6a2140d036e5ef3b0f5.tar.gz
Tag all transaction metrics with an "action" tag
Without this it's impossible to find out what methods/views/queries are executed by a certain controller or Sidekiq worker. While this will increase the total number of series it should stay within reasonable limits due to the amount of "actions" being small enough.
Diffstat (limited to 'lib/gitlab/metrics/transaction.rb')
-rw-r--r--lib/gitlab/metrics/transaction.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/gitlab/metrics/transaction.rb b/lib/gitlab/metrics/transaction.rb
index 73131cc6ef2..86606b1c6d6 100644
--- a/lib/gitlab/metrics/transaction.rb
+++ b/lib/gitlab/metrics/transaction.rb
@@ -6,11 +6,15 @@ module Gitlab
attr_reader :tags, :values
+ attr_accessor :action
+
def self.current
Thread.current[THREAD_KEY]
end
- def initialize
+ # action - A String describing the action performed, usually the class
+ # plus method name.
+ def initialize(action = nil)
@metrics = []
@started_at = nil
@@ -18,6 +22,7 @@ module Gitlab
@values = Hash.new(0)
@tags = {}
+ @action = action
end
def duration
@@ -70,7 +75,15 @@ module Gitlab
end
def submit
- Metrics.submit_metrics(@metrics.map(&:to_hash))
+ metrics = @metrics.map do |metric|
+ hash = metric.to_hash
+
+ hash[:tags][:action] ||= @action if @action
+
+ hash
+ end
+
+ Metrics.submit_metrics(metrics)
end
def sidekiq?