debian-mirror-gitlab/lib/gitlab/usage/metric.rb

51 lines
1.2 KiB
Ruby
Raw Normal View History

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