Commit d6814e03 authored by Niko Belokolodov's avatar Niko Belokolodov Committed by Heinrich Lee Yu

Move p_ci_templates metrics to Snowplow

parent 197edba5
......@@ -184,8 +184,9 @@ class EventCreateService
track_event(event_action: :pushed, event_target: Project, author_id: current_user.id)
if Feature.enabled?(:route_hll_to_snowplow, project, default_enabled: :yaml)
Gitlab::Tracking.event(self.class.to_s, 'action_active_users_project_repo', namespace: project, user: current_user)
namespace = project.namespace
if Feature.enabled?(:route_hll_to_snowplow, namespace, default_enabled: :yaml)
Gitlab::Tracking.event(self.class.to_s, 'action_active_users_project_repo', namespace: namespace, user: current_user, project: project)
end
Users::LastPushEventService.new(current_user)
......
......@@ -19,7 +19,7 @@ module Gitlab
def track_event(template)
Gitlab::UsageDataCounters::CiTemplateUniqueCounter
.track_unique_project_event(project_id: pipeline.project_id, template: template, config_source: pipeline.config_source)
.track_unique_project_event(project: pipeline.project, template: template, config_source: pipeline.config_source, user: current_user)
end
def included_templates
......
......@@ -6,13 +6,18 @@ module Gitlab::UsageDataCounters
KNOWN_EVENTS_FILE_PATH = File.expand_path('known_events/ci_templates.yml', __dir__)
class << self
def track_unique_project_event(project_id:, template:, config_source:)
def track_unique_project_event(project:, template:, config_source:, user:)
expanded_template_name = expand_template_name(template)
return unless expanded_template_name
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(
ci_template_event_name(expanded_template_name, config_source), values: project_id
ci_template_event_name(expanded_template_name, config_source), values: project.id
)
namespace = project.namespace
if Feature.enabled?(:route_hll_to_snowplow, namespace, default_enabled: :yaml)
Gitlab::Tracking.event(name, 'ci_templates_unique', namespace: namespace, user: user, project: project)
end
end
def ci_templates(relative_base = 'lib/gitlab/ci/templates')
......
......@@ -28,7 +28,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::TemplateUsage do
%w(Template-1 Template-2).each do |expected_template|
expect(Gitlab::UsageDataCounters::CiTemplateUniqueCounter).to(
receive(:track_unique_project_event)
.with(project_id: project.id, template: expected_template, config_source: pipeline.config_source)
.with(project: project, template: expected_template, config_source: pipeline.config_source, user: user)
)
end
......
......@@ -5,30 +5,52 @@ require 'spec_helper'
RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do
describe '.track_unique_project_event' do
using RSpec::Parameterized::TableSyntax
include SnowplowHelpers
let(:project_id) { 1 }
let(:project) { build(:project) }
let(:user) { build(:user) }
shared_examples 'tracks template' do
let(:subject) { described_class.track_unique_project_event(project: project, template: template_path, config_source: config_source, user: user) }
it "has an event defined for template" do
expect do
described_class.track_unique_project_event(
project_id: project_id,
template: template_path,
config_source: config_source
)
subject
end.not_to raise_error
end
it "tracks template" do
expanded_template_name = described_class.expand_template_name(template_path)
expected_template_event_name = described_class.ci_template_event_name(expanded_template_name, config_source)
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to(receive(:track_event)).with(expected_template_event_name, values: project_id)
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to(receive(:track_event)).with(expected_template_event_name, values: project.id)
subject
end
context 'Snowplow' do
it 'event is not tracked if FF is disabled' do
stub_feature_flags(route_hll_to_snowplow: false)
subject
described_class.track_unique_project_event(project_id: project_id, template: template_path, config_source: config_source)
expect_no_snowplow_event
end
it 'tracks event' do
subject
expect_snowplow_event(
category: described_class.to_s,
action: 'ci_templates_unique',
namespace: project.namespace,
user: user,
project: project
)
end
end
end
context 'with explicit includes' do
context 'with explicit includes', :snowplow do
let(:config_source) { :repository_source }
(described_class.ci_templates - ['Verify/Browser-Performance.latest.gitlab-ci.yml', 'Verify/Browser-Performance.gitlab-ci.yml']).each do |template|
......@@ -40,7 +62,7 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do
end
end
context 'with implicit includes' do
context 'with implicit includes', :snowplow do
let(:config_source) { :auto_devops_source }
[
......@@ -60,7 +82,7 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do
it 'expands short template names' do
expect do
described_class.track_unique_project_event(project_id: 1, template: 'Dependency-Scanning.gitlab-ci.yml', config_source: :repository_source)
described_class.track_unique_project_event(project: project, template: 'Dependency-Scanning.gitlab-ci.yml', config_source: :repository_source, user: user)
end.not_to raise_error
end
end
......
......@@ -35,8 +35,9 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
expect_snowplow_event(
category: described_class.to_s,
action: 'action_active_users_project_repo',
namespace: project,
user: user
namespace: project.namespace,
user: user,
project: project
)
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