2021-01-05 04:10:15 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Usage
|
|
|
|
class Metric
|
2021-08-10 11:10:03 -04:00
|
|
|
attr_reader :definition
|
2021-01-05 04:10:15 -05:00
|
|
|
|
2021-08-10 11:10:03 -04:00
|
|
|
def initialize(definition)
|
|
|
|
@definition = definition
|
|
|
|
end
|
2021-01-05 04:10:15 -05:00
|
|
|
|
2021-08-10 11:10:03 -04:00
|
|
|
class << self
|
|
|
|
def all
|
|
|
|
@all ||= Gitlab::Usage::MetricDefinition.with_instrumentation_class.map do |definition|
|
|
|
|
self.new(definition)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-01-05 04:10:15 -05:00
|
|
|
|
2021-08-10 11:10:03 -04:00
|
|
|
def with_value
|
|
|
|
unflatten_key_path(intrumentation_object.value)
|
2021-01-05 04:10:15 -05:00
|
|
|
end
|
|
|
|
|
2021-08-10 11:10:03 -04:00
|
|
|
def with_instrumentation
|
|
|
|
unflatten_key_path(intrumentation_object.instrumentation)
|
2021-01-05 04:10:15 -05:00
|
|
|
end
|
|
|
|
|
2021-10-25 14:12:16 -04:00
|
|
|
def with_suggested_name
|
|
|
|
unflatten_key_path(intrumentation_object.suggested_name)
|
|
|
|
end
|
|
|
|
|
2021-08-10 11:10:03 -04:00
|
|
|
private
|
2021-01-05 04:10:15 -05:00
|
|
|
|
2021-08-10 11:10:03 -04:00
|
|
|
def unflatten_key_path(value)
|
|
|
|
::Gitlab::Usage::Metrics::KeyPathProcessor.process(definition.key_path, value)
|
2021-01-05 04:10:15 -05:00
|
|
|
end
|
|
|
|
|
2021-08-10 11:10:03 -04:00
|
|
|
def instrumentation_class
|
|
|
|
"Gitlab::Usage::Metrics::Instrumentations::#{definition.instrumentation_class}"
|
|
|
|
end
|
2021-01-05 04:10:15 -05:00
|
|
|
|
2021-08-10 11:10:03 -04:00
|
|
|
def intrumentation_object
|
|
|
|
instrumentation_class.constantize.new(
|
|
|
|
time_frame: definition.time_frame,
|
|
|
|
options: definition.attributes[:options]
|
|
|
|
)
|
2021-01-05 04:10:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|