Commit 57011e29 authored by Alper Akgun's avatar Alper Akgun

Merge branch 'ali/convert-self-describing-events-to-structured' into 'master'

Remove self-describing Snowplow events

See merge request gitlab-org/gitlab!56816
parents 429fde41 f557ea9f
...@@ -19,12 +19,14 @@ class Groups::EmailCampaignsController < Groups::ApplicationController ...@@ -19,12 +19,14 @@ class Groups::EmailCampaignsController < Groups::ApplicationController
def track_click def track_click
data = { data = {
namespace_id: group.id, namespace_id: group.id,
track: @track, track: @track.to_s,
series: @series, series: @series,
subject_line: subject_line(@track, @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 end
def redirect_link def redirect_link
......
...@@ -469,7 +469,7 @@ Snowplow Micro is a Docker-based solution for testing frontend and backend event ...@@ -469,7 +469,7 @@ Snowplow Micro is a Docker-based solution for testing frontend and backend event
1. Send a test Snowplow event from the Rails console: 1. Send a test Snowplow event from the Rails console:
```ruby ```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. 1. Navigate to `localhost:9090/micro/good` to see the event.
......
...@@ -26,7 +26,9 @@ class SurveyResponsesController < ApplicationController ...@@ -26,7 +26,9 @@ class SurveyResponsesController < ApplicationController
response: params[:response] response: params[:response]
}.compact }.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 end
def to_number(param) def to_number(param)
......
...@@ -20,21 +20,22 @@ RSpec.describe SurveyResponsesController do ...@@ -20,21 +20,22 @@ RSpec.describe SurveyResponsesController do
allow(::Gitlab).to receive(:com?).and_return(true) allow(::Gitlab).to receive(:com?).and_return(true)
end end
it 'tracks a survey_response event' do it 'tracks a survey_response event', :snowplow do
expect(Gitlab::Tracking).to receive(:self_describing_event).with(
SurveyResponsesController::SURVEY_RESPONSE_SCHEMA_URL,
data: { survey_id: 1, response: 'bar' }
)
subject 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
end end
context 'not on GitLab.com' do context 'not on GitLab.com' do
it 'does not track a survey_response event' do it 'does not track a survey_response event', :snowplow do
expect(Gitlab::Tracking).not_to receive(:self_describing_event)
subject subject
expect_no_snowplow_event
end end
end end
end end
......
...@@ -18,10 +18,6 @@ module Gitlab ...@@ -18,10 +18,6 @@ module Gitlab
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action) Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
end 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) def snowplow_options(group)
additional_features = Feature.enabled?(:additional_snowplow_tracking, group) additional_features = Feature.enabled?(:additional_snowplow_tracking, group)
{ {
......
...@@ -15,13 +15,6 @@ module Gitlab ...@@ -15,13 +15,6 @@ module Gitlab
tracker.track_struct_event(category, action, label, property, value, context, (Time.now.to_f * 1000).to_i) tracker.track_struct_event(category, action, label, property, value, context, (Time.now.to_f * 1000).to_i)
end 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 private
def enabled? def enabled?
......
...@@ -41,21 +41,6 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do ...@@ -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) .with('category', 'action', 'label', 'property', 1.5, nil, (Time.now.to_f * 1000).to_i)
end end
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 end
context 'when snowplow is not enabled' do context 'when snowplow is not enabled' do
...@@ -66,13 +51,5 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do ...@@ -66,13 +51,5 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do
subject.event('category', 'action', label: 'label', property: 'property', value: 1.5) subject.event('category', 'action', label: 'label', property: 'property', value: 1.5)
end end
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
end end
...@@ -83,14 +83,4 @@ RSpec.describe Gitlab::Tracking do ...@@ -83,14 +83,4 @@ RSpec.describe Gitlab::Tracking do
described_class.event(nil, 'some_action') described_class.event(nil, 'some_action')
end end
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 end
...@@ -13,19 +13,19 @@ RSpec.describe Groups::EmailCampaignsController do ...@@ -13,19 +13,19 @@ RSpec.describe Groups::EmailCampaignsController do
let(:track) { 'create' } let(:track) { 'create' }
let(:series) { '0' } let(:series) { '0' }
let(:schema) { described_class::EMAIL_CAMPAIGNS_SCHEMA_URL } let(:schema) { described_class::EMAIL_CAMPAIGNS_SCHEMA_URL }
let(:subject_line_text) { subject_line(track.to_sym, series.to_i) }
let(:data) do let(:data) do
{ {
namespace_id: group.id, namespace_id: group.id,
track: track.to_sym, track: track.to_sym,
series: series.to_i, series: series.to_i,
subject_line: subject_line(track.to_sym, series.to_i) subject_line: subject_line_text
} }
end end
before do before do
sign_in(user) sign_in(user)
group.add_developer(user) group.add_developer(user)
allow(Gitlab::Tracking).to receive(:self_describing_event)
end end
subject do subject do
...@@ -34,16 +34,33 @@ RSpec.describe Groups::EmailCampaignsController do ...@@ -34,16 +34,33 @@ RSpec.describe Groups::EmailCampaignsController do
end end
shared_examples 'track and redirect' do shared_examples 'track and redirect' do
it do it 'redirects' do
is_expected.to track_self_describing_event(schema, data) expect(subject).to have_gitlab_http_status(:redirect)
is_expected.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
end end
shared_examples 'no track and 404' do shared_examples 'no track and 404' do
it do it 'returns 404' do
is_expected.not_to track_self_describing_event expect(subject).to have_gitlab_http_status(:not_found)
is_expected.to have_gitlab_http_status(:not_found) end
it 'does not emit a snowplow event', :snowplow do
subject
expect_no_snowplow_event
end end
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