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 ...@@ -36,7 +36,7 @@ module API
get ':id/dependencies' do get ':id/dependencies' do
authorize! :read_dependencies, user_project 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) dependency_params = declared_params(include_missing: false).merge(project: user_project)
dependencies = dependencies_by(dependency_params) dependencies = dependencies_by(dependency_params)
......
...@@ -62,7 +62,7 @@ module API ...@@ -62,7 +62,7 @@ module API
authorize_upload!(project) authorize_upload!(project)
bad_request!('File is too large') if max_file_size_exceeded? 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) create_package_file_params = declared_params.merge(build: current_authenticated_job)
::Packages::Generic::CreatePackageFileService ::Packages::Generic::CreatePackageFileService
...@@ -94,7 +94,7 @@ module API ...@@ -94,7 +94,7 @@ module API
package = ::Packages::Generic::PackageFinder.new(project).execute!(params[:package_name], params[:package_version]) package = ::Packages::Generic::PackageFinder.new(project).execute!(params[:package_name], params[:package_version])
package_file = ::Packages::PackageFileFinder.new(package, params[:file_name]).execute! 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) present_carrierwave_file!(package_file.file)
end end
......
...@@ -544,17 +544,6 @@ module API ...@@ -544,17 +544,6 @@ module API
end end
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) def increment_counter(event_name)
feature_name = "usage_data_#{event_name}" feature_name = "usage_data_#{event_name}"
return unless Feature.enabled?(feature_name) return unless Feature.enabled?(feature_name)
......
...@@ -10,7 +10,7 @@ module API ...@@ -10,7 +10,7 @@ module API
def redirect_registry_request(forward_to_registry, package_type, options) def redirect_registry_request(forward_to_registry, package_type, options)
if forward_to_registry && redirect_registry_request_available? 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)) redirect(registry_url(package_type, options))
else else
yield yield
......
...@@ -50,7 +50,8 @@ module API ...@@ -50,7 +50,8 @@ module API
def track_package_event(event_name, scope, **args) def track_package_event(event_name, scope, **args)
::Packages::CreateEventService.new(nil, current_user, event_name: event_name, scope: scope).execute ::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 end
end end
......
...@@ -12,6 +12,10 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do ...@@ -12,6 +12,10 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do
subject { helper.redirect_registry_request(forward_to_registry, package_type, options) { helper.fallback } } 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 shared_examples 'executing fallback' do
it 'redirects to package registry' do it 'redirects to package registry' do
expect(helper).to receive(:registry_url).never expect(helper).to receive(:registry_url).never
...@@ -23,13 +27,14 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do ...@@ -23,13 +27,14 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do
end end
shared_examples 'executing redirect' do shared_examples 'executing redirect' do
it 'redirects to package registry' do it 'redirects to package registry', :snowplow do
expect(helper).to receive(:track_event).with('npm_request_forward').once
expect(helper).to receive(:registry_url).once expect(helper).to receive(:registry_url).once
expect(helper).to receive(:redirect).once expect(helper).to receive(:redirect).once
expect(helper).to receive(:fallback).never expect(helper).to receive(:fallback).never
subject subject
expect_snowplow_event(category: 'API::NpmInstancePackages', action: 'npm_request_forward')
end end
end end
...@@ -64,7 +69,6 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do ...@@ -64,7 +69,6 @@ RSpec.describe API::Helpers::Packages::DependencyProxyHelpers do
let(:package_type) { pkg_type } let(:package_type) { pkg_type }
it 'raises an error' do 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}") expect { subject }.to raise_error(ArgumentError, "Can't build registry_url for package_type #{package_type}")
end end
end end
......
...@@ -175,20 +175,6 @@ RSpec.describe API::Helpers do ...@@ -175,20 +175,6 @@ RSpec.describe API::Helpers do
end end
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 describe '#increment_unique_values' do
let(:value) { '9f302fea-f828-4ca9-aef4-e10bd723c0b3' } let(:value) { '9f302fea-f828-4ca9-aef4-e10bd723c0b3' }
let(:event_name) { 'g_compliance_dashboard' } 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