Commit 078553cc authored by Alper Akgun's avatar Alper Akgun

Usage data usage_activity_by_stage feature updates

- Makes the `usage_ping_batch_counter` flag default enabled
- Makes the `usage_activity_by_stage` as the single toggle
- Removes additional ::Gitlab.com?
parent 2e08c928
......@@ -37,20 +37,11 @@ module EE
override :uncached_data
def uncached_data
# The `usage_activity_by_stage` queries are likely to time out on large instances, and are sure
# to time out on GitLab.com. Since we are mostly interested in gathering these statistics for
# self hosted instances, prevent them from running on GitLab.com and allow instance maintainers
# to disable them via a feature flag.
return super if (::Feature.disabled?(:usage_ping_batch_counter) && ::Gitlab.com?) ||
::Feature.disabled?(:usage_activity_by_stage, default_enabled: true)
if ::Feature.disabled?(:usage_activity_by_stage_monthly)
super.merge(usage_activity_by_stage)
else
time_period = { created_at: 28.days.ago..Time.current }
usage_activity_by_stage_monthly = usage_activity_by_stage(:usage_activity_by_stage_monthly, time_period)
super.merge(usage_activity_by_stage).merge(usage_activity_by_stage_monthly)
end
return super if ::Feature.disabled?(:usage_activity_by_stage, default_enabled: true)
time_period = { created_at: 28.days.ago..Time.current }
usage_activity_by_stage_monthly = usage_activity_by_stage(:usage_activity_by_stage_monthly, time_period)
super.merge(usage_activity_by_stage).merge(usage_activity_by_stage_monthly)
end
override :features_usage_data
......
......@@ -14,38 +14,6 @@ describe Gitlab::UsageData do
end
describe '.uncached_data' do
context 'when on Gitlab.com' do
before do
allow(Gitlab).to receive(:com?).and_return(true)
end
it "does #{'not' unless usage_ping_batch_counter_on} include usage_activity_by_stage data" do
expect(described_class.uncached_data.include?(:usage_activity_by_stage)).to be(usage_ping_batch_counter_on)
expect(described_class.uncached_data.include?(:usage_activity_by_stage_monthly)).to be(usage_ping_batch_counter_on)
end
context 'when feature is enabled' do
before do
stub_feature_flags(usage_activity_by_stage: true)
end
it "does #{'not' unless usage_ping_batch_counter_on} include usage_activity_by_stage data" do
expect(described_class.uncached_data.include?(:usage_activity_by_stage)).to be(usage_ping_batch_counter_on)
expect(described_class.uncached_data.include?(:usage_activity_by_stage_monthly)).to be(usage_ping_batch_counter_on)
end
context 'when the :usage_activity_by_stage_monthly feature is disabled' do
before do
stub_feature_flags(usage_activity_by_stage_monthly: false)
end
it "does not include usage_activity_by_stage data" do
expect(described_class.uncached_data.include?(:usage_activity_by_stage_monthly)).to be(false)
end
end
end
end
context 'when the :usage_activity_by_stage feature is not enabled' do
before do
stub_feature_flags(usage_activity_by_stage: false)
......@@ -57,7 +25,7 @@ describe Gitlab::UsageData do
end
end
context 'when not on Gitlab.com' do
context 'when the :usage_activity_by_stage feature is enabled' do
it 'includes usage_activity_by_stage data' do
expect(described_class.uncached_data).to include(:usage_activity_by_stage)
expect(described_class.uncached_data).to include(:usage_activity_by_stage_monthly)
......
......@@ -232,7 +232,7 @@ module Gitlab
end
def count(relation, column = nil, fallback: -1, batch: true)
if batch && Feature.enabled?(:usage_ping_batch_counter)
if batch && Feature.enabled?(:usage_ping_batch_counter, default_enabled: true)
Gitlab::Database::BatchCount.batch_count(relation, column)
else
relation.count
......@@ -242,7 +242,7 @@ module Gitlab
end
def distinct_count(relation, column = nil, fallback: -1, batch: true)
if batch && Feature.enabled?(:usage_ping_batch_counter)
if batch && Feature.enabled?(:usage_ping_batch_counter, default_enabled: true)
Gitlab::Database::BatchCount.batch_distinct_count(relation, column)
else
relation.distinct_count_by(column)
......
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