Commit 9e6a125c authored by Patrick Bajao's avatar Patrick Bajao

Merge branch '238587-follow-up-from-add-basic-redis-hll-module' into 'master'

Rename _ids methods

Closes #238587

See merge request gitlab-org/gitlab!39964
parents 8db4eca6 a18af2ad
...@@ -14,23 +14,23 @@ module Gitlab ...@@ -14,23 +14,23 @@ module Gitlab
# @param [ActiveSupport::TimeWithZone] end_date end of time frame # @param [ActiveSupport::TimeWithZone] end_date end of time frame
# @return [Integer] number of unique visitors # @return [Integer] number of unique visitors
def unique_visits_for(targets:, start_date: 7.days.ago, end_date: start_date + 1.week) def unique_visits_for(targets:, start_date: 7.days.ago, end_date: start_date + 1.week)
target_ids = if targets == :analytics events = if targets == :analytics
self.class.analytics_ids self.class.analytics_events
elsif targets == :compliance elsif targets == :compliance
self.class.compliance_ids self.class.compliance_events
else else
Array(targets) Array(targets)
end end
Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: target_ids, start_date: start_date, end_date: end_date) Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: events, start_date: start_date, end_date: end_date)
end end
class << self class << self
def analytics_ids def analytics_events
Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('analytics') Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('analytics')
end end
def compliance_ids def compliance_events
Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('compliance') Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('compliance')
end end
end end
......
...@@ -589,8 +589,8 @@ module Gitlab ...@@ -589,8 +589,8 @@ module Gitlab
end end
def analytics_unique_visits_data def analytics_unique_visits_data
results = ::Gitlab::Analytics::UniqueVisits.analytics_ids.each_with_object({}) do |target_id, hash| results = ::Gitlab::Analytics::UniqueVisits.analytics_events.each_with_object({}) do |target, hash|
hash[target_id] = redis_usage_data { unique_visit_service.unique_visits_for(targets: target_id) } hash[target] = redis_usage_data { unique_visit_service.unique_visits_for(targets: target) }
end end
results['analytics_unique_visits_for_any_target'] = redis_usage_data { unique_visit_service.unique_visits_for(targets: :analytics) } results['analytics_unique_visits_for_any_target'] = redis_usage_data { unique_visit_service.unique_visits_for(targets: :analytics) }
results['analytics_unique_visits_for_any_target_monthly'] = redis_usage_data { unique_visit_service.unique_visits_for(targets: :analytics, start_date: 4.weeks.ago.to_date, end_date: Date.current) } results['analytics_unique_visits_for_any_target_monthly'] = redis_usage_data { unique_visit_service.unique_visits_for(targets: :analytics, start_date: 4.weeks.ago.to_date, end_date: Date.current) }
...@@ -599,8 +599,8 @@ module Gitlab ...@@ -599,8 +599,8 @@ module Gitlab
end end
def compliance_unique_visits_data def compliance_unique_visits_data
results = ::Gitlab::Analytics::UniqueVisits.compliance_ids.each_with_object({}) do |target_id, hash| results = ::Gitlab::Analytics::UniqueVisits.compliance_events.each_with_object({}) do |target, hash|
hash[target_id] = redis_usage_data { unique_visit_service.unique_visits_for(targets: target_id) } hash[target] = redis_usage_data { unique_visit_service.unique_visits_for(targets: target) }
end end
results['compliance_unique_visits_for_any_target'] = redis_usage_data { unique_visit_service.unique_visits_for(targets: :compliance) } results['compliance_unique_visits_for_any_target'] = redis_usage_data { unique_visit_service.unique_visits_for(targets: :compliance) }
results['compliance_unique_visits_for_any_target_monthly'] = redis_usage_data { unique_visit_service.unique_visits_for(targets: :compliance, start_date: 4.weeks.ago.to_date, end_date: Date.current) } results['compliance_unique_visits_for_any_target_monthly'] = redis_usage_data { unique_visit_service.unique_visits_for(targets: :compliance, start_date: 4.weeks.ago.to_date, end_date: Date.current) }
......
...@@ -960,8 +960,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -960,8 +960,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
subject { described_class.analytics_unique_visits_data } subject { described_class.analytics_unique_visits_data }
it 'returns the number of unique visits to pages with analytics features' do it 'returns the number of unique visits to pages with analytics features' do
::Gitlab::Analytics::UniqueVisits.analytics_ids.each do |target_id| ::Gitlab::Analytics::UniqueVisits.analytics_events.each do |target|
expect_any_instance_of(::Gitlab::Analytics::UniqueVisits).to receive(:unique_visits_for).with(targets: target_id).and_return(123) expect_any_instance_of(::Gitlab::Analytics::UniqueVisits).to receive(:unique_visits_for).with(targets: target).and_return(123)
end end
expect_any_instance_of(::Gitlab::Analytics::UniqueVisits).to receive(:unique_visits_for).with(targets: :analytics).and_return(543) expect_any_instance_of(::Gitlab::Analytics::UniqueVisits).to receive(:unique_visits_for).with(targets: :analytics).and_return(543)
...@@ -996,8 +996,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -996,8 +996,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
described_class.clear_memoization(:unique_visit_service) described_class.clear_memoization(:unique_visit_service)
allow_next_instance_of(::Gitlab::Analytics::UniqueVisits) do |instance| allow_next_instance_of(::Gitlab::Analytics::UniqueVisits) do |instance|
::Gitlab::Analytics::UniqueVisits.compliance_ids.each do |target_id| ::Gitlab::Analytics::UniqueVisits.compliance_events.each do |target|
allow(instance).to receive(:unique_visits_for).with(targets: target_id).and_return(123) allow(instance).to receive(:unique_visits_for).with(targets: target).and_return(123)
end end
allow(instance).to receive(:unique_visits_for).with(targets: :compliance).and_return(543) allow(instance).to receive(:unique_visits_for).with(targets: :compliance).and_return(543)
......
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