diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/lib/gitlab/tracking | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/lib/gitlab/tracking')
-rw-r--r-- | spec/lib/gitlab/tracking/destinations/snowplow_spec.rb | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb b/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb index 65597e6568d..f8e73a807c6 100644 --- a/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb +++ b/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb @@ -21,7 +21,10 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do expect(SnowplowTracker::AsyncEmitter) .to receive(:new) - .with('gitfoo.com', { protocol: 'https' }) + .with('gitfoo.com', + { protocol: 'https', + on_success: subject.method(:increment_successful_events_emissions), + on_failure: subject.method(:failure_callback) }) .and_return(emitter) expect(SnowplowTracker::Tracker) @@ -40,6 +43,18 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do .to have_received(:track_struct_event) .with('category', 'action', 'label', 'property', 1.5, nil, (Time.now.to_f * 1000).to_i) end + + it 'increase total snowplow events counter' do + counter = double + + expect(counter).to receive(:increment) + expect(Gitlab::Metrics).to receive(:counter) + .with(:gitlab_snowplow_events_total, + 'Number of Snowplow events') + .and_return(counter) + + subject.event('category', 'action', label: 'label', property: 'property', value: 1.5) + end end end @@ -52,4 +67,43 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do end end end + + context 'callbacks' do + describe 'on success' do + it 'increase gitlab_successful_snowplow_events_total counter' do + counter = double + + expect(counter).to receive(:increment).with({}, 2) + expect(Gitlab::Metrics).to receive(:counter) + .with(:gitlab_snowplow_successful_events_total, + 'Number of successful Snowplow events emissions') + .and_return(counter) + + subject.method(:increment_successful_events_emissions).call(2) + end + end + + describe 'on failure' do + it 'increase gitlab_failed_snowplow_events_total counter and logs failures', :aggregate_failures do + counter = double + error_message = "Admin::AuditLogsController search_audit_event failed to be reported to collector at gitfoo.com" + failures = [{ "e" => "se", + "se_ca" => "Admin::AuditLogsController", + "se_ac" => "search_audit_event" }] + allow(Gitlab::Metrics).to receive(:counter) + .with(:gitlab_snowplow_successful_events_total, + 'Number of successful Snowplow events emissions') + .and_call_original + + expect(Gitlab::AppLogger).to receive(:error).with(error_message) + expect(counter).to receive(:increment).with({}, 1) + expect(Gitlab::Metrics).to receive(:counter) + .with(:gitlab_snowplow_failed_events_total, + 'Number of failed Snowplow events emissions') + .and_return(counter) + + subject.method(:failure_callback).call(2, failures) + end + end + end end |