Commit 4b872ebc authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '210332-approximate-counters-are-not-working-on-gitlab-com' into 'master'

Move approximate counters to batch counting

See merge request gitlab-org/gitlab!27218
parents 8ca2d45a e9629b82
---
title: Use batch counters instead of approximate counters in usage data
merge_request: 27218
author:
type: performance
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
module Gitlab module Gitlab
class UsageData class UsageData
APPROXIMATE_COUNT_MODELS = [Label, MergeRequest, Note, Todo].freeze
BATCH_SIZE = 100 BATCH_SIZE = 100
class << self class << self
...@@ -107,10 +106,12 @@ module Gitlab ...@@ -107,10 +106,12 @@ module Gitlab
suggestions: count(Suggestion), suggestions: count(Suggestion),
todos: count(Todo), todos: count(Todo),
uploads: count(Upload), uploads: count(Upload),
web_hooks: count(WebHook) web_hooks: count(WebHook),
labels: count(Label),
merge_requests: count(MergeRequest),
notes: count(Note)
}.merge( }.merge(
services_usage, services_usage,
approximate_counts,
usage_counters, usage_counters,
user_preferences_usage, user_preferences_usage,
ingress_modsecurity_usage ingress_modsecurity_usage
...@@ -251,16 +252,6 @@ module Gitlab ...@@ -251,16 +252,6 @@ module Gitlab
fallback fallback
end end
def approximate_counts
approx_counts = Gitlab::Database::Count.approximate_counts(APPROXIMATE_COUNT_MODELS)
APPROXIMATE_COUNT_MODELS.each_with_object({}) do |model, result|
key = model.name.underscore.pluralize.to_sym
result[key] = approx_counts[model] || -1
end
end
def installation_type def installation_type
if Rails.env.production? if Rails.env.production?
Gitlab::INSTALLATION_TYPE Gitlab::INSTALLATION_TYPE
......
...@@ -387,29 +387,6 @@ describe Gitlab::UsageData do ...@@ -387,29 +387,6 @@ describe Gitlab::UsageData do
expect(described_class.count(relation, fallback: 15, batch: false)).to eq(15) expect(described_class.count(relation, fallback: 15, batch: false)).to eq(15)
end end
end end
describe '#approximate_counts' do
it 'gets approximate counts for selected models', :aggregate_failures do
create(:label)
expect(Gitlab::Database::Count).to receive(:approximate_counts)
.with(described_class::APPROXIMATE_COUNT_MODELS).once.and_call_original
counts = described_class.approximate_counts.values
expect(counts.count).to eq(described_class::APPROXIMATE_COUNT_MODELS.count)
expect(counts.any? { |count| count < 0 }).to be_falsey
end
it 'returns default values if counts can not be retrieved', :aggregate_failures do
described_class::APPROXIMATE_COUNT_MODELS.map do |model|
model.name.underscore.pluralize.to_sym
end
expect(Gitlab::Database::Count).to receive(:approximate_counts).and_return({})
expect(described_class.approximate_counts.values.uniq).to eq([-1])
end
end
end 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