Commit f557ea9f authored by Alishan Ladhani's avatar Alishan Ladhani

Remove self-describing events

Part of Snowplow standardization effort
parent 2cc6c22f
......@@ -19,12 +19,14 @@ class Groups::EmailCampaignsController < Groups::ApplicationController
def track_click
data = {
namespace_id: group.id,
track: @track,
track: @track.to_s,
series: @series,
subject_line: subject_line(@track, @series)
}
::Gitlab::Tracking.self_describing_event(EMAIL_CAMPAIGNS_SCHEMA_URL, data: data)
context = SnowplowTracker::SelfDescribingJson.new(EMAIL_CAMPAIGNS_SCHEMA_URL, data)
::Gitlab::Tracking.event(self.class.name, 'click', context: [context])
end
def redirect_link
......
......@@ -468,7 +468,7 @@ Snowplow Micro is a Docker-based solution for testing frontend and backend event
1. Send a test Snowplow event from the Rails console:
```ruby
Gitlab::Tracking.self_describing_event('iglu:com.gitlab/pageview_context/jsonschema/1-0-0', data: { page_type: 'MY_TYPE' }, context: nil)
Gitlab::Tracking.event('category', 'action')
```
1. Navigate to `localhost:9090/micro/good` to see the event.
......
......@@ -26,7 +26,9 @@ class SurveyResponsesController < ApplicationController
response: params[:response]
}.compact
::Gitlab::Tracking.self_describing_event(SURVEY_RESPONSE_SCHEMA_URL, data: data)
context = SnowplowTracker::SelfDescribingJson.new(SURVEY_RESPONSE_SCHEMA_URL, data)
::Gitlab::Tracking.event(self.class.name, 'submit_response', context: [context])
end
def to_number(param)
......
......@@ -20,21 +20,22 @@ RSpec.describe SurveyResponsesController do
allow(::Gitlab).to receive(:com?).and_return(true)
end
it 'tracks a survey_response event' do
expect(Gitlab::Tracking).to receive(:self_describing_event).with(
SurveyResponsesController::SURVEY_RESPONSE_SCHEMA_URL,
data: { survey_id: 1, response: 'bar' }
)
it 'tracks a survey_response event', :snowplow do
subject
expect_snowplow_event(
category: described_class.name,
action: 'submit_response',
context: [{ schema: described_class::SURVEY_RESPONSE_SCHEMA_URL, data: { response: 'bar', survey_id: 1 } }]
)
end
end
context 'not on GitLab.com' do
it 'does not track a survey_response event' do
expect(Gitlab::Tracking).not_to receive(:self_describing_event)
it 'does not track a survey_response event', :snowplow do
subject
expect_no_snowplow_event
end
end
end
......
......@@ -18,10 +18,6 @@ module Gitlab
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
end
def self_describing_event(schema_url, data:, context: nil)
snowplow.self_describing_event(schema_url, data: data, context: context)
end
def snowplow_options(group)
additional_features = Feature.enabled?(:additional_snowplow_tracking, group)
{
......
......@@ -15,13 +15,6 @@ module Gitlab
tracker.track_struct_event(category, action, label, property, value, context, (Time.now.to_f * 1000).to_i)
end
def self_describing_event(schema_url, data:, context: nil)
return unless enabled?
event_json = SnowplowTracker::SelfDescribingJson.new(schema_url, data)
tracker.track_self_describing_event(event_json, context, (Time.now.to_f * 1000).to_i)
end
private
def enabled?
......
......@@ -41,21 +41,6 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do
.with('category', 'action', 'label', 'property', 1.5, nil, (Time.now.to_f * 1000).to_i)
end
end
describe '#self_describing_event' do
it 'sends event to tracker' do
allow(tracker).to receive(:track_self_describing_event).and_call_original
subject.self_describing_event('iglu:com.gitlab/foo/jsonschema/1-0-0', data: { foo: 'bar' })
expect(tracker).to have_received(:track_self_describing_event) do |event, context, timestamp|
expect(event.to_json[:schema]).to eq('iglu:com.gitlab/foo/jsonschema/1-0-0')
expect(event.to_json[:data]).to eq(foo: 'bar')
expect(context).to eq(nil)
expect(timestamp).to eq((Time.now.to_f * 1000).to_i)
end
end
end
end
context 'when snowplow is not enabled' do
......@@ -66,13 +51,5 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do
subject.event('category', 'action', label: 'label', property: 'property', value: 1.5)
end
end
describe '#self_describing_event' do
it 'does not send event to tracker' do
expect_any_instance_of(SnowplowTracker::Tracker).not_to receive(:track_self_describing_event)
subject.self_describing_event('iglu:com.gitlab/foo/jsonschema/1-0-0', data: { foo: 'bar' })
end
end
end
end
......@@ -82,14 +82,4 @@ RSpec.describe Gitlab::Tracking do
described_class.event(nil, 'some_action')
end
end
describe '.self_describing_event' do
it 'delegates to snowplow destination' do
expect_any_instance_of(Gitlab::Tracking::Destinations::Snowplow)
.to receive(:self_describing_event)
.with('iglu:com.gitlab/foo/jsonschema/1-0-0', data: { foo: 'bar' }, context: nil)
described_class.self_describing_event('iglu:com.gitlab/foo/jsonschema/1-0-0', data: { foo: 'bar' })
end
end
end
......@@ -13,19 +13,19 @@ RSpec.describe Groups::EmailCampaignsController do
let(:track) { 'create' }
let(:series) { '0' }
let(:schema) { described_class::EMAIL_CAMPAIGNS_SCHEMA_URL }
let(:subject_line_text) { subject_line(track.to_sym, series.to_i) }
let(:data) do
{
namespace_id: group.id,
track: track.to_sym,
series: series.to_i,
subject_line: subject_line(track.to_sym, series.to_i)
subject_line: subject_line_text
}
end
before do
sign_in(user)
group.add_developer(user)
allow(Gitlab::Tracking).to receive(:self_describing_event)
end
subject do
......@@ -34,16 +34,33 @@ RSpec.describe Groups::EmailCampaignsController do
end
shared_examples 'track and redirect' do
it do
is_expected.to track_self_describing_event(schema, data)
is_expected.to have_gitlab_http_status(:redirect)
it 'redirects' do
expect(subject).to have_gitlab_http_status(:redirect)
end
it 'emits a snowplow event', :snowplow do
subject
expect_snowplow_event(
category: described_class.name,
action: 'click',
context: [{
schema: described_class::EMAIL_CAMPAIGNS_SCHEMA_URL,
data: { namespace_id: group.id, series: series.to_i, subject_line: subject_line_text, track: track.to_s }
}]
)
end
end
shared_examples 'no track and 404' do
it do
is_expected.not_to track_self_describing_event
is_expected.to have_gitlab_http_status(:not_found)
it 'returns 404' do
expect(subject).to have_gitlab_http_status(:not_found)
end
it 'does not emit a snowplow event', :snowplow do
subject
expect_no_snowplow_event
end
end
......
# frozen_string_literal: true
RSpec::Matchers.define :track_self_describing_event do |schema, data|
match do
expect(Gitlab::Tracking).to have_received(:self_describing_event)
.with(schema, data: data)
end
match_when_negated do
expect(Gitlab::Tracking).not_to have_received(:self_describing_event)
end
end
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