Commit 857cdee0 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'mwaw/metric_names_suggestions_tweaks' into 'master'

Remove time frame constraint from name suggestion

See merge request gitlab-org/gitlab!58091
parents ef7523d9 623613ad
......@@ -67,7 +67,7 @@ module Gitlab
def metric_name_suggestion
return unless Feature.enabled?(:product_intelligence_metrics_names_suggestions, default_enabled: :yaml)
"\nname: #{Usage::Metrics::NamesSuggestions::Generator.generate(key_path)}"
"\nname: \"#{Usage::Metrics::NamesSuggestions::Generator.generate(key_path)}\""
end
def file_path
......
......@@ -6,6 +6,7 @@ module Gitlab
module NamesSuggestions
class Generator < ::Gitlab::UsageData
FREE_TEXT_METRIC_NAME = "<please fill metric name>"
REDIS_EVENT_METRIC_NAME = "<please fill metric name, suggested format is: {subject}_{verb}{ing|ed}_{object} eg: users_creating_epics or merge_requests_viewed_in_single_file_mode>"
CONSTRAINTS_PROMPT_TEMPLATE = "<adjective describing: '%{constraints}'>"
class << self
......@@ -24,7 +25,7 @@ module Gitlab
end
def redis_usage_counter
FREE_TEXT_METRIC_NAME
REDIS_EVENT_METRIC_NAME
end
def alt_usage_data(*)
......@@ -32,7 +33,7 @@ module Gitlab
end
def redis_usage_data_totals(counter)
counter.fallback_totals.transform_values { |_| FREE_TEXT_METRIC_NAME}
counter.fallback_totals.transform_values { |_| REDIS_EVENT_METRIC_NAME }
end
def sum(relation, column, *rest)
......@@ -48,6 +49,10 @@ module Gitlab
end
def name_suggestion(relation:, column: nil, prefix: nil, distinct: nil)
# rubocop: disable CodeReuse/ActiveRecord
relation = relation.unscope(where: :created_at)
# rubocop: enable CodeReuse/ActiveRecord
parts = [prefix]
arel_column = arelize_column(relation, column)
......@@ -81,7 +86,7 @@ module Gitlab
parts << actual_source
parts += process_joined_relations(actual_source, arel, relation, constraints)
parts.compact.join('_')
parts.compact.join('_').delete('"')
end
def append_constraints_prompt(target, constraints, parts)
......
......@@ -60,6 +60,15 @@ RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::Generator do
end
end
context 'strips off time period constraint' do
it_behaves_like 'name suggestion' do
# corresponding metric is collected with distinct_count(::Clusters::Cluster.aws_installed.enabled.where(time_period), :user_id)
let(:key_path) { 'usage_activity_by_stage_monthly.configure.clusters_platforms_eks' }
let(:constraints) { /<adjective describing\: '\(clusters.provider_type = \d+ AND \(cluster_providers_aws\.status IN \(\d+\)\) AND clusters\.enabled = TRUE\)'>/ }
let(:name_suggestion) { /count_distinct_user_id_from_#{constraints}_clusters_<with>_#{constraints}_cluster_providers_aws/ }
end
end
context 'for sum metrics' do
it_behaves_like 'name suggestion' do
# corresponding metric is collected with sum(JiraImportState.finished, :imported_issues_count)
......@@ -80,7 +89,7 @@ RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::Generator do
it_behaves_like 'name suggestion' do
# corresponding metric is collected with redis_usage_data { unique_visit_service.unique_visits_for(targets: :analytics) }
let(:key_path) { 'analytics_unique_visits.analytics_unique_visits_for_any_target' }
let(:name_suggestion) { /<please fill metric name>/ }
let(:name_suggestion) { /<please fill metric name, suggested format is: {subject}_{verb}{ing|ed}_{object} eg: users_creating_epics or merge_requests_viewed_in_single_file_mode>/ }
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