summaryrefslogtreecommitdiff
path: root/lib/gitlab/usage/metric.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/usage/metric.rb')
-rw-r--r--lib/gitlab/usage/metric.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/gitlab/usage/metric.rb b/lib/gitlab/usage/metric.rb
index 24e044c5740..cf48aa49938 100644
--- a/lib/gitlab/usage/metric.rb
+++ b/lib/gitlab/usage/metric.rb
@@ -18,19 +18,25 @@ module Gitlab
end
def with_value
- unflatten_key_path(intrumentation_object.value)
+ with_availability(proc { instrumentation_object.value })
end
def with_instrumentation
- unflatten_key_path(intrumentation_object.instrumentation)
+ with_availability(proc { instrumentation_object.instrumentation })
end
def with_suggested_name
- unflatten_key_path(intrumentation_object.suggested_name)
+ with_availability(proc { instrumentation_object.suggested_name })
end
private
+ def with_availability(value_proc)
+ return {} unless instrumentation_object.available?
+
+ unflatten_key_path(value_proc.call)
+ end
+
def unflatten_key_path(value)
::Gitlab::Usage::Metrics::KeyPathProcessor.process(definition.key_path, value)
end
@@ -39,8 +45,8 @@ module Gitlab
"Gitlab::Usage::Metrics::Instrumentations::#{definition.instrumentation_class}"
end
- def intrumentation_object
- instrumentation_class.constantize.new(
+ def instrumentation_object
+ @instrumentation_object ||= instrumentation_class.constantize.new(
time_frame: definition.time_frame,
options: definition.attributes[:options]
)