Commit 62017483 authored by Mario de la Ossa's avatar Mario de la Ossa

Add issue changes to UsageData

Adds counters for the following actions to UsageData:
- title changed
- description changed
- assignee changed
- made confidential
- made visible
parent 8f027931
......@@ -44,6 +44,8 @@ module SystemNotes
def change_assignee(assignee)
body = assignee.nil? ? 'removed assignee' : "assigned to #{assignee.to_reference}"
issue_activity_counter.track_issue_assignee_changed_action(author: author) if noteable.is_a?(Issue)
create_note(NoteSummary.new(noteable, project, author, body, action: 'assignee'))
end
......@@ -74,6 +76,8 @@ module SystemNotes
body = text_parts.join(' and ')
issue_activity_counter.track_issue_assignee_changed_action(author: author) if noteable.is_a?(Issue)
create_note(NoteSummary.new(noteable, project, author, body, action: 'assignee'))
end
......@@ -96,6 +100,8 @@ 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)
create_note(NoteSummary.new(noteable, project, author, body, action: 'title'))
end
......@@ -113,6 +119,8 @@ module SystemNotes
def change_description
body = 'changed the description'
issue_activity_counter.track_issue_description_changed_action(author: author) if noteable.is_a?(Issue)
create_note(NoteSummary.new(noteable, project, author, body, action: 'description'))
end
......@@ -209,9 +217,13 @@ module SystemNotes
if noteable.confidential
body = 'made the issue confidential'
action = 'confidential'
issue_activity_counter.track_issue_made_confidential_action(author: author) if noteable.is_a?(Issue)
else
body = 'made the issue visible to everyone'
action = 'visible'
issue_activity_counter.track_issue_made_visible_action(author: author) if noteable.is_a?(Issue)
end
create_note(NoteSummary.new(noteable, project, author, body, action: action))
......@@ -353,6 +365,10 @@ module SystemNotes
noteable.respond_to?(:resource_state_events) &&
::Feature.enabled?(:track_resource_state_change_events, noteable.project, default_enabled: true)
end
def issue_activity_counter
Gitlab::UsageDataCounters::IssueActivityUniqueCounter
end
end
end
......
---
title: Add Issue actions to UsageData
merge_request: 40904
author:
type: other
---
name: track_issue_activity_actions
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40904
rollout_issue_url:
group: group::project_management
type: development
default_enabled: false
\ No newline at end of file
# frozen_string_literal: true
module Gitlab
module UsageDataCounters
module IssueActivityUniqueCounter
ISSUE_TITLE_CHANGED = 'g_project_management_issue_title_changed'
ISSUE_DESCRIPTION_CHANGED = 'g_project_management_issue_description_changed'
ISSUE_ASSIGNEE_CHANGED = 'g_project_management_issue_assignee_changed'
ISSUE_MADE_CONFIDENTIAL = 'g_project_management_issue_made_confidential'
ISSUE_MADE_VISIBLE = 'g_project_management_issue_made_visible'
ISSUE_CATEGORY = 'issues_edit'
class << self
def track_issue_title_changed_action(author:, time: Time.zone.now)
track_unique_action(ISSUE_TITLE_CHANGED, author, time)
end
def track_issue_description_changed_action(author:, time: Time.zone.now)
track_unique_action(ISSUE_DESCRIPTION_CHANGED, author, time)
end
def track_issue_assignee_changed_action(author:, time: Time.zone.now)
track_unique_action(ISSUE_ASSIGNEE_CHANGED, author, time)
end
def track_issue_made_confidential_action(author:, time: Time.zone.now)
track_unique_action(ISSUE_MADE_CONFIDENTIAL, author, time)
end
def track_issue_made_visible_action(author:, time: Time.zone.now)
track_unique_action(ISSUE_MADE_VISIBLE, author, time)
end
private
def track_unique_action(action, author, time)
return unless Feature.enabled?(:track_issue_activity_actions)
return unless author
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(author.id, action, time)
end
end
end
end
end
......@@ -173,3 +173,24 @@
redis_slot: incident_management
category: incident_management
aggregation: weekly
# Project Management group
- name: g_project_management_issue_title_changed
category: issues_edit
redis_slot: project_management
aggregation: daily
- name: g_project_management_issue_description_changed
category: issues_edit
redis_slot: project_management
aggregation: daily
- name: g_project_management_issue_assignee_changed
category: issues_edit
redis_slot: project_management
aggregation: daily
- name: g_project_management_issue_made_confidential
category: issues_edit
redis_slot: project_management
aggregation: daily
- name: g_project_management_issue_made_visible
category: issues_edit
redis_slot: project_management
aggregation: daily
......@@ -20,7 +20,7 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
describe '.categories' do
it 'gets all unique category names' do
expect(described_class.categories).to contain_exactly('analytics', 'compliance', 'ide_edit', 'search', 'source_code', 'incident_management')
expect(described_class.categories).to contain_exactly('analytics', 'compliance', 'ide_edit', 'search', 'source_code', 'incident_management', 'issues_edit')
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_gitlab_redis_shared_state do
let(:user1) { build(:user, id: 1) }
let(:user2) { build(:user, id: 2) }
let(:user3) { build(:user, id: 3) }
let(:time) { Time.zone.now }
shared_examples 'tracks and counts action' do
before do
stub_application_setting(usage_ping_enabled: true)
end
def count_unique(date_from:, date_to:)
Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: action, start_date: date_from, end_date: date_to)
end
specify do
aggregate_failures do
expect(track_action(author: user1)).to be_truthy
expect(track_action(author: user1)).to be_truthy
expect(track_action(author: user2)).to be_truthy
expect(track_action(author: user3, time: time - 3.days)).to be_truthy
expect(count_unique(date_from: time, date_to: time)).to eq(2)
expect(count_unique(date_from: time - 5.days, date_to: 1.day.since(time))).to eq(3)
end
end
it 'does not track edit actions if author is not present' do
expect(track_action(author: nil)).to be_nil
end
context 'when feature flag track_issue_activity_actions is disabled' do
it 'does not track edit actions' do
stub_feature_flags(track_issue_activity_actions: false)
expect(track_action(author: user1)).to be_nil
end
end
end
context 'for Issue title edit actions' do
it_behaves_like 'tracks and counts action' do
let(:action) { described_class::ISSUE_TITLE_CHANGED }
def track_action(params)
described_class.track_issue_title_changed_action(params)
end
end
end
context 'for Issue description edit actions' do
it_behaves_like 'tracks and counts action' do
let(:action) { described_class::ISSUE_DESCRIPTION_CHANGED }
def track_action(params)
described_class.track_issue_description_changed_action(params)
end
end
end
context 'for Issue assignee edit actions' do
it_behaves_like 'tracks and counts action' do
let(:action) { described_class::ISSUE_ASSIGNEE_CHANGED }
def track_action(params)
described_class.track_issue_assignee_changed_action(params)
end
end
end
context 'for Issue make confidential actions' do
it_behaves_like 'tracks and counts action' do
let(:action) { described_class::ISSUE_MADE_CONFIDENTIAL }
def track_action(params)
described_class.track_issue_made_confidential_action(params)
end
end
end
context 'for Issue make visible actions' do
it_behaves_like 'tracks and counts action' do
let(:action) { described_class::ISSUE_MADE_VISIBLE }
def track_action(params)
described_class.track_issue_made_visible_action(params)
end
end
end
it 'can return the count of actions per user deduplicated', :aggregate_failures do
described_class.track_issue_title_changed_action(author: user1)
described_class.track_issue_description_changed_action(author: user1)
described_class.track_issue_assignee_changed_action(author: user1)
described_class.track_issue_title_changed_action(author: user2, time: time - 2.days)
described_class.track_issue_title_changed_action(author: user3, time: time - 3.days)
described_class.track_issue_description_changed_action(author: user3, time: time - 3.days)
described_class.track_issue_assignee_changed_action(author: user3, time: time - 3.days)
events = Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category(described_class::ISSUE_CATEGORY)
today_count = Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: events, start_date: time, end_date: time)
week_count = Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: events, start_date: time - 5.days, end_date: 1.day.since(time))
expect(today_count).to eq(1)
expect(week_count).to eq(3)
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