gitlab-org--gitlab-foss/lib/gitlab/metrics/methods/metric_options.rb

62 lines
1.7 KiB
Ruby
Raw Normal View History

2018-01-16 08:06:56 -05:00
module Gitlab
module Metrics
2018-01-29 06:33:08 -05:00
module Methods
2018-01-16 08:06:56 -05:00
class MetricOptions
SMALL_NETWORK_BUCKETS = [0.005, 0.01, 0.1, 1, 10].freeze
2018-01-16 08:06:56 -05:00
def initialize(options = {})
@multiprocess_mode = options[:multiprocess_mode] || :all
@buckets = options[:buckets] || SMALL_NETWORK_BUCKETS
2018-01-16 08:06:56 -05:00
@base_labels = options[:base_labels] || {}
2018-01-16 09:47:07 -05:00
@docstring = options[:docstring]
@with_feature = options[:with_feature]
2018-01-16 08:06:56 -05:00
end
# Documentation describing metric in metrics endpoint '/-/metrics'
2018-01-16 09:47:07 -05:00
def docstring(docstring = nil)
@docstring = docstring unless docstring.nil?
2018-01-16 08:06:56 -05:00
2018-01-16 09:47:07 -05:00
@docstring
2018-01-16 08:06:56 -05:00
end
# 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
2018-01-16 09:47:07 -05:00
def multiprocess_mode(mode = nil)
@multiprocess_mode = mode unless mode.nil?
2018-01-16 08:06:56 -05:00
@multiprocess_mode
end
# Measurement buckets for histograms
2018-01-16 09:47:07 -05:00
def buckets(buckets = nil)
@buckets = buckets unless buckets.nil?
2018-01-16 08:06:56 -05:00
@buckets
end
# Base labels are merged with per metric labels
2018-01-16 09:47:07 -05:00
def base_labels(base_labels = nil)
@base_labels = base_labels unless base_labels.nil?
2018-01-16 08:06:56 -05:00
@base_labels
end
# Use feature toggle to control whether certain metric is enabled/disabled
2018-01-16 09:47:07 -05:00
def with_feature(name = nil)
2018-01-18 07:37:53 -05:00
@with_feature = name unless name.nil?
2018-01-16 08:06:56 -05:00
2018-01-18 07:37:53 -05:00
@with_feature
2018-01-16 08:06:56 -05:00
end
def evaluate(&block)
instance_eval(&block) if block_given?
self
end
end
end
end
end