Commit bd0d49d5 authored by Felipe Artur's avatar Felipe Artur Committed by Matthias Käppler

Track epic destroy event on usage ping

Record epic destroy event on usage ping
parent 99b2ae9c
......@@ -4,18 +4,26 @@ module Issuable
class DestroyService < IssuableBaseService
def execute(issuable)
if issuable.destroy
delete_todos(issuable)
issuable.update_project_counter_caches
issuable.assignees.each(&:invalidate_cache_counts)
after_destroy(issuable)
end
end
private
def after_destroy(issuable)
delete_todos(issuable)
issuable.update_project_counter_caches
issuable.assignees.each(&:invalidate_cache_counts)
end
def group_for(issuable)
issuable.resource_parent
end
def delete_todos(issuable)
actor = issuable.is_a?(Epic) ? issuable.resource_parent : issuable.resource_parent.group
group = group_for(issuable)
if Feature.enabled?(:destroy_issuable_todos_async, actor, default_enabled: :yaml)
if Feature.enabled?(:destroy_issuable_todos_async, group, default_enabled: :yaml)
TodosDestroyer::DestroyedIssuableWorker
.perform_async(issuable.id, issuable.class.name)
else
......@@ -26,3 +34,5 @@ module Issuable
end
end
end
Issuable::DestroyService.prepend_if_ee('EE::Issuable::DestroyService')
......@@ -9872,6 +9872,30 @@ Status: `data_available`
Tiers: `premium`, `ultimate`
### `redis_hll_counters.epics_usage.g_project_management_epic_destroyed_monthly`
Count of MAU destroying epics
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/config/metrics/counts_28d/20210413174710_g_project_management_epic_destroyed_monthly.yml)
Group: `group::product planning`
Status: `implemented`
Tiers: `premium`, `ultimate`
### `redis_hll_counters.epics_usage.g_project_management_epic_destroyed_weekly`
Count of WAU destroying epics
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/config/metrics/counts_7d/20210413174449_g_project_management_epic_destroyed_weekly.yml)
Group: `group::product planning`
Status: `implemented`
Tiers: `premium`, `ultimate`
### `redis_hll_counters.epics_usage.g_project_management_epic_issue_added_monthly`
Count of MAU adding issues to epics
......
# frozen_string_literal: true
module EE
module Issuable
module DestroyService
extend ::Gitlab::Utils::Override
private
override :after_destroy
def after_destroy(issuable)
track_usage_ping_epic_destroyed if issuable.is_a?(Epic)
super
end
override :group_for
def group_for(issuable)
return issuable.resource_parent if issuable.is_a?(Epic)
super
end
def track_usage_ping_epic_destroyed
::Gitlab::UsageDataCounters::EpicActivityUniqueCounter.track_epic_destroyed(author: current_user)
end
end
end
end
---
title: Track epic destroyed action on usage ping
merge_request: 59185
author:
type: other
---
# Name of this metric contains g_project_management prefix
# because we are using the same slot from issue_tracking to
# allow data aggregation.
key_path: redis_hll_counters.epics_usage.g_project_management_epic_destroyed_monthly
description: Count of MAU destroying epics
product_section: dev
product_stage: plan
product_group: group::product planning
product_category: epics_usage
value_type: number
status: implemented
milestone: "13.11"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/59185
time_frame: 28d
data_source: redis_hll
distribution:
- ee
tier:
- premium
- ultimate
---
# Name of this metric contains g_project_management prefix
# because we are using the same slot from issue_tracking to
# allow data aggregation.
key_path: redis_hll_counters.epics_usage.g_project_management_epic_destroyed_weekly
description: Count of WAU destroying epics
product_section: dev
product_stage: plan
product_group: group::product planning
product_category: epics_usage
value_type: number
status: implemented
milestone: "13.11"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/59185
time_frame: 7d
data_source: redis_hll
distribution:
- ee
tier:
- premium
- ultimate
......@@ -28,6 +28,7 @@ module Gitlab
EPIC_CONFIDENTIAL = 'g_project_management_users_setting_epic_confidential'
EPIC_VISIBLE = 'g_project_management_users_setting_epic_visible'
EPIC_LABELS = 'g_project_management_epic_users_changing_labels'
EPIC_DESTROYED = 'g_project_management_epic_destroyed'
class << self
def track_epic_created_action(author:)
......@@ -114,6 +115,10 @@ module Gitlab
track_unique_action(EPIC_LABELS, author)
end
def track_epic_destroyed(author:)
track_unique_action(EPIC_DESTROYED, author)
end
private
def track_unique_action(action, author)
......
......@@ -257,4 +257,16 @@ RSpec.describe Gitlab::UsageDataCounters::EpicActivityUniqueCounter, :clean_gitl
it_behaves_like 'does not track when feature flag is disabled', :track_epics_activity
end
context 'for destroying epic' do
def track_action(params)
described_class.track_epic_destroyed(**params)
end
it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::ISSUE_EPIC_DESTROYED }
end
it_behaves_like 'does not track when feature flag is disabled', :track_epics_activity
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Issuable::DestroyService do
let_it_be(:user) { create(:user) }
subject(:service) { described_class.new(nil, user) }
describe '#execute' do
context 'when destroying an epic' do
let(:issuable) { create(:epic) }
it 'records usage ping epic destroy event' do
expect(Gitlab::UsageDataCounters::EpicActivityUniqueCounter).to receive(:track_epic_destroyed).with(author: user)
subject.execute(issuable)
end
end
context 'when destroying other issuable type' do
let(:issuable) { create(:issue) }
it 'does not track usage ping epic destroy event' do
expect(Gitlab::UsageDataCounters::EpicActivityUniqueCounter).not_to receive(:track_epic_destroyed)
subject.execute(issuable)
end
end
end
end
......@@ -134,3 +134,9 @@
redis_slot: project_management
aggregation: daily
feature_flag: track_epics_activity
- name: g_project_management_epic_destroyed
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