Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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