Commit 19024d3c authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Mikołaj Wawrzyniak

Add plan to snowplow standard context [RUN AS-IF-FOSS]

parent c62a65ec
......@@ -579,6 +579,7 @@ The [`StandardContext`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/g
| `namespace_id` | **{dotted-circle}** | integer | |
| `environment` | **{check-circle}** | string (max 32 chars) | Name of the source environment, such as `production` or `staging` |
| `source` | **{check-circle}** | string (max 32 chars) | Name of the source application, such as `gitlab-rails` or `gitlab-javascript` |
| `plan` | **{dotted-circle}** | string (max 32 chars) | Name of the plan for the namespace, such as `free`, `premium`, or `ultimate`. Automatically picked from the `namespace`. |
| `extra` | **{dotted-circle}** | JSON | Any additional data associated with the event, in the form of key-value pairs |
### Default Schema
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Tracking::StandardContext do
let_it_be(:project) { create(:project) }
let_it_be(:namespace) { create(:namespace) }
let_it_be(:plan) { :ultimate_plan }
let(:snowplow_context) { subject.to_context }
describe '#to_context' do
context 'plan' do
context 'when namespace is not available' do
it 'is nil' do
expect(snowplow_context.to_json.dig(:data, :plan)).to be_nil
end
end
context 'when namespace is available' do
subject { described_class.new(namespace: create(:namespace_with_plan, plan: plan)) }
it 'contains plan name' do
expect(snowplow_context.to_json.dig(:data, :plan)).to eq(Plan::ULTIMATE)
end
end
end
end
end
......@@ -3,10 +3,12 @@
module Gitlab
module Tracking
class StandardContext
GITLAB_STANDARD_SCHEMA_URL = 'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-4'
GITLAB_STANDARD_SCHEMA_URL = 'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-5'
GITLAB_RAILS_SOURCE = 'gitlab-rails'
def initialize(namespace: nil, project: nil, user: nil, **extra)
@namespace = namespace
@plan = @namespace&.actual_plan_name
@extra = extra
end
......@@ -36,6 +38,7 @@ module Gitlab
{
environment: environment,
source: source,
plan: @plan,
extra: @extra
}
end
......
......@@ -57,6 +57,22 @@ RSpec.describe Gitlab::Tracking::StandardContext do
expect(snowplow_context.to_json.dig(:data, :source)).to eq(described_class::GITLAB_RAILS_SOURCE)
end
context 'plan' do
context 'when namespace is not available' do
it 'is nil' do
expect(snowplow_context.to_json.dig(:data, :plan)).to be_nil
end
end
context 'when namespace is available' do
subject { described_class.new(namespace: create(:namespace)) }
it 'contains plan name' do
expect(snowplow_context.to_json.dig(:data, :plan)).to eq(Plan::DEFAULT)
end
end
end
context 'with extra data' do
subject { described_class.new(extra_key_1: 'extra value 1', extra_key_2: 'extra value 2') }
......
......@@ -36,6 +36,8 @@ RSpec.describe Gitlab::Tracking do
end
describe '.event' do
let(:namespace) { create(:namespace) }
shared_examples 'delegates to destination' do |klass|
before do
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow).to receive(:event)
......@@ -47,7 +49,6 @@ RSpec.describe Gitlab::Tracking do
project = double(:project)
user = double(:user)
namespace = double(:namespace)
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