debian-mirror-gitlab/lib/gitlab/usage/metrics/instrumentations/generic_metric.rb

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

50 lines
1.1 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class GenericMetric < BaseMetric
# Usage example
#
# class UuidMetric < GenericMetric
# value do
# Gitlab::CurrentSettings.uuid
# end
# end
2021-10-27 15:23:28 +05:30
FALLBACK = -1
2021-06-08 01:23:25 +05:30
class << self
2021-10-27 15:23:28 +05:30
attr_reader :metric_value
def fallback(custom_fallback = FALLBACK)
return @metric_fallback if defined?(@metric_fallback)
@metric_fallback = custom_fallback
end
2021-09-04 01:27:46 +05:30
2021-06-08 01:23:25 +05:30
def value(&block)
@metric_value = block
end
2021-10-27 15:23:28 +05:30
end
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
def initialize(time_frame: 'none', options: {})
@time_frame = time_frame
@options = options
2021-06-08 01:23:25 +05:30
end
def value
2021-10-27 15:23:28 +05:30
alt_usage_data(fallback: self.class.fallback) do
2021-06-08 01:23:25 +05:30
self.class.metric_value.call
end
end
2021-09-04 01:27:46 +05:30
def suggested_name
2021-10-27 15:23:28 +05:30
Gitlab::Usage::Metrics::NameSuggestion.for(:alt)
2021-09-04 01:27:46 +05:30
end
2021-06-08 01:23:25 +05:30
end
end
end
end
end