Commit d72d4296 authored by Max Woolf's avatar Max Woolf

Merge branch '351076-follow-up-from-track-api-requests-for-jetbrains-plugin' into 'master'

Resolve "Follow-up from "Track API requests for jetbrains plugin""

See merge request gitlab-org/gitlab!79823
parents 5a01f210 4796ba6b
...@@ -52,7 +52,8 @@ module QA ...@@ -52,7 +52,8 @@ module QA
"otp" => "OTP", "otp" => "OTP",
"jira_api" => "JiraAPI", "jira_api" => "JiraAPI",
"registry_tls" => "RegistryTLS", "registry_tls" => "RegistryTLS",
"jetbrains" => "JetBrains" "jetbrains" => "JetBrains",
"vscode" => "VSCode"
) )
loader.setup loader.setup
......
...@@ -2,62 +2,14 @@ ...@@ -2,62 +2,14 @@
require 'spec_helper' require 'spec_helper'
RSpec.shared_examples 'a tracked jetbrains unique action' do |event| RSpec.describe Gitlab::UsageDataCounters::JetBrainsPluginActivityUniqueCounter, :clean_gitlab_redis_shared_state do # rubocop:disable RSpec/FilePath
before do
stub_application_setting(usage_ping_enabled: true)
end
def count_unique(date_from:, date_to:)
Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: action, start_date: date_from, end_date: date_to)
end
it 'tracks when the user agent is from jetbrains' do
aggregate_failures do
user_agent = { user_agent: 'gitlab-jetbrains-plugin/0.0.1 intellij-idea/2021.2.4 java/11.0.13 mac-os-x/aarch64/12.1' }
expect(track_action(user: user1, **user_agent)).to be_truthy
expect(track_action(user: user1, **user_agent)).to be_truthy
expect(track_action(user: user2, **user_agent)).to be_truthy
expect(count_unique(date_from: time - 1.week, date_to: time + 1.week)).to eq(2)
end
end
it 'does not track when the user agent is not from jetbrains' do
aggregate_failures do
user_agent = { user_agent: 'normal_user_agent' }
expect(track_action(user: user1, **user_agent)).to be_falsey
expect(track_action(user: user1, **user_agent)).to be_falsey
expect(track_action(user: user2, **user_agent)).to be_falsey
expect(count_unique(date_from: time - 1.week, date_to: time + 1.week)).to eq(0)
end
end
it 'does not track if user agent is not present' do
expect(track_action(user: nil, user_agent: nil)).to be_nil
end
it 'does not track if user is not present' do
user_agent = { user_agent: 'gitlab-jetbrains-plugin/0.0.1 intellij-idea/2021.2.4 java/11.0.13 mac-os-x/aarch64/12.1' }
expect(track_action(user: nil, **user_agent)).to be_nil
end
end
RSpec.describe Gitlab::UsageDataCounters::JetBrainsPluginActivityUniqueCounter, :clean_gitlab_redis_shared_state do
let(:user1) { build(:user, id: 1) } let(:user1) { build(:user, id: 1) }
let(:user2) { build(:user, id: 2) } let(:user2) { build(:user, id: 2) }
let(:time) { Time.current } let(:time) { Time.current }
context 'when tracking a jetbrains api request' do
it_behaves_like 'a tracked jetbrains unique action' do
let(:action) { described_class::JETBRAINS_API_REQUEST_ACTION } let(:action) { described_class::JETBRAINS_API_REQUEST_ACTION }
let(:user_agent) { { user_agent: 'gitlab-jetbrains-plugin/0.0.1 intellij-idea/2021.2.4 java/11.0.13 mac-os-x/aarch64/12.1' } }
def track_action(params) context 'when tracking a jetbrains api request' do
described_class.track_api_request_when_trackable(**params) it_behaves_like 'a request from an extension'
end
end
end end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::UsageDataCounters::VSCodeExtensionActivityUniqueCounter, :clean_gitlab_redis_shared_state do # rubocop:disable RSpec/FilePath
let(:user1) { build(:user, id: 1) }
let(:user2) { build(:user, id: 2) }
let(:time) { Time.current }
let(:action) { described_class::VS_CODE_API_REQUEST_ACTION }
let(:user_agent) { { user_agent: 'vs-code-gitlab-workflow/3.11.1 VSCode/1.52.1 Node.js/12.14.1 (darwin; x64)' } }
context 'when tracking a vs code api request' do
it_behaves_like 'a request from an extension'
end
end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.shared_examples 'a tracked vs code unique action' do |event| RSpec.shared_examples 'a request from an extension' do |event|
before do before do
stub_application_setting(usage_ping_enabled: true) stub_application_setting(usage_ping_enabled: true)
end end
...@@ -11,10 +11,12 @@ RSpec.shared_examples 'a tracked vs code unique action' do |event| ...@@ -11,10 +11,12 @@ RSpec.shared_examples 'a tracked vs code unique action' do |event|
Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: action, start_date: date_from, end_date: date_to) Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: action, start_date: date_from, end_date: date_to)
end end
it 'tracks when the user agent is from vs code' do def track_action(params)
aggregate_failures do described_class.track_api_request_when_trackable(**params)
user_agent = { user_agent: 'vs-code-gitlab-workflow/3.11.1 VSCode/1.52.1 Node.js/12.14.1 (darwin; x64)' } end
it 'tracks when the user agent is matching' do
aggregate_failures do
expect(track_action(user: user1, **user_agent)).to be_truthy expect(track_action(user: user1, **user_agent)).to be_truthy
expect(track_action(user: user1, **user_agent)).to be_truthy expect(track_action(user: user1, **user_agent)).to be_truthy
expect(track_action(user: user2, **user_agent)).to be_truthy expect(track_action(user: user2, **user_agent)).to be_truthy
...@@ -23,7 +25,7 @@ RSpec.shared_examples 'a tracked vs code unique action' do |event| ...@@ -23,7 +25,7 @@ RSpec.shared_examples 'a tracked vs code unique action' do |event|
end end
end end
it 'does not track when the user agent is not from vs code' do it 'does not track when the user agent is not matching' do
aggregate_failures do aggregate_failures do
user_agent = { user_agent: 'normal_user_agent' } user_agent = { user_agent: 'normal_user_agent' }
...@@ -40,24 +42,6 @@ RSpec.shared_examples 'a tracked vs code unique action' do |event| ...@@ -40,24 +42,6 @@ RSpec.shared_examples 'a tracked vs code unique action' do |event|
end end
it 'does not track if user is not present' do it 'does not track if user is not present' do
user_agent = { user_agent: 'vs-code-gitlab-workflow/3.11.1 VSCode/1.52.1 Node.js/12.14.1 (darwin; x64)' }
expect(track_action(user: nil, **user_agent)).to be_nil expect(track_action(user: nil, **user_agent)).to be_nil
end end
end end
RSpec.describe Gitlab::UsageDataCounters::VSCodeExtensionActivityUniqueCounter, :clean_gitlab_redis_shared_state do
let(:user1) { build(:user, id: 1) }
let(:user2) { build(:user, id: 2) }
let(:time) { Time.current }
context 'when tracking a vs code api request' do
it_behaves_like 'a tracked vs code unique action' do
let(:action) { described_class::VS_CODE_API_REQUEST_ACTION }
def track_action(params)
described_class.track_api_request_when_trackable(**params)
end
end
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