Skip to content
代码片段 群组 项目
未验证 提交 832759a0 编辑于 作者: Piotr Skorupa's avatar Piotr Skorupa 提交者: GitLab
浏览文件

Merge branch '438827-tracking-namespace-that-empowered-a-user-to-use-a-feature' into 'master'

Track namespaces that empowered a user to use a feature

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/148463



Merged-by: default avatarPiotr Skorupa <pskorupa@gitlab.com>
Approved-by: default avatarJonas Larsen <jlarsen@gitlab.com>
Approved-by: default avatarSebastian Rehm <srehm@gitlab.com>
Approved-by: default avatarPiotr Skorupa <pskorupa@gitlab.com>
Co-authored-by: default avatarJonas Larsen <jlarsen@gitlab.com>
Co-authored-by: default avatarSebastian Rehm <srehm@gitlab.com>
Co-authored-by: default avatarNiko Belokolodov <nbelokolodov@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -62,6 +62,16 @@ If a `project` but no `namespace` is provided, the `project.namespace` is used a
In some cases you might want to specify the `category` manually or provide none at all. To do that, you can call the `InternalEvents.track_event` method directly instead of using the module.
In case when a feature is enabled through multiple namespaces and its required to track why the feature is enabled, it is
possible to pass an optional `feature_enabled_by_namespace_ids` parameter with an array of namespace ids.
```ruby
Gitlab::InternalEvents.track_event(
...
feature_enabled_by_namespace_ids: [namespace_one.id, namespace_two.id]
)
```
#### Additional properties
Additional properties can be passed when tracking events. They can be used to save additional data related to given event. It is possible to send a maximum of three additional properties with keys `label` (string), `property` (string) and `value`(numeric).
......
......@@ -118,12 +118,14 @@ def trigger_snowplow_event(event_name, category, additional_properties, kwargs)
user = kwargs[:user]
project = kwargs[:project]
namespace = kwargs[:namespace]
feature_enabled_by_namespace_ids = kwargs[:feature_enabled_by_namespace_ids]
standard_context = Tracking::StandardContext.new(
project_id: project&.id,
user_id: user&.id,
namespace_id: namespace&.id,
plan_name: namespace&.actual_plan_name
plan_name: namespace&.actual_plan_name,
feature_enabled_by_namespace_ids: feature_enabled_by_namespace_ids
).to_context
service_ping_context = Tracking::ServicePingContext.new(
......
......@@ -6,7 +6,9 @@ class StandardContext
GITLAB_STANDARD_SCHEMA_URL = 'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-9'
GITLAB_RAILS_SOURCE = 'gitlab-rails'
def initialize(namespace_id: nil, plan_name: nil, project_id: nil, user_id: nil, **extra)
def initialize(
namespace_id: nil, plan_name: nil, project_id: nil, user_id: nil,
feature_enabled_by_namespace_ids: nil, **extra)
check_argument_type(:namespace_id, namespace_id, [Integer])
check_argument_type(:plan_name, plan_name, [String])
check_argument_type(:project_id, project_id, [Integer])
......@@ -17,6 +19,7 @@ def initialize(namespace_id: nil, plan_name: nil, project_id: nil, user_id: nil,
@project_id = project_id
@user_id = user_id
@extra = extra
@feature_enabled_by_namespace_ids = feature_enabled_by_namespace_ids
end
def to_context
......@@ -41,7 +44,7 @@ def source
private
attr_accessor :namespace_id, :project_id, :extra, :plan_name, :user_id
attr_accessor :namespace_id, :project_id, :extra, :plan_name, :user_id, :feature_enabled_by_namespace_ids
def to_h
{
......@@ -53,6 +56,7 @@ def to_h
is_gitlab_team_member: gitlab_team_member?(user_id),
namespace_id: namespace_id,
project_id: project_id,
feature_enabled_by_namespace_ids: feature_enabled_by_namespace_ids,
context_generated_at: Time.current
}
end
......
......@@ -174,6 +174,29 @@ def validate_service_ping_context(service_ping_context)
end
end
context 'when feature_enabled_by_namespace_ids is passed' do
let(:feature_enabled_by_namespace_ids) { [1, 2, 3] }
it 'is sent to Snowplow' do
described_class.track_event(
event_name,
user: user,
project: project,
feature_enabled_by_namespace_ids: feature_enabled_by_namespace_ids
)
expect(fake_snowplow).to have_received(:event) do |_, _, args|
contexts = args[:context]&.map(&:to_json)
standard_context = contexts.find do |c|
c[:schema] == Gitlab::Tracking::StandardContext::GITLAB_STANDARD_SCHEMA_URL
end
expect(standard_context[:data][:feature_enabled_by_namespace_ids]).to eq(feature_enabled_by_namespace_ids)
end
end
end
context 'when arguments are invalid' do
let(:error_class) { described_class::InvalidPropertyTypeError }
......
......@@ -35,6 +35,7 @@
expect(Gitlab::Tracking::StandardContext)
.to have_received(:new)
.with(
feature_enabled_by_namespace_ids: try(:feature_enabled_by_namespace_ids),
project_id: project&.id,
user_id: user&.id,
namespace_id: namespace&.id,
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册