Commit b3941ef8 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '205578-trigger-pkg-guest-events' into 'master'

triggers package guest events tracking using redis counter

See merge request gitlab-org/gitlab!48547
parents 27da16c9 bdc3587f
......@@ -4,7 +4,9 @@ module Packages
class CreateEventService < BaseService
def execute
if Feature.enabled?(:collect_package_events_redis) && redis_event_name
unless guest?
if guest?
::Gitlab::UsageDataCounters::GuestPackageEventCounter.count(redis_event_name)
else
::Gitlab::UsageDataCounters::HLLRedisCounter.track_event(current_user.id, redis_event_name)
end
end
......
---
title: Tracks guest package events
merge_request: 48547
author:
type: added
---
- i_package_composer_guest_delete
- i_package_composer_guest_pull
- i_package_composer_guest_push
- i_package_conan_guest_delete
- i_package_conan_guest_pull
- i_package_conan_guest_push
- i_package_container_guest_delete
- i_package_container_guest_pull
- i_package_container_guest_push
- i_package_debian_guest_delete
- i_package_debian_guest_pull
- i_package_debian_guest_push
- i_package_generic_guest_delete
- i_package_generic_guest_pull
- i_package_generic_guest_push
- i_package_golang_guest_delete
- i_package_golang_guest_pull
- i_package_golang_guest_push
- i_package_maven_guest_delete
- i_package_maven_guest_pull
- i_package_maven_guest_push
- i_package_npm_guest_delete
- i_package_npm_guest_pull
- i_package_npm_guest_push
- i_package_nuget_guest_delete
- i_package_nuget_guest_pull
- i_package_nuget_guest_push
- i_package_pypi_guest_delete
- i_package_pypi_guest_pull
- i_package_pypi_guest_push
- i_package_tag_guest_delete
- i_package_tag_guest_pull
- i_package_tag_guest_push
......@@ -70,12 +70,34 @@ RSpec.describe Packages::CreateEventService do
end
it 'tracks the event' do
expect(::Gitlab::UsageDataCounters::GuestPackageEventCounter).not_to receive(:count)
expect(::Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(user.id, Packages::Event.allowed_event_name(expected_scope, event_name, originator_type))
subject
end
end
shared_examples 'redis package guest event creation' do |originator_type, expected_scope|
context 'with feature flag disabled' do
before do
stub_feature_flags(collect_package_events_redis: false)
end
it 'does not track the event' do
expect(::Gitlab::UsageDataCounters::GuestPackageEventCounter).not_to receive(:count)
subject
end
end
it 'tracks the event' do
expect(::Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event)
expect(::Gitlab::UsageDataCounters::GuestPackageEventCounter).to receive(:count).with(Packages::Event.allowed_event_name(expected_scope, event_name, originator_type))
subject
end
end
context 'with a user' do
let(:user) { create(:user) }
......@@ -94,6 +116,7 @@ RSpec.describe Packages::CreateEventService do
let(:user) { nil }
it_behaves_like 'db package event creation', 'guest', 'container'
it_behaves_like 'redis package guest event creation', 'guest', 'container'
end
context 'with a package as scope' do
......@@ -103,6 +126,7 @@ RSpec.describe Packages::CreateEventService do
let(:user) { nil }
it_behaves_like 'db package event creation', 'guest', 'npm'
it_behaves_like 'redis package guest event creation', 'guest', 'npm'
end
context 'with user' do
......
......@@ -27,14 +27,14 @@ RSpec.describe 'gitlab:packages:events namespace rake task' do
end
Packages::Event::EVENT_SCOPES.keys.each do |event_scope|
it "includes includes `#{event_scope}` scope" do
it "includes `#{event_scope}` scope" do
expect(subject.find { |event| event['name'].include?(event_scope) }).not_to be_nil
end
end
it 'excludes some event types' do
expect(subject.find { |event| event['name'].include?("search_package") }).to be_nil
expect(subject.find { |event| event['name'].include?("list_package") }).to be_nil
expect(subject.grep(/search_package/)).to be_empty
expect(subject.grep(/list_package/)).to be_empty
end
end
......@@ -42,7 +42,7 @@ RSpec.describe 'gitlab:packages:events namespace rake task' do
let(:task) { 'generate_guest' }
Packages::Event::EVENT_SCOPES.keys.each do |event_scope|
it "includes includes `#{event_scope}` scope" do
it "includes `#{event_scope}` scope" do
expect(subject.find { |event| event.include?(event_scope) }).not_to be_nil
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