summaryrefslogtreecommitdiff
path: root/lib/gitlab/usage/metric.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/gitlab/usage/metric.rb
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
downloadgitlab-ce-8c890596f5d0792c467fe12805ab1b39f93bf140.tar.gz
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'lib/gitlab/usage/metric.rb')
-rw-r--r--lib/gitlab/usage/metric.rb49
1 files changed, 26 insertions, 23 deletions
diff --git a/lib/gitlab/usage/metric.rb b/lib/gitlab/usage/metric.rb
index f3469209f48..5b1ac189c13 100644
--- a/lib/gitlab/usage/metric.rb
+++ b/lib/gitlab/usage/metric.rb
@@ -3,40 +3,43 @@
module Gitlab
module Usage
class Metric
- include ActiveModel::Model
+ attr_reader :definition
- InvalidMetricError = Class.new(RuntimeError)
-
- attr_accessor :key_path, :value
+ def initialize(definition)
+ @definition = definition
+ end
- validates :key_path, presence: true
+ class << self
+ def all
+ @all ||= Gitlab::Usage::MetricDefinition.with_instrumentation_class.map do |definition|
+ self.new(definition)
+ end
+ end
+ end
- def definition
- self.class.definitions[key_path]
+ def with_value
+ unflatten_key_path(intrumentation_object.value)
end
- def unflatten_key_path
- unflatten(key_path.split('.'), value)
+ def with_instrumentation
+ unflatten_key_path(intrumentation_object.instrumentation)
end
- class << self
- def definitions
- @definitions ||= Gitlab::Usage::MetricDefinition.definitions
- end
+ private
- def dictionary
- definitions.map { |key, definition| definition.to_dictionary }
- end
+ def unflatten_key_path(value)
+ ::Gitlab::Usage::Metrics::KeyPathProcessor.process(definition.key_path, value)
end
- private
+ def instrumentation_class
+ "Gitlab::Usage::Metrics::Instrumentations::#{definition.instrumentation_class}"
+ end
- def unflatten(keys, value)
- loop do
- value = { keys.pop.to_sym => value }
- break if keys.blank?
- end
- value
+ def intrumentation_object
+ instrumentation_class.constantize.new(
+ time_frame: definition.time_frame,
+ options: definition.attributes[:options]
+ )
end
end
end