Commit 1711cbd5 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch '346046-track-work-item-created' into 'master'

Track users creating work items

See merge request gitlab-org/gitlab!81201
parents 2bd2984c a46d1706
......@@ -7,4 +7,12 @@ class WorkItem < Issue
def noteable_target_type_name
'issue'
end
private
def record_create_action
super
Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter.track_work_item_created_action(author: author)
end
end
---
key_path: redis_hll_counters.work_items.users_creating_work_items_monthly
description: Unique users creating work items
product_category: team planning
product_section: dev
product_stage: plan
product_group: group::project management
value_type: number
status: active
milestone: '14.9'
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81201
time_frame: 28d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
options:
events:
- users_creating_work_items
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.work_items.users_creating_work_items_weekly
description: Unique users creating work items
product_category: team planning
product_section: dev
product_stage: plan
product_group: group::project management
value_type: number
status: active
milestone: '14.9'
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81201
time_frame: 7d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
options:
events:
- users_creating_work_items
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
......@@ -4,3 +4,8 @@
redis_slot: users
aggregation: weekly
feature_flag: track_work_items_activity
- name: users_creating_work_items
category: work_items
redis_slot: users
aggregation: weekly
feature_flag: track_work_items_activity
......@@ -3,9 +3,14 @@
module Gitlab
module UsageDataCounters
module WorkItemActivityUniqueCounter
WORK_ITEM_CREATED = 'users_creating_work_items'
WORK_ITEM_TITLE_CHANGED = 'users_updating_work_item_title'
class << self
def track_work_item_created_action(author:)
track_unique_action(WORK_ITEM_CREATED, author)
end
def track_work_item_title_changed_action(author:)
track_unique_action(WORK_ITEM_TITLE_CHANGED, author)
end
......
......@@ -17,16 +17,12 @@ RSpec.describe Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter, :clean_
end
end
describe '.track_work_item_title_changed_action' do
subject(:track_event) { described_class.track_work_item_title_changed_action(author: user) }
let(:event_name) { described_class::WORK_ITEM_TITLE_CHANGED }
shared_examples 'work item unique counter' do
context 'when track_work_items_activity FF is enabled' do
it 'tracks a unique event only once' do
expect { 3.times { track_event } }.to change {
Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(
event_names: described_class::WORK_ITEM_TITLE_CHANGED,
event_names: event_name,
start_date: 2.weeks.ago,
end_date: 2.weeks.from_now
)
......@@ -48,4 +44,20 @@ RSpec.describe Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter, :clean_
it_behaves_like 'counter that does not track the event'
end
end
describe '.track_work_item_created_action' do
subject(:track_event) { described_class.track_work_item_created_action(author: user) }
let(:event_name) { described_class::WORK_ITEM_CREATED }
it_behaves_like 'work item unique counter'
end
describe '.track_work_item_title_changed_action' do
subject(:track_event) { described_class.track_work_item_title_changed_action(author: user) }
let(:event_name) { described_class::WORK_ITEM_TITLE_CHANGED }
it_behaves_like 'work item unique counter'
end
end
......@@ -10,4 +10,16 @@ RSpec.describe WorkItem do
expect(work_item.noteable_target_type_name).to eq('issue')
end
end
describe 'callbacks' do
describe 'record_create_action' do
it 'records the creation action after saving' do
expect(Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter).to receive(:track_work_item_created_action)
# During the work item transition we also want to track work items as issues
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_created_action)
create(:work_item)
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