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 ...@@ -579,6 +579,7 @@ The [`StandardContext`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/g
| `namespace_id` | **{dotted-circle}** | integer | | | `namespace_id` | **{dotted-circle}** | integer | |
| `environment` | **{check-circle}** | string (max 32 chars) | Name of the source environment, such as `production` or `staging` | | `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` | | `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 | | `extra` | **{dotted-circle}** | JSON | Any additional data associated with the event, in the form of key-value pairs |
### Default Schema ### 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 @@ ...@@ -3,10 +3,12 @@
module Gitlab module Gitlab
module Tracking module Tracking
class StandardContext 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' GITLAB_RAILS_SOURCE = 'gitlab-rails'
def initialize(namespace: nil, project: nil, user: nil, **extra) def initialize(namespace: nil, project: nil, user: nil, **extra)
@namespace = namespace
@plan = @namespace&.actual_plan_name
@extra = extra @extra = extra
end end
...@@ -36,6 +38,7 @@ module Gitlab ...@@ -36,6 +38,7 @@ module Gitlab
{ {
environment: environment, environment: environment,
source: source, source: source,
plan: @plan,
extra: @extra extra: @extra
} }
end end
......
...@@ -57,6 +57,22 @@ RSpec.describe Gitlab::Tracking::StandardContext do ...@@ -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) expect(snowplow_context.to_json.dig(:data, :source)).to eq(described_class::GITLAB_RAILS_SOURCE)
end 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 context 'with extra data' do
subject { described_class.new(extra_key_1: 'extra value 1', extra_key_2: 'extra value 2') } 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 ...@@ -36,6 +36,8 @@ RSpec.describe Gitlab::Tracking do
end end
describe '.event' do describe '.event' do
let(:namespace) { create(:namespace) }
shared_examples 'delegates to destination' do |klass| shared_examples 'delegates to destination' do |klass|
before do before do
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow).to receive(:event) allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow).to receive(:event)
...@@ -47,7 +49,6 @@ RSpec.describe Gitlab::Tracking do ...@@ -47,7 +49,6 @@ RSpec.describe Gitlab::Tracking do
project = double(:project) project = double(:project)
user = double(:user) user = double(:user)
namespace = double(:namespace)
expect(Gitlab::Tracking::StandardContext) expect(Gitlab::Tracking::StandardContext)
.to receive(:new) .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