Welcome to mirror list, hosted at ThFree Co, Russian Federation.

generic_metric.rb « instrumentations « metrics « usage « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7c6462815980c5d27082954454182b34886fb5a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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
          FALLBACK = -1

          class << self
            attr_reader :metric_value

            def fallback(custom_fallback = FALLBACK)
              return @metric_fallback if defined?(@metric_fallback)

              @metric_fallback = custom_fallback
            end

            def value(&block)
              @metric_value = block
            end
          end

          def initialize(metric_definition)
            super(metric_definition.reverse_merge(time_frame: 'none'))
          end

          def value
            alt_usage_data(fallback: self.class.fallback) do
              self.class.metric_value.call
            end
          end

          def suggested_name
            Gitlab::Usage::Metrics::NameSuggestion.for(:alt)
          end
        end
      end
    end
  end
end