Commit 1f835de1 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'ali/remove-snowplow-api-helper' into 'master'

Remove snowplow API helper

See merge request gitlab-org/gitlab!56267
parents be5fab5b c57eda43
......@@ -36,7 +36,7 @@ module API
get ':id/dependencies' do
authorize! :read_dependencies, user_project
track_event('view_dependencies')
::Gitlab::Tracking.event(self.options[:for].name, 'view_dependencies')
dependency_params = declared_params(include_missing: false).merge(project: user_project)
dependencies = dependencies_by(dependency_params)
......
......@@ -62,7 +62,7 @@ module API
authorize_upload!(project)
bad_request!('File is too large') if max_file_size_exceeded?
track_event('push_package')
::Gitlab::Tracking.event(self.options[:for].name, 'push_package')
create_package_file_params = declared_params.merge(build: current_authenticated_job)
::Packages::Generic::CreatePackageFileService
......@@ -94,7 +94,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!
track_event('pull_package')
::Gitlab::Tracking.event(self.options[:for].name, 'pull_package')
present_carrierwave_file!(package_file.file)
end
......
......@@ -544,17 +544,6 @@ module API
end
end
def track_event(action = action_name, **args)
category = args.delete(:category) || self.options[:for].name
raise "invalid category" unless category
::Gitlab::Tracking.event(category, action.to_s, **args)
rescue => error
Gitlab::AppLogger.warn(
"Tracking event failed for action: #{action}, category: #{category}, message: #{error.message}"
)
end
def increment_counter(event_name)
feature_name = "usage_data_#{event_name}"
return unless Feature.enabled?(feature_name)
......
......@@ -10,7 +10,7 @@ module API
def redirect_registry_request(forward_to_registry, package_type, options)
if forward_to_registry && redirect_registry_request_available?
track_event("#{package_type}_request_forward")
::Gitlab::Tracking.event(self.options[:for].name, "#{package_type}_request_forward")
redirect(registry_url(package_type, options))
else
yield
......
......@@ -50,7 +50,8 @@ module API
def track_package_event(event_name, scope, **args)
::Packages::CreateEventService.new(nil, current_user, event_name: event_name, scope: scope).execute
track_event(event_name, **args)
category = args.delete(:category) || self.options[:for].name
::Gitlab::Tracking.event(category, event_name.to_s, **args)
end
end
end
......
......@@ -12,6 +12,10 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do
subject { helper.redirect_registry_request(forward_to_registry, package_type, options) { helper.fallback } }
before do
allow(helper).to receive(:options).and_return(for: API::NpmInstancePackages)
end
shared_examples 'executing fallback' do
it 'redirects to package registry' do
expect(helper).to receive(:registry_url).never
......@@ -23,13 +27,14 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do
end
shared_examples 'executing redirect' do
it 'redirects to package registry' do
expect(helper).to receive(:track_event).with('npm_request_forward').once
it 'redirects to package registry', :snowplow do
expect(helper).to receive(:registry_url).once
expect(helper).to receive(:redirect).once
expect(helper).to receive(:fallback).never
subject
expect_snowplow_event(category: 'API::NpmInstancePackages', action: 'npm_request_forward')
end
end
......@@ -64,7 +69,6 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do
let(:package_type) { pkg_type }
it 'raises an error' do
allow(helper).to receive(:track_event)
expect { subject }.to raise_error(ArgumentError, "Can't build registry_url for package_type #{package_type}")
end
end
......
......@@ -175,20 +175,6 @@ RSpec.describe API::Helpers do
end
end
describe '#track_event' do
it "creates a gitlab tracking event", :snowplow do
subject.track_event('my_event', category: 'foo')
expect_snowplow_event(category: 'foo', action: 'my_event')
end
it "logs an exception" do
expect(Gitlab::AppLogger).to receive(:warn).with(/Tracking event failed/)
subject.track_event('my_event', category: nil)
end
end
describe '#increment_unique_values' do
let(:value) { '9f302fea-f828-4ca9-aef4-e10bd723c0b3' }
let(:event_name) { 'g_compliance_dashboard' }
......
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