Commit 54088ec6 authored by charlie ablett's avatar charlie ablett

Track epic create note via usage ping

- Add usage ping metrics files
- Organise all note creation tracking events in one place
parent a9f4517a
......@@ -75,16 +75,9 @@ module Notes
increment_usage_counter(note)
track_event(note, current_user)
if Feature.enabled?(:notes_create_service_tracking, project)
Gitlab::Tracking.event('Notes::CreateService', 'execute', **tracking_data_for(note))
end
if note.for_merge_request? && note.diff_note? && note.start_of_discussion?
Discussions::CaptureDiffNotePositionService.new(note.noteable, note.diff_file&.paths).execute(note.discussion)
end
track_note_creation_usage_for_issues(note) if note.for_issue?
track_note_creation_usage_for_merge_requests(note) if note.for_merge_request?
end
def do_commands(note, update_params, message, only_commands)
......@@ -111,6 +104,16 @@ module Notes
}
end
def track_event(note, user)
track_note_creation_usage_for_issues(note) if note.for_issue?
track_note_creation_usage_for_merge_requests(note) if note.for_merge_request?
track_usage_event(:incident_management_incident_comment, user.id) if note.for_issue? && note.noteable.incident?
if Feature.enabled?(:notes_create_service_tracking, project)
Gitlab::Tracking.event('Notes::CreateService', 'execute', **tracking_data_for(note))
end
end
def tracking_data_for(note)
label = Gitlab.ee? && note.author == User.visual_review_bot ? 'anonymous_visual_review_note' : 'note'
......@@ -120,12 +123,6 @@ module Notes
}
end
def track_event(note, user)
return unless note.noteable.is_a?(Issue) && note.noteable.incident?
track_usage_event(:incident_management_incident_comment, user.id)
end
def track_note_creation_usage_for_issues(note)
Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_comment_added_action(author: note.author)
end
......@@ -135,3 +132,5 @@ module Notes
end
end
end
Notes::CreateService.prepend_if_ee('EE::Notes::CreateService')
---
title: Track epic note created via usage ping
merge_request: 56609
author:
type: other
......@@ -9908,6 +9908,30 @@ Status: `implemented`
Tiers: `premium`, `ultimate`
### `redis_hll_counters.epics_usage.g_project_management_users_creating_epic_notes_monthly`
Counts of MAU adding epic notes
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/config/metrics/counts_28d/20210314215451_g_project_management_users_creating_epic_notes_monthly.yml)
Group: `group:product planning`
Status: `implemented`
Tiers: `premium`, `ultimate`
### `redis_hll_counters.epics_usage.g_project_management_users_creating_epic_notes_weekly`
Counts of WAU adding epic notes
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/config/metrics/counts_7d/20210314231518_g_project_management_users_creating_epic_notes_weekly.yml)
Group: `group:product planning`
Status: `implemented`
Tiers: `premium`, `ultimate`
### `redis_hll_counters.epics_usage.g_project_management_users_destroying_epic_notes_monthly`
Counts of MAU destroying epic notes
......
# frozen_string_literal: true
module EE
module Notes
module CreateService
extend ::Gitlab::Utils::Override
private
override :track_event
def track_event(note, user)
track_note_creation_usage_for_epics(user) if note.for_epic?
super(note, user)
end
def track_note_creation_usage_for_epics(user)
::Gitlab::UsageDataCounters::EpicActivityUniqueCounter.track_epic_note_created_action(author: user)
end
end
end
end
---
# 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_users_creating_epic_notes_monthly
description: Counts of MAU adding epic notes
product_section: dev
product_stage: plan
product_group: group:product planning
product_category: epics_usage
value_type: number
status: implemented
milestone: "13.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56609
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_users_creating_epic_notes_weekly
description: Counts of WAU adding epic notes
product_section: dev
product_stage: plan
product_group: group:product planning
product_category: epics_usage
value_type: number
status: implemented
milestone: "13.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56609
time_frame: 7d
data_source: redis_hll
distribution:
- ee
tier:
- premium
- ultimate
......@@ -8,6 +8,7 @@ module Gitlab
# slot of issue events to allow data aggregation.
# More information in: https://gitlab.com/gitlab-org/gitlab/-/issues/322405
EPIC_CREATED = 'g_project_management_epic_created'
EPIC_NOTE_CREATED = 'g_project_management_users_creating_epic_notes'
EPIC_NOTE_UPDATED = 'g_project_management_users_updating_epic_notes'
EPIC_NOTE_DESTROYED = 'g_project_management_users_destroying_epic_notes'
EPIC_START_DATE_SET_AS_FIXED = 'g_project_management_users_setting_epic_start_date_as_fixed'
......@@ -21,6 +22,10 @@ module Gitlab
track_unique_action(EPIC_CREATED, author, time)
end
def track_epic_note_created_action(author:, time: Time.zone.now)
track_unique_action(EPIC_NOTE_CREATED, author, time)
end
def track_epic_note_updated_action(author:, time: Time.zone.now)
track_unique_action(EPIC_NOTE_UPDATED, author, time)
end
......
......@@ -20,6 +20,18 @@ RSpec.describe Gitlab::UsageDataCounters::EpicActivityUniqueCounter, :clean_gitl
it_behaves_like 'does not track when feature flag is disabled', :track_epics_activity
end
context 'for epic note created event' do
def track_action(params)
described_class.track_epic_note_created_action(**params)
end
it_behaves_like 'a daily tracked issuable event' do
let(:action) { described_class::EPIC_NOTE_CREATED }
end
it_behaves_like 'does not track when feature flag is disabled', :track_epics_activity
end
context 'for epic note updated event' do
def track_action(params)
described_class.track_epic_note_updated_action(**params)
......
......@@ -7,6 +7,8 @@ RSpec.describe Notes::CreateService do
let(:project) { create(:project) }
let(:note_params) { opts }
let_it_be(:user) { create(:user) }
context 'for issues' do
let(:issuable) { create(:issue, project: project, weight: 10) }
let(:opts) { { noteable_type: 'Issue', noteable_id: issuable.id } }
......@@ -38,7 +40,6 @@ RSpec.describe Notes::CreateService do
context 'for merge_requests' do
let(:issuable) { create(:merge_request, project: project, source_project: project) }
let(:developer) { create(:user) }
let(:user) { create(:user) }
let(:opts) { { noteable_type: 'MergeRequest', noteable_id: issuable.id } }
it_behaves_like 'issuable quick actions' do
......@@ -59,5 +60,16 @@ RSpec.describe Notes::CreateService do
end
end
end
context 'for epics' do
let_it_be(:epic) { create(:epic) }
let(:opts) { { noteable_type: 'Epic', noteable_id: epic.id, note: "hello" } }
it 'tracks epic note creation' do
expect(::Gitlab::UsageDataCounters::EpicActivityUniqueCounter).to receive(:track_epic_note_created_action)
described_class.new(nil, user, opts).execute
end
end
end
end
......@@ -9,6 +9,12 @@
aggregation: daily
feature_flag: track_epics_activity
- name: g_project_management_users_creating_epic_notes
category: epics_usage
redis_slot: project_management
aggregation: daily
feature_flag: track_epics_activity
- name: g_project_management_users_updating_epic_notes
category: epics_usage
redis_slot: project_management
......
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