2021-03-05 18:09:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Usage
|
|
|
|
module Metrics
|
|
|
|
module NamesSuggestions
|
|
|
|
class Generator < ::Gitlab::UsageData
|
|
|
|
class << self
|
|
|
|
def generate(key_path)
|
2022-02-09 00:15:57 +00:00
|
|
|
data.deep_stringify_keys.dig(*key_path.split('.'))
|
2021-03-05 18:09:17 +00:00
|
|
|
end
|
|
|
|
|
2021-10-28 09:13:54 +00:00
|
|
|
def add_metric(metric, time_frame: 'none', options: {})
|
2021-07-21 15:08:52 +00:00
|
|
|
metric_class = "Gitlab::Usage::Metrics::Instrumentations::#{metric}".constantize
|
|
|
|
|
2021-10-28 09:13:54 +00:00
|
|
|
metric_class.new(time_frame: time_frame, options: options).suggested_name
|
2021-07-21 15:08:52 +00:00
|
|
|
end
|
|
|
|
|
2021-03-05 18:09:17 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def count(relation, column = nil, batch: true, batch_size: nil, start: nil, finish: nil)
|
2021-06-07 12:10:00 +00:00
|
|
|
Gitlab::Usage::Metrics::NameSuggestion.for(:count, column: column, relation: relation)
|
2021-03-05 18:09:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def distinct_count(relation, column = nil, batch: true, batch_size: nil, start: nil, finish: nil)
|
2021-06-07 12:10:00 +00:00
|
|
|
Gitlab::Usage::Metrics::NameSuggestion.for(:distinct_count, column: column, relation: relation)
|
2021-03-05 18:09:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def redis_usage_counter
|
2021-06-07 12:10:00 +00:00
|
|
|
Gitlab::Usage::Metrics::NameSuggestion.for(:redis)
|
2021-03-05 18:09:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def alt_usage_data(*)
|
2021-06-07 12:10:00 +00:00
|
|
|
Gitlab::Usage::Metrics::NameSuggestion.for(:alt)
|
2021-03-05 18:09:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def redis_usage_data_totals(counter)
|
2021-06-07 12:10:00 +00:00
|
|
|
counter.fallback_totals.transform_values { |_| Gitlab::Usage::Metrics::NameSuggestion.for(:redis) }
|
2021-03-05 18:09:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def sum(relation, column, *rest)
|
2021-06-07 12:10:00 +00:00
|
|
|
Gitlab::Usage::Metrics::NameSuggestion.for(:sum, column: column, relation: relation)
|
2021-03-05 18:09:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def estimate_batch_distinct_count(relation, column = nil, *rest)
|
2021-06-07 12:10:00 +00:00
|
|
|
Gitlab::Usage::Metrics::NameSuggestion.for(:estimate_batch_distinct_count, column: column, relation: relation)
|
2021-03-05 18:09:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def add(*args)
|
|
|
|
"add_#{args.join('_and_')}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|