Commit 9508d32a authored by Sean McGivern's avatar Sean McGivern

Merge branch 'include_user_on_snowplow_event' into 'master'

Add user to Snowplow event

See merge request gitlab-org/gitlab!71353
parents c2ecd08e e27b92a0
---
name: add_actor_based_user_to_snowplow_tracking
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/71353
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/338150
milestone: '14.4'
type: development
group: group::product intelligence
default_enabled: false
......@@ -30,7 +30,7 @@ module Security
'scan',
context: [context],
idempotency_key: Digest::SHA256.hexdigest(idempotency_key),
user: build.user_id,
user: build.user,
project: build.project_id,
label: analyzer_id(report),
property: scan_type(report, report_type))
......
......@@ -43,7 +43,7 @@ RSpec.describe Security::TrackScanService do
}
}],
idempotency_key: '82fc6391e4be61e03e51fa8c5c6bfc32b3d3f0065ad2fe0a01211606952b8d82',
user: user.id,
user: user,
project: project.id,
label: 'gitlab-dast',
property: 'dast')
......@@ -81,7 +81,7 @@ RSpec.describe Security::TrackScanService do
}
}],
idempotency_key: '62bc6c62686b327dbf420f8891e1418406b60f49e574b6ff22f4d6a272dbc595',
user: user.id,
user: user,
project: project.id,
label: nil,
property: 'dast')
......
......@@ -10,6 +10,7 @@ module Gitlab
@namespace = namespace
@plan = namespace&.actual_plan_name
@project = project
@user = user
@extra = extra
end
......@@ -35,7 +36,7 @@ module Gitlab
private
attr_accessor :namespace, :project, :extra, :plan
attr_accessor :namespace, :project, :extra, :plan, :user
def to_h
{
......@@ -44,6 +45,7 @@ module Gitlab
plan: plan,
extra: extra
}.merge(project_and_namespace)
.merge(user_data)
end
def project_and_namespace
......@@ -58,6 +60,10 @@ module Gitlab
def project_id
project.is_a?(Integer) ? project : project&.id
end
def user_data
::Feature.enabled?(:add_actor_based_user_to_snowplow_tracking, user) ? { user_id: user&.id } : {}
end
end
end
end
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Tracking::StandardContext do
let_it_be(:project) { create(:project) }
let_it_be(:namespace) { create(:namespace) }
let_it_be(:user) { create(:user) }
let(:snowplow_context) { subject.to_context }
......@@ -87,8 +88,8 @@ RSpec.describe Gitlab::Tracking::StandardContext do
end
end
it 'does not contain user id' do
expect(snowplow_context.to_json[:data].keys).not_to include(:user_id)
it 'contains user id' do
expect(snowplow_context.to_json[:data].keys).to include(:user_id)
end
it 'contains namespace and project ids' do
......@@ -104,8 +105,18 @@ RSpec.describe Gitlab::Tracking::StandardContext do
stub_feature_flags(add_namespace_and_project_to_snowplow_tracking: false)
end
it 'does not contain any ids' do
expect(snowplow_context.to_json[:data].keys).not_to include(:user_id, :project_id, :namespace_id)
it 'does not contain project or namespace ids' do
expect(snowplow_context.to_json[:data].keys).not_to include(:project_id, :namespace_id)
end
end
context 'without add_actor_based_user_to_snowplow_tracking feature' do
before do
stub_feature_flags(add_actor_based_user_to_snowplow_tracking: false)
end
it 'does not contain user_id' do
expect(snowplow_context.to_json[:data].keys).not_to include(:user_id)
end
end
end
......
......@@ -48,7 +48,7 @@ RSpec.describe Gitlab::Tracking do
other_context = double(:context)
project = build_stubbed(:project)
user = double(:user)
user = build_stubbed(:user)
expect(Gitlab::Tracking::StandardContext)
.to receive(:new)
......
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