2021-05-07 08:10:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Usage
|
|
|
|
module Metrics
|
|
|
|
module Instrumentations
|
|
|
|
class BaseMetric
|
|
|
|
include Gitlab::Utils::UsageData
|
2021-05-25 14:10:42 -04:00
|
|
|
include Gitlab::Usage::TimeFrame
|
2021-05-07 08:10:27 -04:00
|
|
|
|
|
|
|
attr_reader :time_frame
|
2021-05-20 05:10:30 -04:00
|
|
|
attr_reader :options
|
2021-05-07 08:10:27 -04:00
|
|
|
|
2022-04-21 05:10:19 -04:00
|
|
|
class << self
|
|
|
|
def available?(&block)
|
2022-08-03 08:11:38 -04:00
|
|
|
return @metric_available = block if block
|
2022-04-21 05:10:19 -04:00
|
|
|
|
|
|
|
return @metric_available.call if instance_variable_defined?('@metric_available')
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :metric_available
|
|
|
|
end
|
|
|
|
|
2022-09-23 08:13:18 -04:00
|
|
|
def initialize(metric_definition)
|
|
|
|
@time_frame = metric_definition.fetch(:time_frame)
|
|
|
|
@options = metric_definition.fetch(:options, {})
|
2021-05-07 08:10:27 -04:00
|
|
|
end
|
2021-07-21 11:08:52 -04:00
|
|
|
|
|
|
|
def instrumentation
|
|
|
|
value
|
|
|
|
end
|
2022-04-21 05:10:19 -04:00
|
|
|
|
|
|
|
def available?
|
|
|
|
self.class.available?
|
|
|
|
end
|
2021-05-07 08:10:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|