Commit a18bc97b authored by Alex Ives's avatar Alex Ives

Add geo secondary web user usage ping

- Added a migration that adds index to resource_owner_id
- Added section to usage_data for enablement

Relates to: https://gitlab.com/gitlab-org/gitlab/-/issues/273134Co-authored-by: default avatarAlishan Ladhani <aladhani@gitlab.com>
parent 779878fd
---
title: Add usage ping for web users of geo secondaries
merge_request: 46278
author:
type: added
# frozen_string_literal: true
class AddIndexToOauthAccessGrantsResourceOwnerId < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_oauth_access_grants_on_resource_owner_id'
disable_ddl_transaction!
def up
add_concurrent_index :oauth_access_grants, %i[resource_owner_id application_id created_at], name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :oauth_access_grants, INDEX_NAME
end
end
c269a999cabce99d26f3be303656bbb27f2b843b639755b112ad350d4cb5b5c6
\ No newline at end of file
......@@ -21162,6 +21162,8 @@ CREATE INDEX index_notification_settings_on_user_id ON notification_settings USI
CREATE UNIQUE INDEX index_notifications_on_user_id_and_source_id_and_source_type ON notification_settings USING btree (user_id, source_id, source_type);
CREATE INDEX index_oauth_access_grants_on_resource_owner_id ON oauth_access_grants USING btree (resource_owner_id, application_id, created_at);
CREATE UNIQUE INDEX index_oauth_access_grants_on_token ON oauth_access_grants USING btree (token);
CREATE INDEX index_oauth_access_tokens_on_application_id ON oauth_access_tokens USING btree (application_id);
......
......@@ -274,6 +274,22 @@ module EE
}, approval_rules_counts)
end
override :usage_activity_by_stage_enablement
def usage_activity_by_stage_enablement(time_period)
return super unless ::Gitlab::Geo.enabled?
super.merge({
geo_secondary_web_oauth_users: distinct_count(
OauthAccessGrant
.where(time_period)
.where(
application_id: GeoNode.secondary_nodes.select(:oauth_application_id)
),
:resource_owner_id
)
})
end
# Omitted because no user, creator or author associated: `campaigns_imported_from_github`, `ldap_group_links`
override :usage_activity_by_stage_manage
def usage_activity_by_stage_manage(time_period)
......
......@@ -374,6 +374,22 @@ RSpec.describe Gitlab::UsageData do
end
end
describe 'usage_data_by_stage_enablement' do
it 'returns empty hash if geo is not enabled' do
expect(described_class.usage_activity_by_stage_enablement({})).to eq({})
end
it 'excludes data outside of the date range' do
create_list(:geo_node, 2).each do |node|
for_defined_days_back do
create(:oauth_access_grant, application: node.oauth_application)
end
end
expect(described_class.usage_activity_by_stage_enablement(described_class.last_28_days_time_period)).to eq(geo_secondary_web_oauth_users: 2)
end
end
describe 'usage_activity_by_stage_manage' do
it 'includes accurate usage_activity_by_stage data' do
stub_config(
......
......@@ -521,6 +521,7 @@ module Gitlab
key => {
configure: usage_activity_by_stage_configure(time_period),
create: usage_activity_by_stage_create(time_period),
enablement: usage_activity_by_stage_enablement(time_period),
manage: usage_activity_by_stage_manage(time_period),
monitor: usage_activity_by_stage_monitor(time_period),
package: usage_activity_by_stage_package(time_period),
......@@ -576,6 +577,11 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
# Empty placeholder allows this to match the pattern used by other sections
def usage_activity_by_stage_enablement(time_period)
{}
end
# Omitted because no user, creator or author associated: `campaigns_imported_from_github`, `ldap_group_links`
# rubocop: disable CodeReuse/ActiveRecord
def usage_activity_by_stage_manage(time_period)
......
......@@ -50,3 +50,4 @@ UsageData/DistinctCountByLargeForeignKey:
- 'owner_id'
- 'project_id'
- 'user_id'
- 'resource_owner_id'
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