Commit 61d0cc96 authored by Rajendra Kadam's avatar Rajendra Kadam

Add user, project and namespace in snowplow event tracking

This MR adds user, project and namespace to tracking calls
and sends information to StandardContext class and updates specs
parent e1cd303d
......@@ -18,7 +18,7 @@ class Groups::AuditEventsController < Groups::ApplicationController
@is_last_page = events.last_page?
@events = AuditEventSerializer.new.represent(events)
Gitlab::Tracking.event(self.class.name, 'search_audit_event')
Gitlab::Tracking.event(self.class.name, 'search_audit_event', user: current_user, namespace: group)
end
private
......
......@@ -17,7 +17,7 @@ class Projects::AuditEventsController < Projects::ApplicationController
@is_last_page = events.last_page?
@events = AuditEventSerializer.new.represent(events)
Gitlab::Tracking.event(self.class.name, 'search_audit_event')
Gitlab::Tracking.event(self.class.name, 'search_audit_event', user: current_user, project: project, namespace: project.namespace)
end
private
......
......@@ -36,7 +36,7 @@ module API
get ':id/dependencies' do
authorize! :read_dependencies, user_project
::Gitlab::Tracking.event(self.options[:for].name, 'view_dependencies')
::Gitlab::Tracking.event(self.options[:for].name, 'view_dependencies', project: user_project, user: current_user, namespace: user_project.namespace)
dependency_params = declared_params(include_missing: false).merge(project: user_project)
dependencies = dependencies_by(dependency_params)
......
......@@ -134,7 +134,9 @@ RSpec.describe Groups::AuditEventsController do
expect_snowplow_event(
category: 'Groups::AuditEventsController',
action: 'search_audit_event'
action: 'search_audit_event',
user: owner,
namespace: group
)
end
end
......
......@@ -146,7 +146,10 @@ RSpec.describe Projects::AuditEventsController do
expect_snowplow_event(
category: 'Projects::AuditEventsController',
action: 'search_audit_event'
action: 'search_audit_event',
project: project,
user: maintainer,
namespace: project.namespace
)
end
end
......
......@@ -10,6 +10,7 @@ RSpec.describe API::Dependencies do
subject(:request) { get api("/projects/#{project.id}/dependencies", user), params: params }
let(:params) { {} }
let(:snowplow_standard_context_params) { { user: user, project: project, namespace: project.namespace } }
before do
stub_licensed_features(dependency_scanning: true, security_dashboard: true)
......
......@@ -255,7 +255,7 @@ module API
delete do
authorize!(:destroy_package, project)
track_package_event('delete_package', :conan, category: 'API::ConanPackages')
track_package_event('delete_package', :conan, category: 'API::ConanPackages', user: current_user, project: project, namespace: project.namespace)
package.destroy
end
......
......@@ -62,7 +62,7 @@ module API
authorize_upload!(project)
bad_request!('File is too large') if max_file_size_exceeded?
::Gitlab::Tracking.event(self.options[:for].name, 'push_package')
::Gitlab::Tracking.event(self.options[:for].name, 'push_package', user: current_user, project: project, namespace: project.namespace)
create_package_file_params = declared_params.merge(build: current_authenticated_job)
::Packages::Generic::CreatePackageFileService
......@@ -96,7 +96,7 @@ module API
package = ::Packages::Generic::PackageFinder.new(project).execute!(params[:package_name], params[:package_version])
package_file = ::Packages::PackageFileFinder.new(package, params[:file_name]).execute!
::Gitlab::Tracking.event(self.options[:for].name, 'pull_package')
::Gitlab::Tracking.event(self.options[:for].name, 'pull_package', user: current_user, project: project, namespace: project.namespace)
present_carrierwave_file!(package_file.file)
end
......
......@@ -155,7 +155,7 @@ module API
conan_package_reference: params[:conan_package_reference]
).execute!
track_package_event('pull_package', :conan, category: 'API::ConanPackages') if params[:file_name] == ::Packages::Conan::FileMetadatum::PACKAGE_BINARY
track_package_event('pull_package', :conan, category: 'API::ConanPackages', user: current_user, project: project, namespace: project.namespace) if params[:file_name] == ::Packages::Conan::FileMetadatum::PACKAGE_BINARY
present_carrierwave_file!(package_file.file)
end
......@@ -170,7 +170,7 @@ module API
def track_push_package_event
if params[:file_name] == ::Packages::Conan::FileMetadatum::PACKAGE_BINARY && params[:file].size > 0 # rubocop: disable Style/ZeroLengthPredicate
track_package_event('push_package', :conan, category: 'API::ConanPackages')
track_package_event('push_package', :conan, category: 'API::ConanPackages', user: current_user, project: project, namespace: project.namespace)
end
end
......
......@@ -56,7 +56,7 @@ module Gitlab
return if dnt_enabled?
track_experiment_event_for(experiment_key, action, value, subject: subject) do |tracking_data|
::Gitlab::Tracking.event(tracking_data.delete(:category), tracking_data.delete(:action), **tracking_data)
::Gitlab::Tracking.event(tracking_data.delete(:category), tracking_data.delete(:action), **tracking_data.merge!(user: current_user))
end
end
......
......@@ -196,9 +196,12 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
end
describe '#track_experiment_event', :snowplow do
let(:user) { build(:user) }
context 'when the experiment is enabled' do
before do
stub_experiment(test_experiment: true)
allow(controller).to receive(:current_user).and_return(user)
end
context 'the user is part of the experimental group' do
......@@ -213,7 +216,8 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
category: 'Team',
action: 'start',
property: 'experimental_group',
value: 1
value: 1,
user: user
)
end
end
......@@ -230,7 +234,8 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
category: 'Team',
action: 'start',
property: 'control_group',
value: 1
value: 1,
user: user
)
end
end
......@@ -247,7 +252,8 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
category: 'Team',
action: 'start',
property: 'control_group',
value: 1
value: 1,
user: user
)
end
end
......@@ -280,7 +286,8 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
action: 'start',
property: 'control_group',
value: 1,
label: Digest::MD5.hexdigest('abc')
label: Digest::MD5.hexdigest('abc'),
user: user
)
end
......@@ -294,7 +301,8 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
action: 'start',
property: 'control_group',
value: 1,
label: Digest::MD5.hexdigest('somestring')
label: Digest::MD5.hexdigest('somestring'),
user: user
)
end
end
......@@ -313,7 +321,8 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
action: 'start',
property: 'control_group',
value: 1,
label: cookies.permanent.signed[:experimentation_subject_id]
label: cookies.permanent.signed[:experimentation_subject_id],
user: user
)
end
end
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe API::ConanInstancePackages do
let(:snowplow_standard_context_params) { { user: user, project: project, namespace: project.namespace } }
include_context 'conan api setup'
describe 'GET /api/v4/packages/conan/v1/ping' do
......
......@@ -19,6 +19,7 @@ RSpec.describe API::GenericPackages do
let(:user) { personal_access_token.user }
let(:ci_build) { create(:ci_build, :running, user: user, project: project) }
let(:snowplow_standard_context_params) { { user: user, project: project, namespace: project.namespace } }
def auth_header
return {} if user_role == :anonymous
......
......@@ -4,6 +4,6 @@ RSpec.shared_examples 'a gitlab tracking event' do |category, action|
it "creates a gitlab tracking event #{action}", :snowplow do
subject
expect_snowplow_event(category: category, action: action)
expect_snowplow_event(category: category, action: action, **snowplow_standard_context_params)
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