Commit e8e02887 authored by Mikolaj Wawrzyniak's avatar Mikolaj Wawrzyniak Committed by Alper Akgun

Change manage events metric counter method

Underlying relation 'events' for
usage_activity_by_stage_monthly.manage.events has to many records
which cause ordinary batch counter to reject query due to surpassed
limits. Estimated batch counter has higher max limits, so
replacing ordinary batch counter with estimated one should address
the problem

Changelog: fixed
parent 7d567806
......@@ -536,7 +536,9 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def usage_activity_by_stage_manage(time_period)
{
events: distinct_count(::Event.where(time_period), :author_id),
# rubocop: disable UsageData/LargeTable
events: estimate_batch_distinct_count(::Event.where(time_period), :author_id),
# rubocop: enable UsageData/LargeTable
groups: distinct_count(::GroupMember.where(time_period), :user_id),
users_created: count(::User.where(time_period), start: minimum_id(User), finish: maximum_id(User)),
omniauth_providers: filtered_omniauth_provider_names.reject { |name| name == 'group_saml' },
......
......@@ -193,6 +193,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
describe 'usage_activity_by_stage_manage' do
let_it_be(:error_rate) { Gitlab::Database::PostgresHll::BatchDistinctCounter::ERROR_RATE }
it 'includes accurate usage_activity_by_stage data' do
stub_config(
omniauth:
......@@ -213,14 +215,14 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
expect(described_class.usage_activity_by_stage_manage({})).to include(
events: 2,
events: be_within(error_rate).percent_of(2),
groups: 2,
users_created: 6,
omniauth_providers: ['google_oauth2'],
user_auth_by_provider: { 'group_saml' => 2, 'ldap' => 4, 'standard' => 0, 'two-factor' => 0, 'two-factor-via-u2f-device' => 0, "two-factor-via-webauthn-device" => 0 }
)
expect(described_class.usage_activity_by_stage_manage(described_class.monthly_time_range_db_params)).to include(
events: 1,
events: be_within(error_rate).percent_of(1),
groups: 1,
users_created: 3,
omniauth_providers: ['google_oauth2'],
......
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