From 60bd0a24f539217d760437e49e86c04e5c43498a Mon Sep 17 00:00:00 2001 From: Victor Zagorodny Date: Wed, 6 Feb 2019 19:56:16 +0200 Subject: [PATCH 1/2] Add user_preferences_usage to usage ping --- lib/gitlab/usage_data.rb | 9 ++++++++- spec/lib/gitlab/usage_data_spec.rb | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index 6bfcf83f388..4f70d6b689d 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -90,7 +90,10 @@ module Gitlab todos: count(Todo), uploads: count(Upload), web_hooks: count(WebHook) - }.merge(services_usage).merge(approximate_counts) + } + .merge(services_usage) + .merge(approximate_counts) + .merge(user_preferences: user_preferences_usage) } end # rubocop: enable CodeReuse/ActiveRecord @@ -159,6 +162,10 @@ module Gitlab } end + def user_preferences_usage + {} # augmented in EE + end + def count(relation, fallback: -1) relation.count rescue ActiveRecord::StatementInvalid diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 4f5993ba226..52edc46d5e4 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -124,6 +124,7 @@ describe Gitlab::UsageData do todos uploads web_hooks + user_preferences )) end From fa518963ec7a703ddb321533884a49c516a4acd7 Mon Sep 17 00:00:00 2001 From: Victor Zagorodny Date: Fri, 8 Feb 2019 13:22:11 +0200 Subject: [PATCH 2/2] Protect group overview usage ping w/ feature flag user_preferences key is includes into system usage data only if group_overview_security_dashboard feature flag is enabled; see https://gitlab.com/gitlab-org/gitlab-ee/issues/7048 --- lib/gitlab/usage_data.rb | 7 +++++-- spec/lib/gitlab/usage_data_spec.rb | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index 4f70d6b689d..a65f4a8639c 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -93,8 +93,11 @@ module Gitlab } .merge(services_usage) .merge(approximate_counts) - .merge(user_preferences: user_preferences_usage) - } + }.tap do |data| + if Feature.enabled?(:group_overview_security_dashboard) + data[:counts][:user_preferences] = user_preferences_usage + end + end end # rubocop: enable CodeReuse/ActiveRecord diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 52edc46d5e4..d3eae80cc56 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -128,6 +128,11 @@ describe Gitlab::UsageData do )) end + it 'does not gather user preferences usage data when the feature is disabled' do + stub_feature_flags(group_overview_security_dashboard: false) + expect(subject[:counts].keys).not_to include(:user_preferences) + end + it 'gathers projects data correctly' do count_data = subject[:counts]