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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.3 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
2022-07-16 23:28:13 +05:30
with_availability(proc { instrumentation_object.value })
2021-03-08 18:12:59 +05:30
end
2021-10-27 15:23:28 +05:30
def with_instrumentation
2022-07-16 23:28:13 +05:30
with_availability(proc { instrumentation_object.instrumentation })
2021-03-08 18:12:59 +05:30
end
2021-12-11 22:18:48 +05:30
def with_suggested_name
2022-07-16 23:28:13 +05:30
with_availability(proc { instrumentation_object.suggested_name })
2021-12-11 22:18:48 +05:30
end
2021-10-27 15:23:28 +05:30
private
2021-03-08 18:12:59 +05:30
2022-07-16 23:28:13 +05:30
def with_availability(value_proc)
return {} unless instrumentation_object.available?
unflatten_key_path(value_proc.call)
end
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
2022-07-16 23:28:13 +05:30
def instrumentation_object
2022-11-25 23:54:43 +05:30
@instrumentation_object ||= instrumentation_class.constantize.new(definition.attributes)
2021-03-08 18:12:59 +05:30
end
end
end
end