summaryrefslogtreecommitdiff
path: root/lib/gitlab/usage/metrics/instrumentations/generic_metric.rb
blob: 1849773e33dd26eb7396652b1016acef5d422abe (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
# 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
          class << self
            attr_reader :metric_operation
            @metric_operation = :alt

            def value(&block)
              @metric_value = block
            end

            attr_reader :metric_value
          end

          def value
            alt_usage_data do
              self.class.metric_value.call
            end
          end

          def suggested_name
            Gitlab::Usage::Metrics::NameSuggestion.for(
              self.class.metric_operation
            )
          end
        end
      end
    end
  end
end