Commit 3279a270 authored by Mario de la Ossa's avatar Mario de la Ossa

Add UsageData for designs added/removed from issue

Adds three new UsageData unique events for Issue Designs:

- design added to issue
- design modified in issue
- design removed from issue
parent a8d50a38
......@@ -16,6 +16,7 @@ module DesignManagement
version = delete_designs!
EventCreateService.new.destroy_designs(designs, current_user)
Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_designs_removed_action(author: current_user)
success(version: version)
end
......
......@@ -66,7 +66,7 @@ module DesignManagement
action = new_file?(design) ? :create : :update
on_success do
::Gitlab::UsageDataCounters::DesignsCounter.count(action)
track_usage_metrics(action)
end
DesignManagement::DesignAction.new(design, action, content)
......@@ -128,6 +128,16 @@ module DesignManagement
end
end
end
def track_usage_metrics(action)
if action == :update
::Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_designs_modified_action(author: current_user)
else
::Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_designs_added_action(author: current_user)
end
::Gitlab::UsageDataCounters::DesignsCounter.count(action)
end
end
end
......
---
title: Added UsageData metrics for Issue designs' usage
merge_request: 44373
author:
type: added
......@@ -27,6 +27,9 @@ module Gitlab
ISSUE_ADDED_TO_EPIC = 'g_project_management_issue_added_to_epic'
ISSUE_REMOVED_FROM_EPIC = 'g_project_management_issue_removed_from_epic'
ISSUE_CHANGED_EPIC = 'g_project_management_issue_changed_epic'
ISSUE_DESIGNS_ADDED = 'g_project_management_issue_designs_added'
ISSUE_DESIGNS_MODIFIED = 'g_project_management_issue_designs_modified'
ISSUE_DESIGNS_REMOVED = 'g_project_management_issue_designs_removed'
class << self
def track_issue_created_action(author:, time: Time.zone.now)
......@@ -117,6 +120,18 @@ module Gitlab
track_unique_action(ISSUE_CHANGED_EPIC, author, time)
end
def track_issue_designs_added_action(author:, time: Time.zone.now)
track_unique_action(ISSUE_DESIGNS_ADDED, author, time)
end
def track_issue_designs_modified_action(author:, time: Time.zone.now)
track_unique_action(ISSUE_DESIGNS_MODIFIED, author, time)
end
def track_issue_designs_removed_action(author:, time: Time.zone.now)
track_unique_action(ISSUE_DESIGNS_REMOVED, author, time)
end
private
def track_unique_action(action, author, time)
......
......@@ -279,3 +279,15 @@
category: issues_edit
redis_slot: project_management
aggregation: daily
- name: g_project_management_issue_designs_added
category: issues_edit
redis_slot: project_management
aggregation: daily
- name: g_project_management_issue_designs_modified
category: issues_edit
redis_slot: project_management
aggregation: daily
- name: g_project_management_issue_designs_removed
category: issues_edit
redis_slot: project_management
aggregation: daily
......@@ -232,6 +232,36 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
end
context 'for Issue designs added actions' do
it_behaves_like 'tracks and counts action' do
let(:action) { described_class::ISSUE_DESIGNS_ADDED }
def track_action(params)
described_class.track_issue_designs_added_action(**params)
end
end
end
context 'for Issue designs modified actions' do
it_behaves_like 'tracks and counts action' do
let(:action) { described_class::ISSUE_DESIGNS_MODIFIED }
def track_action(params)
described_class.track_issue_designs_modified_action(**params)
end
end
end
context 'for Issue designs removed actions' do
it_behaves_like 'tracks and counts action' do
let(:action) { described_class::ISSUE_DESIGNS_REMOVED }
def track_action(params)
described_class.track_issue_designs_removed_action(**params)
end
end
end
it 'can return the count of actions per user deduplicated', :aggregate_failures do
described_class.track_issue_title_changed_action(author: user1)
described_class.track_issue_description_changed_action(author: user1)
......
......@@ -80,6 +80,16 @@ RSpec.describe DesignManagement::DeleteDesignsService do
expect { run_service rescue nil }
.not_to change { [counter.totals, Event.count] }
end
it 'does not log any UsageData metrics' do
redis_hll = ::Gitlab::UsageDataCounters::HLLRedisCounter
event = Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_DESIGNS_REMOVED
expect { run_service rescue nil }
.not_to change { redis_hll.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }
run_service rescue nil
end
end
context 'one design is passed' do
......@@ -98,6 +108,12 @@ RSpec.describe DesignManagement::DeleteDesignsService do
expect { run_service }.to change { counter.read(:delete) }.by(1)
end
it 'updates UsageData for removed designs' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_designs_removed_action).with(author: user)
run_service
end
it 'creates an event in the activity stream' do
expect { run_service }
.to change { Event.count }.by(1)
......
......@@ -102,9 +102,11 @@ RSpec.describe DesignManagement::SaveDesignsService do
end
end
it 'creates a commit, an event in the activity stream and updates the creation count' do
it 'creates a commit, an event in the activity stream and updates the creation count', :aggregate_failures do
counter = Gitlab::UsageDataCounters::DesignsCounter
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_designs_added_action).with(author: user)
expect { run_service }
.to change { Event.count }.by(1)
.and change { Event.for_design.created_action.count }.by(1)
......@@ -190,6 +192,12 @@ RSpec.describe DesignManagement::SaveDesignsService do
expect(updated_designs.first.versions.size).to eq(2)
end
it 'updates UsageData for changed designs' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_designs_modified_action).with(author: user)
run_service
end
it 'records the correct events' do
counter = Gitlab::UsageDataCounters::DesignsCounter
expect { run_service }
......
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