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