Class: Gitlab::Metrics::Methods::MetricOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/metrics/methods/metric_options.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MetricOptions

Returns a new instance of MetricOptions.



7
8
9
10
11
12
13
# File 'lib/gitlab/metrics/methods/metric_options.rb', line 7

def initialize(options = {})
  @multiprocess_mode = options[:multiprocess_mode] || :all
  @buckets = options[:buckets] || ::Prometheus::Client::Histogram::DEFAULT_BUCKETS
  @docstring = options[:docstring]
  @with_feature = options[:with_feature]
  @label_keys = options[:label_keys] || []
end

Instance Method Details

#base_labelsObject

Base labels are merged with per metric labels



41
42
43
44
45
# File 'lib/gitlab/metrics/methods/metric_options.rb', line 41

def base_labels
  @base_labels ||= @label_keys.product([nil]).to_h

  @base_labels
end

#buckets(buckets = nil) ⇒ Object

Measurement buckets for histograms



34
35
36
37
38
# File 'lib/gitlab/metrics/methods/metric_options.rb', line 34

def buckets(buckets = nil)
  @buckets = buckets unless buckets.nil?

  @buckets
end

#docstring(docstring = nil) ⇒ Object

Documentation describing metric in metrics endpoint ‘/-/metrics’



16
17
18
19
20
# File 'lib/gitlab/metrics/methods/metric_options.rb', line 16

def docstring(docstring = nil)
  @docstring = docstring unless docstring.nil?

  @docstring
end

#evaluate(&block) ⇒ Object



63
64
65
66
67
# File 'lib/gitlab/metrics/methods/metric_options.rb', line 63

def evaluate(&block)
  instance_eval(&block) if block

  self
end

#label_keys(label_keys = nil) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/gitlab/metrics/methods/metric_options.rb', line 47

def label_keys(label_keys = nil)
  unless label_keys.nil?
    @label_keys = label_keys
    @base_labels = nil
  end

  @label_keys
end

#multiprocess_mode(mode = nil) ⇒ Object

Gauge aggregation mode for multiprocess metrics

  • :all (default) returns each gauge for every process

  • :livesum all process’es gauges summed up

  • :max maximum value of per process gauges

  • :min minimum value of per process gauges



27
28
29
30
31
# File 'lib/gitlab/metrics/methods/metric_options.rb', line 27

def multiprocess_mode(mode = nil)
  @multiprocess_mode = mode unless mode.nil?

  @multiprocess_mode
end

#with_feature(name = nil) ⇒ Object

Use feature toggle to control whether certain metric is enabled/disabled



57
58
59
60
61
# File 'lib/gitlab/metrics/methods/metric_options.rb', line 57

def with_feature(name = nil)
  @with_feature = name unless name.nil?

  @with_feature
end