Commit 179b4f81 authored by Michael Kozono's avatar Michael Kozono

Merge branch 'visual-review-api-tracking' into 'master'

Gitlab::Tracking data point for VisualReviewDiscussion API

Closes #11944

See merge request gitlab-org/gitlab!18890
parents 27fc442d 77e2072e
......@@ -42,6 +42,10 @@ module Notes
clear_noteable_diffs_cache(note)
Suggestions::CreateService.new(note).execute
increment_usage_counter(note)
if Feature.enabled?(:notes_create_service_tracking, project)
Gitlab::Tracking.event('Notes::CreateService', 'execute', tracking_data_for(note))
end
end
if quick_actions_service.commands_executed_count.to_i > 0
......@@ -59,5 +63,16 @@ module Notes
note
end
private
def tracking_data_for(note)
label = Gitlab.ee? && note.author == User.visual_review_bot ? 'anonymous_visual_review_note' : 'note'
{
label: label,
value: note.id
}
end
end
end
......@@ -22,6 +22,28 @@ describe API::VisualReviewDiscussions do
expect { request }.to change(merge_request.notes, :count).by(1)
end
it 'tracks a visual review feedback event' do
expect(Gitlab::Tracking).to receive(:event) do |category, action, data|
expect(category).to eq('Notes::CreateService')
expect(action).to eq('execute')
expect(data[:label]).to eq('anonymous_visual_review_note')
expect(data[:value]).to be_an(Integer)
end
request
end
context 'with notes_create_service_tracking feature flag disabled' do
before do
stub_feature_flags(notes_create_service_tracking: false)
end
it 'does not track any events' do
expect(Gitlab::Tracking).not_to receive(:event)
request
end
end
describe 'the API response' do
before do
request
......
......@@ -117,6 +117,29 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
expect(response).to have_gitlab_http_status(401)
end
it 'tracks a Notes::CreateService event' do
expect(Gitlab::Tracking).to receive(:event) do |category, action, data|
expect(category).to eq('Notes::CreateService')
expect(action).to eq('execute')
expect(data[:label]).to eq('note')
expect(data[:value]).to be_an(Integer)
end
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), params: { body: 'hi!' }
end
context 'with notes_create_service_tracking feature flag disabled' do
before do
stub_feature_flags(notes_create_service_tracking: false)
end
it 'does not track any events' do
expect(Gitlab::Tracking).not_to receive(:event)
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions"), params: { body: 'hi!' }
end
end
context 'when an admin or owner makes the request' do
it 'accepts the creation date to be set' do
creation_time = 2.weeks.ago
......
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