Commit 68b1650f authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix timebox events to track only issue events

Also renames the hook to be more specific.
Also changes resource state event to make the hooks consistent.
parent 925ea029
...@@ -11,7 +11,7 @@ class ResourceStateEvent < ResourceEvent ...@@ -11,7 +11,7 @@ class ResourceStateEvent < ResourceEvent
# state is used for issue and merge request states. # state is used for issue and merge request states.
enum state: Issue.available_states.merge(MergeRequest.available_states).merge(reopened: 5) enum state: Issue.available_states.merge(MergeRequest.available_states).merge(reopened: 5)
after_save :usage_metrics after_create :issue_usage_metrics
def self.issuable_attrs def self.issuable_attrs
%i(issue merge_request).freeze %i(issue merge_request).freeze
...@@ -27,7 +27,7 @@ class ResourceStateEvent < ResourceEvent ...@@ -27,7 +27,7 @@ class ResourceStateEvent < ResourceEvent
private private
def usage_metrics def issue_usage_metrics
return unless for_issue? return unless for_issue?
case state case state
......
...@@ -13,7 +13,7 @@ class ResourceTimeboxEvent < ResourceEvent ...@@ -13,7 +13,7 @@ class ResourceTimeboxEvent < ResourceEvent
remove: 2 remove: 2
} }
after_save :usage_metrics after_create :issue_usage_metrics
def self.issuable_attrs def self.issuable_attrs
%i(issue merge_request).freeze %i(issue merge_request).freeze
...@@ -25,7 +25,13 @@ class ResourceTimeboxEvent < ResourceEvent ...@@ -25,7 +25,13 @@ class ResourceTimeboxEvent < ResourceEvent
private private
def usage_metrics def for_issue?
issue_id.present?
end
def issue_usage_metrics
return unless for_issue?
case self case self
when ResourceMilestoneEvent when ResourceMilestoneEvent
Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_milestone_changed_action(author: user) Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_milestone_changed_action(author: user)
......
...@@ -6,8 +6,10 @@ module EE ...@@ -6,8 +6,10 @@ module EE
private private
override :usage_metrics override :issue_usage_metrics
def usage_metrics def issue_usage_metrics
return unless for_issue?
case self case self
when ResourceIterationEvent when ResourceIterationEvent
::Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_iteration_changed_action(author: user) ::Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_iteration_changed_action(author: user)
......
...@@ -41,7 +41,7 @@ RSpec.describe ResourceStateEvent, type: :model do ...@@ -41,7 +41,7 @@ RSpec.describe ResourceStateEvent, type: :model do
end end
context 'callbacks' do context 'callbacks' do
describe '#usage_metrics' do describe '#issue_usage_metrics' do
it 'tracks closed issues' do it 'tracks closed issues' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_closed_action) expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_closed_action)
...@@ -53,6 +53,12 @@ RSpec.describe ResourceStateEvent, type: :model do ...@@ -53,6 +53,12 @@ RSpec.describe ResourceStateEvent, type: :model do
create(described_class.name.underscore.to_sym, issue: issue, state: described_class.states[:reopened]) create(described_class.name.underscore.to_sym, issue: issue, state: described_class.states[:reopened])
end end
it 'does not track merge requests' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_closed_action)
create(described_class.name.underscore.to_sym, merge_request: merge_request, state: described_class.states[:closed])
end
end end
end end
end end
...@@ -75,11 +75,17 @@ RSpec.shared_examples 'timebox resource event actions' do ...@@ -75,11 +75,17 @@ RSpec.shared_examples 'timebox resource event actions' do
end end
RSpec.shared_examples 'timebox resource tracks issue metrics' do |type| RSpec.shared_examples 'timebox resource tracks issue metrics' do |type|
describe '#usage_metrics' do describe '#issue_usage_metrics' do
it 'tracks usage' do it 'tracks usage for issues' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:"track_issue_#{type}_changed_action") expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:"track_issue_#{type}_changed_action")
create(described_class.name.underscore.to_sym, issue: create(:issue)) create(described_class.name.underscore.to_sym, issue: create(:issue))
end end
it 'does not track usage for merge requests' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:"track_issue_#{type}_changed_action")
create(described_class.name.underscore.to_sym, merge_request: create(:merge_request))
end
end end
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