Commit 93458a7b authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '343668-edit-work-item-title-redis-counter' into 'master'

Track work item title updates

See merge request gitlab-org/gitlab!80532
parents 8ac92c08 2a209c23
......@@ -160,6 +160,7 @@ module SystemNotes
body = "changed title from **#{marked_old_title}** to **#{marked_new_title}**"
issue_activity_counter.track_issue_title_changed_action(author: author) if noteable.is_a?(Issue)
work_item_activity_counter.track_work_item_title_changed_action(author: author) if noteable.is_a?(WorkItem)
create_note(NoteSummary.new(noteable, project, author, body, action: 'title'))
end
......@@ -484,6 +485,10 @@ module SystemNotes
Gitlab::UsageDataCounters::IssueActivityUniqueCounter
end
def work_item_activity_counter
Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter
end
def track_cross_reference_action
issue_activity_counter.track_issue_cross_referenced_action(author: author) if noteable.is_a?(Issue)
end
......
---
name: track_work_items_activity
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/80532
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/352903
milestone: '14.9'
type: development
group: group::project management
default_enabled: false
---
key_path: redis_hll_counters.work_items.users_updating_work_item_title_monthly
description: Unique users updating a work item's title
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/80532
time_frame: 28d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
options:
events:
- users_updating_work_item_title
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.work_items.users_updating_work_item_title_weekly
description: Unique users updating a work item's title
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/80532
time_frame: 7d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
options:
events:
- users_updating_work_item_title
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
- name: users_updating_work_item_title
category: work_items
redis_slot: users
aggregation: weekly
feature_flag: track_work_items_activity
# frozen_string_literal: true
module Gitlab
module UsageDataCounters
module WorkItemActivityUniqueCounter
WORK_ITEM_TITLE_CHANGED = 'users_updating_work_item_title'
class << self
def track_work_item_title_changed_action(author:)
track_unique_action(WORK_ITEM_TITLE_CHANGED, author)
end
private
def track_unique_action(action, author)
return unless author
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(action, values: author.id)
end
end
end
end
end
......@@ -50,7 +50,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
'importer',
'network_policies',
'geo',
'growth'
'growth',
'work_items'
)
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter, :clean_gitlab_redis_shared_state do
let(:user) { build(:user, id: 1) }
shared_examples 'counter that does not track the event' do
it 'does not track the event' do
expect { 3.times { track_event } }.to not_change {
Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(
event_names: event_name,
start_date: 2.weeks.ago,
end_date: 2.weeks.from_now
)
}
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 }
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,
start_date: 2.weeks.ago,
end_date: 2.weeks.from_now
)
}.by(1)
end
context 'when author is nil' do
let(:user) { nil }
it_behaves_like 'counter that does not track the event'
end
end
context 'when track_work_items_activity FF is disabled' do
before do
stub_feature_flags(track_work_items_activity: false)
end
it_behaves_like 'counter that does not track the event'
end
end
end
......@@ -23,6 +23,9 @@ RSpec.describe WorkItems::UpdateService do
it 'triggers issuable_title_updated graphql subscription' do
expect(GraphqlTriggers).to receive(:issuable_title_updated).with(work_item).and_call_original
expect(Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter).to receive(:track_work_item_title_changed_action).with(author: current_user)
# During the work item transition we also want to track work items as issues
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_title_changed_action)
update_work_item
end
......@@ -33,6 +36,7 @@ RSpec.describe WorkItems::UpdateService do
it 'does not trigger issuable_title_updated graphql subscription' do
expect(GraphqlTriggers).not_to receive(:issuable_title_updated)
expect(Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter).not_to receive(:track_work_item_title_changed_action)
update_work_item
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