Commit f99218fb authored by Mikolaj Wawrzyniak's avatar Mikolaj Wawrzyniak

Add metric name suggestion generator

parent 7fbb521a
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module NamesSuggestions
class Generator < ::Gitlab::UsageData
class << self
def generate(key_path)
uncached_data.deep_stringify_keys.dig(*key_path.split('.'))
end
private
def count(relation, column = nil, batch: true, batch_size: nil, start: nil, finish: nil)
"count_#{parse_target_and_source(column, relation)}"
end
def distinct_count(relation, column = nil, batch: true, batch_size: nil, start: nil, finish: nil)
"count_distinct_#{parse_target_and_source(column, relation)}"
end
def redis_usage_counter
"names_suggestions_for_redis_counters_are_not_supported_yet"
end
def redis_usage_data_totals(counter)
counter.fallback_totals.transform_values { |_| "names_suggestions_for_redis_counters_are_not_supported_yet" }
end
def sum(relation, column, *rest)
"sum_#{parse_target_and_source(column, relation)}"
end
def estimate_batch_distinct_count(relation, column = nil, *rest)
"estimate_distinct_#{parse_target_and_source(column, relation)}"
end
def add(*args)
"add_#{args.join('_and_')}"
end
def parse_target_and_source(column, relation)
if column
"#{column}_from_#{relation.table_name}"
else
relation.table_name
end
end
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::Generator do
describe '#generate' do
context 'for count metrics' do
it 'return correct name' do
expect(described_class.generate('counts.boards')).to eq 'count_boards'
end
end
context 'for count distinct metrics' do
it 'return correct name' do
expect(described_class.generate('counts.issues_using_zoom_quick_actions')).to eq 'count_distinct_issue_id_from_zoom_meetings'
end
end
context 'for sum metrics' do
it 'return correct name' do
expect(described_class.generate('counts.jira_imports_total_imported_issues_count')).to eq 'sum_imported_issues_count_from_jira_imports'
end
end
context 'for add metrics' do
it 'return correct name' do
expect(described_class.generate('counts.snippets')).to eq 'add_count_snippets_and_count_snippets'
end
end
context 'for redis metrics' do
it 'return correct name' do
expect(described_class.generate('analytics_unique_visits.analytics_unique_visits_for_any_target')).to eq 'names_suggestions_for_redis_counters_are_not_supported_yet'
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment