Commit 03f16a82 authored by Tan Le's avatar Tan Le

Track audit event searches via Snowplow

On relevant page load, a search action will be triggered and we'd like
to capture that event to report on usages and improve our audit event
offerings. The audit event searches are via a full page reload, hence we
will use the backend code to track this action.
parent 64239221
......@@ -2,6 +2,7 @@
class ProfilesController < Profiles::ApplicationController
include ActionView::Helpers::SanitizeHelper
include Gitlab::Tracking
before_action :user
before_action :authorize_change_username!, only: :update_username
......@@ -65,6 +66,8 @@ class ProfilesController < Profiles::ApplicationController
@events = AuditEvent.where(entity_type: "User", entity_id: current_user.id)
.order("created_at DESC")
.page(params[:page])
Gitlab::Tracking.event(self.class.name, 'search_audit_event')
end
# rubocop: enable CodeReuse/ActiveRecord
......
---
title: Track audit event searches via Snowplow
merge_request: 44888
author:
type: other
......@@ -7,6 +7,7 @@ class Admin::AuditLogsController < Admin::ApplicationController
include AuditEvents::Sortable
include AuditEvents::DateRange
include Analytics::UniqueVisitsHelper
include Gitlab::Tracking
before_action :check_license_admin_audit_log_available!
......@@ -30,6 +31,8 @@ class Admin::AuditLogsController < Admin::ApplicationController
else
nil
end
Gitlab::Tracking.event(self.class.name, 'search_audit_event')
end
private
......
......@@ -20,6 +20,8 @@ class Groups::AuditEventsController < Groups::ApplicationController
def index
@is_last_page = events.last_page?
@events = AuditEventSerializer.new.represent(events)
Gitlab::Tracking.event(self.class.name, 'search_audit_event')
end
private
......
......@@ -18,6 +18,8 @@ class Projects::AuditEventsController < Projects::ApplicationController
def index
@is_last_page = events.last_page?
@events = AuditEventSerializer.new.represent(events)
Gitlab::Tracking.event(self.class.name, 'search_audit_event')
end
private
......
......@@ -32,6 +32,15 @@ RSpec.describe Admin::AuditLogsController do
let(:request_params) { { 'entity_type': 'User' } }
let(:target_id) { 'i_compliance_audit_events' }
end
it 'tracks search event', :snowplow do
get :index
expect_snowplow_event(
category: 'Admin::AuditLogsController',
action: 'search_audit_event'
)
end
end
end
end
......@@ -128,6 +128,15 @@ RSpec.describe Groups::AuditEventsController do
expect(serializer).to have_received(:represent).with(kind_of(Kaminari::PaginatableWithoutCount))
end
end
it 'tracks search event', :snowplow do
request
expect_snowplow_event(
category: 'Groups::AuditEventsController',
action: 'search_audit_event'
)
end
end
end
......
......@@ -140,6 +140,15 @@ RSpec.describe Projects::AuditEventsController do
expect(response).to have_gitlab_http_status(:not_found)
end
end
it 'tracks search event', :snowplow do
request
expect_snowplow_event(
category: 'Projects::AuditEventsController',
action: 'search_audit_event'
)
end
end
context 'unauthorized' do
......
......@@ -101,6 +101,19 @@ RSpec.describe ProfilesController, :request_store do
end
end
describe 'GET audit_log' do
it 'tracks search event', :snowplow do
sign_in(user)
get :audit_log
expect_snowplow_event(
category: 'ProfilesController',
action: 'search_audit_event'
)
end
end
describe 'PUT update_username' do
let(:namespace) { user.namespace }
let(:gitlab_shell) { Gitlab::Shell.new }
......
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