Commit 95263a0e authored by Ash McKenzie's avatar Ash McKenzie Committed by Alex Buijs

New usage_activity_by_stage for UsageData

Focusing on Manage
parent 3ff1f8a3
......@@ -13,6 +13,13 @@ module EE
super + [::Gitlab::UsageCounters::DesignsCounter]
end
override :uncached_data
def uncached_data
return super unless ::Feature.enabled?(:usage_activity_by_stage, default_enabled: true)
super.merge(usage_activity_by_stage)
end
override :features_usage_data
def features_usage_data
super.merge(features_usage_data_ee)
......@@ -165,6 +172,22 @@ module EE
count(::Issue.authored(::User.alert_bot))
end
# Source: https://gitlab.com/gitlab-data/analytics/blob/master/transform/snowflake-dbt/data/ping_metrics_to_stage_mapping_data.csv
# rubocop: disable CodeReuse/ActiveRecord
def usage_activity_by_stage
{
usage_activity_by_stage: {
manage: {
groups: count(::GroupMember.distinct, count_by: :user_id),
ldap_group_links: -1, # no creator / user ID
ldap_keys: count(::LDAPKey.distinct, count_by: :user_id),
ldap_users: count(::GroupMember.distinct.of_ldap_type, count_by: :user_id)
}
}
}
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......
require 'spec_helper'
describe Gitlab::UsageData do
describe '.uncached_data' do
context 'when the :usage_activity_by_stage feaure is not enabled' do
it 'does not include usage_activity_by_stage data' do
stub_feature_flags(usage_activity_by_stage: false)
expect(described_class.uncached_data).not_to include(:usage_activity_by_stage)
end
end
context 'when the :usage_activity_by_stage feaure is enabled' do
before do
stub_feature_flags(usage_activity_by_stage: true)
end
it 'includes usage_activity_by_stage data' do
expect(described_class.uncached_data).to include(:usage_activity_by_stage)
end
context 'for manage' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user)
create(:group_member, user: user)
create(:key, type: 'LDAPKey', user: user)
create(:group_member, ldap: true, user: user)
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to eq(groups: 1, ldap_group_links: -1, ldap_keys: 1, ldap_users: 1)
end
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