debian-mirror-gitlab/lib/gitlab/metrics/methods/metric_options.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
1.9 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Gitlab
module Metrics
module Methods
class MetricOptions
def initialize(options = {})
@multiprocess_mode = options[:multiprocess_mode] || :all
2020-10-24 23:57:45 +05:30
@buckets = options[:buckets] || ::Prometheus::Client::Histogram::DEFAULT_BUCKETS
2018-03-17 18:26:18 +05:30
@docstring = options[:docstring]
@with_feature = options[:with_feature]
2020-10-24 23:57:45 +05:30
@label_keys = options[:label_keys] || []
2018-03-17 18:26:18 +05:30
end
# Documentation describing metric in metrics endpoint '/-/metrics'
def docstring(docstring = nil)
@docstring = docstring unless docstring.nil?
@docstring
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
def multiprocess_mode(mode = nil)
@multiprocess_mode = mode unless mode.nil?
@multiprocess_mode
end
# Measurement buckets for histograms
def buckets(buckets = nil)
@buckets = buckets unless buckets.nil?
@buckets
end
# Base labels are merged with per metric labels
2020-10-24 23:57:45 +05:30
def base_labels
@base_labels ||= @label_keys.product([nil]).to_h
2018-03-17 18:26:18 +05:30
@base_labels
end
2020-10-24 23:57:45 +05:30
def label_keys(label_keys = nil)
unless label_keys.nil?
@label_keys = label_keys
@base_labels = nil
end
@label_keys
end
2018-03-17 18:26:18 +05:30
# Use feature toggle to control whether certain metric is enabled/disabled
def with_feature(name = nil)
@with_feature = name unless name.nil?
@with_feature
end
def evaluate(&block)
instance_eval(&block) if block_given?
2020-10-24 23:57:45 +05:30
2018-03-17 18:26:18 +05:30
self
end
end
end
end
end