summaryrefslogtreecommitdiff
path: root/lib/gitlab/usage/metrics/instrumentations/base_metric.rb
blob: f76ed1753b28f48fd0b691ccb9f17f9557479ff7 (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
# frozen_string_literal: true

module Gitlab
  module Usage
    module Metrics
      module Instrumentations
        class BaseMetric
          include Gitlab::Utils::UsageData
          include Gitlab::Usage::TimeFrame

          attr_reader :time_frame
          attr_reader :options

          class << self
            def available?(&block)
              return @metric_available = block if block_given?

              return @metric_available.call if instance_variable_defined?('@metric_available')

              true
            end

            attr_reader :metric_available
          end

          def initialize(time_frame:, options: {})
            @time_frame = time_frame
            @options = options
          end

          def instrumentation
            value
          end

          def available?
            self.class.available?
          end
        end
      end
    end
  end
end