Commit 8cb3edc3 authored by Felipe Artur's avatar Felipe Artur

Track linked epics removed on usage ping

Record linked epic removed on usage ping
and use RedisHLL for data aggregation.

Changelog: added
EE: true
parent 57c6d334
# frozen_string_literal: true
module Epics::RelatedEpicLinks::UsageDataHelper
ALLOWED_LINK_TYPES =
[
IssuableLink::TYPE_RELATES_TO,
IssuableLink::TYPE_BLOCKS,
IssuableLink::TYPE_IS_BLOCKED_BY
].freeze
ALLOWED_EVENT_TYPES = [:added, :removed].freeze
def track_related_epics_event_for(link_type:, event_type:)
return unless ALLOWED_LINK_TYPES.include?(link_type)
return unless ALLOWED_EVENT_TYPES.include?(event_type)
event_method_name = "track_linked_epic_with_type_#{link_type}_#{event_type}"
Gitlab::UsageDataCounters::EpicActivityUniqueCounter
.method(event_method_name)
.call(author: current_user)
end
end
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module Epics::RelatedEpicLinks module Epics::RelatedEpicLinks
class CreateService < IssuableLinks::CreateService class CreateService < IssuableLinks::CreateService
include UsageDataHelper
def linkable_issuables(epics) def linkable_issuables(epics)
@linkable_issuables ||= begin @linkable_issuables ||= begin
epics.select { |epic| can?(current_user, :admin_epic, epic) } epics.select { |epic| can?(current_user, :admin_epic, epic) }
...@@ -15,9 +17,7 @@ module Epics::RelatedEpicLinks ...@@ -15,9 +17,7 @@ module Epics::RelatedEpicLinks
private private
def after_create_for(link) def after_create_for(link)
if link.link_type == link.class::TYPE_RELATES_TO track_related_epics_event_for(link_type: params[:link_type], event_type: :added)
::Gitlab::UsageDataCounters::EpicActivityUniqueCounter.track_epic_related_added(author: current_user)
end
end end
def references(extractor) def references(extractor)
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
module Epics module Epics
module RelatedEpicLinks module RelatedEpicLinks
class DestroyService < ::IssuableLinks::DestroyService class DestroyService < ::IssuableLinks::DestroyService
include UsageDataHelper
private private
def permission_to_remove_relation? def permission_to_remove_relation?
...@@ -10,7 +12,7 @@ module Epics ...@@ -10,7 +12,7 @@ module Epics
end end
def track_event def track_event
# No op track_related_epics_event_for(link_type: link.link_type, event_type: :removed)
end end
def not_found_message def not_found_message
......
...@@ -45,6 +45,7 @@ options: ...@@ -45,6 +45,7 @@ options:
- g_project_management_epic_cross_referenced - g_project_management_epic_cross_referenced
- g_project_management_users_epic_issue_added_from_epic - g_project_management_users_epic_issue_added_from_epic
- g_project_management_epic_related_added - g_project_management_epic_related_added
- g_project_management_epic_related_removed
distribution: distribution:
- ee - ee
tier: tier:
......
---
key_path: redis_hll_counters.epics_usage.g_project_management_epic_related_removed_monthly
description: Count of MAU removing related epics
product_section: dev
product_stage: plan
product_group: group::product planning
product_category: epics_usage
value_type: number
status: active
milestone: "14.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/83547
time_frame: 28d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
options:
events:
- g_project_management_epic_related_removed
distribution:
- ee
tier:
- ultimate
...@@ -45,6 +45,7 @@ options: ...@@ -45,6 +45,7 @@ options:
- g_project_management_epic_cross_referenced - g_project_management_epic_cross_referenced
- g_project_management_users_epic_issue_added_from_epic - g_project_management_users_epic_issue_added_from_epic
- g_project_management_epic_related_added - g_project_management_epic_related_added
- g_project_management_epic_related_removed
distribution: distribution:
- ee - ee
tier: tier:
......
---
key_path: redis_hll_counters.epics_usage.g_project_management_epic_related_removed_weekly
description: Count of WAU removing related epics
product_section: dev
product_stage: plan
product_group: group::product planning
product_category: epics_usage
value_type: number
status: active
milestone: "14.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/83547
time_frame: 7d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
options:
events:
- g_project_management_epic_related_removed
distribution:
- ee
tier:
- ultimate
...@@ -36,6 +36,7 @@ module Gitlab ...@@ -36,6 +36,7 @@ module Gitlab
EPIC_TASK_UNCHECKED = 'project_management_users_unchecking_epic_task' EPIC_TASK_UNCHECKED = 'project_management_users_unchecking_epic_task'
EPIC_CROSS_REFERENCED = 'g_project_management_epic_cross_referenced' EPIC_CROSS_REFERENCED = 'g_project_management_epic_cross_referenced'
EPIC_RELATED_ADDED = 'g_project_management_epic_related_added' EPIC_RELATED_ADDED = 'g_project_management_epic_related_added'
EPIC_RELATED_REMOVED = 'g_project_management_epic_related_removed'
class << self class << self
def track_epic_created_action(author:) def track_epic_created_action(author:)
...@@ -150,10 +151,23 @@ module Gitlab ...@@ -150,10 +151,23 @@ module Gitlab
track_unique_action(EPIC_CROSS_REFERENCED, author) track_unique_action(EPIC_CROSS_REFERENCED, author)
end end
def track_epic_related_added(author:) def track_linked_epic_with_type_relates_to_added(author:)
track_unique_action(EPIC_RELATED_ADDED, author) track_unique_action(EPIC_RELATED_ADDED, author)
end end
def track_linked_epic_with_type_relates_to_removed(author:)
track_unique_action(EPIC_RELATED_REMOVED, author)
end
def track_linked_epic_with_type_blocks_added(author:)
end
def track_linked_epic_with_type_blocks_removed(author:)
end
def track_linked_epic_with_type_is_blocked_by_added(author:)
end
private private
def track_unique_action(action, author) def track_unique_action(action, author)
......
...@@ -340,7 +340,7 @@ RSpec.describe Gitlab::UsageDataCounters::EpicActivityUniqueCounter, :clean_gitl ...@@ -340,7 +340,7 @@ RSpec.describe Gitlab::UsageDataCounters::EpicActivityUniqueCounter, :clean_gitl
context 'for related epic added' do context 'for related epic added' do
def track_action(params) def track_action(params)
described_class.track_epic_related_added(**params) described_class.track_linked_epic_with_type_relates_to_added(**params)
end end
it_behaves_like 'a daily tracked issuable event' do it_behaves_like 'a daily tracked issuable event' do
...@@ -349,4 +349,16 @@ RSpec.describe Gitlab::UsageDataCounters::EpicActivityUniqueCounter, :clean_gitl ...@@ -349,4 +349,16 @@ RSpec.describe Gitlab::UsageDataCounters::EpicActivityUniqueCounter, :clean_gitl
it_behaves_like 'does not track when feature flag is disabled', :track_epics_activity it_behaves_like 'does not track when feature flag is disabled', :track_epics_activity
end end
context 'for related epic removed' do
def track_action(params)
described_class.track_linked_epic_with_type_relates_to_removed(**params)
end
it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::EPIC_RELATED_REMOVED }
end
it_behaves_like 'does not track when feature flag is disabled', :track_epics_activity
end
end end
...@@ -54,14 +54,14 @@ RSpec.describe Epics::RelatedEpicLinks::CreateService do ...@@ -54,14 +54,14 @@ RSpec.describe Epics::RelatedEpicLinks::CreateService do
end end
context 'event tracking' do context 'event tracking' do
context 'for related link type' do context 'for relates_to link type' do
it 'records event for each link created' do it 'records event for each link created' do
params = { params = {
link_type: IssuableLink::TYPE_RELATES_TO, link_type: IssuableLink::TYPE_RELATES_TO,
issuable_references: [issuable_a, issuable3].map { |epic| epic.to_reference(issuable.group, full: true) } issuable_references: [issuable_a, issuable3].map { |epic| epic.to_reference(issuable.group, full: true) }
} }
expect(Gitlab::UsageDataCounters::EpicActivityUniqueCounter).to receive(:track_epic_related_added).with(author: user).twice expect(Gitlab::UsageDataCounters::EpicActivityUniqueCounter).to receive(:track_linked_epic_with_type_relates_to_added).with(author: user).twice
described_class.new(issuable, user, params).execute described_class.new(issuable, user, params).execute
end end
......
...@@ -15,5 +15,21 @@ RSpec.describe Epics::RelatedEpicLinks::DestroyService do ...@@ -15,5 +15,21 @@ RSpec.describe Epics::RelatedEpicLinks::DestroyService do
subject { described_class.new(issuable_link, user).execute } subject { described_class.new(issuable_link, user).execute }
it_behaves_like 'a destroyable issuable link' it_behaves_like 'a destroyable issuable link'
context 'event tracking' do
before do
issuable_link.source.resource_parent.add_reporter(user)
issuable_link.target.resource_parent.add_reporter(user)
end
context 'for relates_to link type' do
it 'records event for related epic link destroyed' do
expect(Gitlab::UsageDataCounters::EpicActivityUniqueCounter)
.to receive(:track_linked_epic_with_type_relates_to_removed).with(author: user).once
subject
end
end
end
end end
end end
...@@ -194,3 +194,9 @@ ...@@ -194,3 +194,9 @@
redis_slot: project_management redis_slot: project_management
aggregation: daily aggregation: daily
feature_flag: track_epics_activity feature_flag: track_epics_activity
- name: g_project_management_epic_related_removed
category: epics_usage
redis_slot: project_management
aggregation: daily
feature_flag: track_epics_activity
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