Commit b405f8d4 authored by Stan Hu's avatar Stan Hu

Merge branch 'fj-rename-track-unique-actions' into 'master'

Rename TrackUniqueActions to TrackUniqueEvents

See merge request gitlab-org/gitlab!39946
parents 5807d890 7a78f64c
......@@ -109,7 +109,7 @@ class EventCreateService
def wiki_event(wiki_page_meta, author, action, fingerprint)
raise IllegalActionError, action unless Event::WIKI_ACTIONS.include?(action)
Gitlab::UsageDataCounters::TrackUniqueActions.track_event(event_action: action, event_target: wiki_page_meta.class, author_id: author.id)
Gitlab::UsageDataCounters::TrackUniqueEvents.track_event(event_action: action, event_target: wiki_page_meta.class, author_id: author.id)
duplicate = Event.for_wiki_meta(wiki_page_meta).for_fingerprint(fingerprint).first
return duplicate if duplicate.present?
......@@ -154,7 +154,7 @@ class EventCreateService
result = Event.insert_all(attribute_sets, returning: %w[id])
tuples.each do |record, status, _|
Gitlab::UsageDataCounters::TrackUniqueActions.track_event(event_action: status, event_target: record.class, author_id: current_user.id)
Gitlab::UsageDataCounters::TrackUniqueEvents.track_event(event_action: status, event_target: record.class, author_id: current_user.id)
end
result
......@@ -172,7 +172,7 @@ class EventCreateService
new_event
end
Gitlab::UsageDataCounters::TrackUniqueActions.track_event(event_action: :pushed, event_target: Project, author_id: current_user.id)
Gitlab::UsageDataCounters::TrackUniqueEvents.track_event(event_action: :pushed, event_target: Project, author_id: current_user.id)
Users::LastPushEventService.new(current_user)
.cache_last_push_event(event)
......
......@@ -236,7 +236,7 @@ Recommendations:
Examples of implementation:
- [`Gitlab::UsageDataCounters::TrackUniqueActions`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/usage_data_counters/track_unique_actions.rb)
- [`Gitlab::UsageDataCounters::TrackUniqueEvents`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/usage_data_counters/track_unique_actions.rb)
- [`Gitlab::Analytics::UniqueVisits`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/analytics/unique_visits.rb)
Example of usage:
......@@ -247,10 +247,10 @@ redis_usage_data(Gitlab::UsageDataCounters::WikiPageCounter)
redis_usage_data { ::Gitlab::UsageCounters::PodLogs.usage_totals[:total] }
# Redis HLL counter
counter = Gitlab::UsageDataCounters::TrackUniqueActions
counter = Gitlab::UsageDataCounters::TrackUniqueEvents
redis_usage_data do
counter.count_unique_events(
event_action: Gitlab::UsageDataCounters::TrackUniqueActions::PUSH_ACTION,
event_action: Gitlab::UsageDataCounters::TrackUniqueEvents::PUSH_ACTION,
date_from: time_period[:created_at].first,
date_to: time_period[:created_at].last
)
......
......@@ -604,27 +604,27 @@ module Gitlab
end
def action_monthly_active_users(time_period)
counter = Gitlab::UsageDataCounters::TrackUniqueActions
counter = Gitlab::UsageDataCounters::TrackUniqueEvents
project_count = redis_usage_data do
counter.count_unique(
event_action: Gitlab::UsageDataCounters::TrackUniqueActions::PUSH_ACTION,
counter.count_unique_events(
event_action: Gitlab::UsageDataCounters::TrackUniqueEvents::PUSH_ACTION,
date_from: time_period[:created_at].first,
date_to: time_period[:created_at].last
)
end
design_count = redis_usage_data do
counter.count_unique(
event_action: Gitlab::UsageDataCounters::TrackUniqueActions::DESIGN_ACTION,
counter.count_unique_events(
event_action: Gitlab::UsageDataCounters::TrackUniqueEvents::DESIGN_ACTION,
date_from: time_period[:created_at].first,
date_to: time_period[:created_at].last
)
end
wiki_count = redis_usage_data do
counter.count_unique(
event_action: Gitlab::UsageDataCounters::TrackUniqueActions::WIKI_ACTION,
counter.count_unique_events(
event_action: Gitlab::UsageDataCounters::TrackUniqueEvents::WIKI_ACTION,
date_from: time_period[:created_at].first,
date_to: time_period[:created_at].last
)
......
......@@ -2,7 +2,7 @@
module Gitlab
module UsageDataCounters
module TrackUniqueActions
module TrackUniqueEvents
KEY_EXPIRY_LENGTH = 29.days
WIKI_ACTION = :wiki_action
......@@ -38,7 +38,7 @@ module Gitlab
Gitlab::Redis::HLL.add(key: target_key, value: author_id, expiry: KEY_EXPIRY_LENGTH)
end
def count_unique(event_action:, date_from:, date_to:)
def count_unique_events(event_action:, date_from:, date_to:)
keys = (date_from.to_date..date_to.to_date).map { |date| key(event_action, date) }
Gitlab::Redis::HLL.count(keys: keys)
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redis_shared_state do
RSpec.describe Gitlab::UsageDataCounters::TrackUniqueEvents, :clean_gitlab_redis_shared_state do
subject(:track_unique_events) { described_class }
let(:time) { Time.zone.now }
......@@ -12,7 +12,7 @@ RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redi
end
def count_unique(params)
track_unique_events.count_unique(params)
track_unique_events.count_unique_events(params)
end
context 'tracking an event' do
......
......@@ -912,7 +912,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
let(:time) { Time.zone.now }
before do
counter = Gitlab::UsageDataCounters::TrackUniqueActions
counter = Gitlab::UsageDataCounters::TrackUniqueEvents
project = Event::TARGET_TYPES[:project]
wiki = Event::TARGET_TYPES[:wiki]
design = Event::TARGET_TYPES[:design]
......
......@@ -202,11 +202,11 @@ RSpec.describe EventCreateService do
end
it 'records the event in the event counter' do
counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
counter_class = Gitlab::UsageDataCounters::TrackUniqueEvents
tracking_params = { event_action: counter_class::WIKI_ACTION, date_from: Date.yesterday, date_to: Date.today }
expect { create_event }
.to change { counter_class.count_unique(tracking_params) }
.to change { counter_class.count_unique_events(tracking_params) }
.by(1)
end
end
......@@ -243,11 +243,11 @@ RSpec.describe EventCreateService do
it_behaves_like 'service for creating a push event', PushEventPayloadService
it 'records the event in the event counter' do
counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
counter_class = Gitlab::UsageDataCounters::TrackUniqueEvents
tracking_params = { event_action: counter_class::PUSH_ACTION, date_from: Date.yesterday, date_to: Date.today }
expect { subject }
.to change { counter_class.count_unique(tracking_params) }
.to change { counter_class.count_unique_events(tracking_params) }
.from(0).to(1)
end
end
......@@ -266,11 +266,11 @@ RSpec.describe EventCreateService do
it_behaves_like 'service for creating a push event', BulkPushEventPayloadService
it 'records the event in the event counter' do
counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
counter_class = Gitlab::UsageDataCounters::TrackUniqueEvents
tracking_params = { event_action: counter_class::PUSH_ACTION, date_from: Date.yesterday, date_to: Date.today }
expect { subject }
.to change { counter_class.count_unique(tracking_params) }
.to change { counter_class.count_unique_events(tracking_params) }
.from(0).to(1)
end
end
......@@ -320,11 +320,11 @@ RSpec.describe EventCreateService do
end
it 'records the event in the event counter' do
counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
counter_class = Gitlab::UsageDataCounters::TrackUniqueEvents
tracking_params = { event_action: counter_class::DESIGN_ACTION, date_from: Date.yesterday, date_to: Date.today }
expect { result }
.to change { counter_class.count_unique(tracking_params) }
.to change { counter_class.count_unique_events(tracking_params) }
.from(0).to(1)
end
end
......@@ -347,11 +347,11 @@ RSpec.describe EventCreateService do
end
it 'records the event in the event counter' do
counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
counter_class = Gitlab::UsageDataCounters::TrackUniqueEvents
tracking_params = { event_action: counter_class::DESIGN_ACTION, date_from: Date.yesterday, date_to: Date.today }
expect { result }
.to change { counter_class.count_unique(tracking_params) }
.to change { counter_class.count_unique_events(tracking_params) }
.from(0).to(1)
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