Commit 1ca3e5d9 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch 'mwaw/338593-collection-of-namespace_id-and-project_id-in-service-ping' into 'master'

Resolve "Collection of namespace_id and project_id in Service Ping"

See merge request gitlab-org/gitlab!68277
parents 821936f8 0dbb1063
---
name: add_namespace_and_project_to_snowplow_tracking
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68277
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/338670
milestone: '14.3'
type: development
group: group::product intelligence
default_enabled: false
......@@ -8,7 +8,8 @@ module Gitlab
def initialize(namespace: nil, project: nil, user: nil, **extra)
@namespace = namespace
@plan = @namespace&.actual_plan_name
@plan = namespace&.actual_plan_name
@project = project
@extra = extra
end
......@@ -34,14 +35,29 @@ module Gitlab
private
attr_accessor :namespace, :project, :extra, :plan
def to_h
{
environment: environment,
source: source,
plan: @plan,
extra: @extra
plan: plan,
extra: extra
}.merge(project_and_namespace)
end
def project_and_namespace
return {} unless ::Feature.enabled?(:add_namespace_and_project_to_snowplow_tracking, default_enabled: :yaml)
{
namespace_id: namespace&.id,
project_id: project_id
}
end
def project_id
project.is_a?(Integer) ? project : project&.id
end
end
end
end
......@@ -87,8 +87,26 @@ 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)
end
it 'contains namespace and project ids' do
expect(snowplow_context.to_json[:data].keys).to include(:project_id, :namespace_id)
end
it 'accepts just project id as integer' do
expect { described_class.new(project: 1).to_context }.not_to raise_error
end
context 'without add_namespace_and_project_to_snowplow_tracking feature' do
before 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)
end
end
end
end
......@@ -47,7 +47,7 @@ RSpec.describe Gitlab::Tracking do
it "delegates to #{klass} destination" do
other_context = double(:context)
project = double(:project)
project = build_stubbed(:project)
user = double(:user)
expect(Gitlab::Tracking::StandardContext)
......
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