Class: Gitlab::Metrics::Transaction
- Inherits:
-
Object
- Object
- Gitlab::Metrics::Transaction
- Includes:
- Methods
- Defined in:
- lib/gitlab/metrics/transaction.rb
Overview
Class for storing metrics information of a single transaction.
Direct Known Subclasses
Constant Summary collapse
- FILTERED_LABEL_KEYS =
labels that potentially contain sensitive information and will be filtered
%i[branch path].freeze
- EVENT_SERIES =
The series to store events (e.g. Git pushes) in.
'events'
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
-
#add_event(event_name, tags = {}) ⇒ Object
Tracks a business level event.
- #filter_labels(labels) ⇒ Object
-
#increment(name, value = 1, labels = {}, &block) ⇒ Object
Increment counter metric.
-
#initialize ⇒ Transaction
constructor
A new instance of Transaction.
-
#method_call_for(name, module_name, method_name) ⇒ Object
Returns a MethodCall object for the given name.
-
#observe(name, value, labels = {}, &block) ⇒ Object
Observe histogram metric.
- #run ⇒ Object
-
#set(name, value, labels = {}, &block) ⇒ Object
Set gauge metric.
Constructor Details
#initialize ⇒ Transaction
Returns a new instance of Transaction.
17 18 19 |
# File 'lib/gitlab/metrics/transaction.rb', line 17 def initialize @methods = {} end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
15 16 17 |
# File 'lib/gitlab/metrics/transaction.rb', line 15 def method @method end |
Instance Method Details
#add_event(event_name, tags = {}) ⇒ Object
Tracks a business level event
Business level events including events such as Git pushes, Emails being sent, etc.
event_name - The name of the event (e.g. “git_push”). tags - A set of tags to attach to the event.
32 33 34 35 36 37 38 39 |
# File 'lib/gitlab/metrics/transaction.rb', line 32 def add_event(event_name, = {}) event_name = "gitlab_transaction_event_#{event_name}_total".to_sym metric = self.class.prometheus_metric(event_name, :counter) do label_keys .keys end metric.increment(filter_labels()) end |
#filter_labels(labels) ⇒ Object
108 109 110 |
# File 'lib/gitlab/metrics/transaction.rb', line 108 def filter_labels(labels) labels.empty? ? self.labels : labels.without(*FILTERED_LABEL_KEYS).merge(self.labels) end |
#increment(name, value = 1, labels = {}, &block) ⇒ Object
Increment counter metric
It will initialize the metric if metric is not found
block - if provided can be used to initialize metric with custom options (docstring, labels, with_feature)
Example: “‘ transaction.increment(:mestric_name, 1, { docstring: ’Custom title’, base_labels: ‘yes’ } ) do
transaction.increment(:mestric_name, 1) do
docstring 'Custom title'
label_keys %i(sane)
end “‘
65 66 67 68 69 |
# File 'lib/gitlab/metrics/transaction.rb', line 65 def increment(name, value = 1, labels = {}, &block) counter = self.class.prometheus_metric(name, :counter, &block) counter.increment(filter_labels(labels), value) end |
#method_call_for(name, module_name, method_name) ⇒ Object
Returns a MethodCall object for the given name.
42 43 44 45 46 47 48 |
# File 'lib/gitlab/metrics/transaction.rb', line 42 def method_call_for(name, module_name, method_name) unless method = @methods[name] @methods[name] = method = MethodCall.new(name, module_name, method_name, self) end method end |
#observe(name, value, labels = {}, &block) ⇒ Object
Observe histogram metric
It will initialize the metric if metric is not found
block - if provided, it can be used to initialize metric with custom options (docstring, labels, with_feature, buckets)
Example: “‘ transaction.observe(:mestric_name, 1) do
buckets [100, 1000, 10000, 100000, 1000000, 10000000]
end “‘
102 103 104 105 106 |
# File 'lib/gitlab/metrics/transaction.rb', line 102 def observe(name, value, labels = {}, &block) histogram = self.class.prometheus_metric(name, :histogram, &block) histogram.observe(filter_labels(labels), value) end |
#run ⇒ Object
21 22 23 |
# File 'lib/gitlab/metrics/transaction.rb', line 21 def run raise NotImplementedError end |
#set(name, value, labels = {}, &block) ⇒ Object
Set gauge metric
It will initialize the metric if metric is not found
block - if provided, it can be used to initialize metric with custom options (docstring, labels, with_feature, multiprocess_mode)
-
multiprocess_mode is :all by default
Example: “‘ transaction.set(:mestric_name, 1) do
multiprocess_mode :livesum
end “‘
84 85 86 87 88 |
# File 'lib/gitlab/metrics/transaction.rb', line 84 def set(name, value, labels = {}, &block) gauge = self.class.prometheus_metric(name, :gauge, &block) gauge.set(filter_labels(labels), value) end |