Add ide actions to Usage Data

parent 146c43c9
---
title: Add IDE edit actions to Usage Data
merge_request: 40939
author:
type: changed
...@@ -650,41 +650,37 @@ module Gitlab ...@@ -650,41 +650,37 @@ module Gitlab
end end
def action_monthly_active_users(time_period) def action_monthly_active_users(time_period)
counter = Gitlab::UsageDataCounters::TrackUniqueEvents date_range = { date_from: time_period[:created_at].first, date_to: time_period[:created_at].last }
project_count = redis_usage_data do event_monthly_active_users(date_range)
counter.count_unique_events( .merge!(ide_monthly_active_users(date_range))
event_action: Gitlab::UsageDataCounters::TrackUniqueEvents::PUSH_ACTION, end
date_from: time_period[:created_at].first,
date_to: time_period[:created_at].last
)
end
design_count = redis_usage_data do private
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 def event_monthly_active_users(date_range)
counter.count_unique_events( data = {
event_action: Gitlab::UsageDataCounters::TrackUniqueEvents::WIKI_ACTION, action_monthly_active_users_project_repo: Gitlab::UsageDataCounters::TrackUniqueEvents::PUSH_ACTION,
date_from: time_period[:created_at].first, action_monthly_active_users_design_management: Gitlab::UsageDataCounters::TrackUniqueEvents::DESIGN_ACTION,
date_to: time_period[:created_at].last action_monthly_active_users_wiki_repo: Gitlab::UsageDataCounters::TrackUniqueEvents::WIKI_ACTION
) }
data.each do |key, event|
data[key] = redis_usage_data { Gitlab::UsageDataCounters::TrackUniqueEvents.count_unique_events(event_action: event, **date_range) }
end end
end
def ide_monthly_active_users(date_range)
counter = Gitlab::UsageDataCounters::EditorUniqueCounter
{ {
action_monthly_active_users_project_repo: project_count, action_monthly_active_users_web_ide_edit: redis_usage_data { counter.count_web_ide_edit_actions(date_range) },
action_monthly_active_users_design_management: design_count, action_monthly_active_users_sfe_edit: redis_usage_data { counter.count_sfe_edit_actions(date_range) },
action_monthly_active_users_wiki_repo: wiki_count action_monthly_active_users_snippet_editor_edit: redis_usage_data { counter.count_snippet_editor_edit_actions(date_range) },
action_monthly_active_users_ide_edit: redis_usage_data { counter.count_edit_using_editor(date_range) }
} }
end end
private
def distinct_count_service_desk_enabled_projects(time_period) def distinct_count_service_desk_enabled_projects(time_period)
project_creator_id_start = user_minimum_id project_creator_id_start = user_minimum_id
project_creator_id_finish = user_maximum_id project_creator_id_finish = user_maximum_id
......
...@@ -999,6 +999,9 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -999,6 +999,9 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
describe '#action_monthly_active_users', :clean_gitlab_redis_shared_state do describe '#action_monthly_active_users', :clean_gitlab_redis_shared_state do
let(:time_period) { { created_at: 2.days.ago..time } } let(:time_period) { { created_at: 2.days.ago..time } }
let(:time) { Time.zone.now } let(:time) { Time.zone.now }
let(:user1) { build(:user, id: 1) }
let(:user2) { build(:user, id: 2) }
let(:user3) { build(:user, id: 3) }
before do before do
counter = Gitlab::UsageDataCounters::TrackUniqueEvents counter = Gitlab::UsageDataCounters::TrackUniqueEvents
...@@ -1014,6 +1017,20 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -1014,6 +1017,20 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
counter.track_event(event_action: :created, event_target: project, author_id: 5, time: time - 3.days) counter.track_event(event_action: :created, event_target: project, author_id: 5, time: time - 3.days)
counter.track_event(event_action: :created, event_target: wiki, author_id: 3) counter.track_event(event_action: :created, event_target: wiki, author_id: 3)
counter.track_event(event_action: :created, event_target: design, author_id: 3) counter.track_event(event_action: :created, event_target: design, author_id: 3)
counter = Gitlab::UsageDataCounters::EditorUniqueCounter
counter.track_web_ide_edit_action(author: user1)
counter.track_web_ide_edit_action(author: user1)
counter.track_sfe_edit_action(author: user1)
counter.track_snippet_editor_edit_action(author: user1)
counter.track_snippet_editor_edit_action(author: user1, time: time - 3.days)
counter.track_web_ide_edit_action(author: user2)
counter.track_sfe_edit_action(author: user2)
counter.track_web_ide_edit_action(author: user3, time: time - 3.days)
counter.track_snippet_editor_edit_action(author: user3)
end end
it 'returns the distinct count of user actions within the specified time period' do it 'returns the distinct count of user actions within the specified time period' do
...@@ -1021,7 +1038,11 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -1021,7 +1038,11 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
{ {
action_monthly_active_users_design_management: 1, action_monthly_active_users_design_management: 1,
action_monthly_active_users_project_repo: 3, action_monthly_active_users_project_repo: 3,
action_monthly_active_users_wiki_repo: 1 action_monthly_active_users_wiki_repo: 1,
action_monthly_active_users_web_ide_edit: 2,
action_monthly_active_users_sfe_edit: 2,
action_monthly_active_users_snippet_editor_edit: 2,
action_monthly_active_users_ide_edit: 3
} }
) )
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