Skip to content
Snippets Groups Projects
Commit 95e4a760 authored by Doug Barrett's avatar Doug Barrett :two: Committed by Peter Leitzen
Browse files

Simplify send_telemetry method signature

parent 80afda25
No related branches found
No related tags found
1 merge request!4507Simplify send_telemetry method signature
......@@ -26,7 +26,13 @@ module GDK
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
send_telemetry(result, command, {
send_telemetry(result, command, duration: duration)
result
end
def self.send_telemetry(success, command, duration:)
payload = {
duration: duration,
environment: environment,
platform: GDK::Machine.platform,
......@@ -34,12 +40,8 @@ module GDK
version_manager: version_manager,
team_member: team_member?,
session_id: session_id
})
result
end
}
def self.send_telemetry(success, command, payload = {})
# This is tightly coupled to GDK commands and returns false when the system call exits with a non-zero status.
status = success ? 'Finish' : 'Failed'
......@@ -131,7 +133,7 @@ module GDK
# This should only be used for telemetry and NEVER for authentication.
def self.team_member?
Shellout.new(%w[git config --get user.email], chdir: GDK.config.gdk_root)
.run.include?('@gitlab.com')
.run.include?('@gitlab.com')
end
def self.update_settings(username)
......
......@@ -25,7 +25,7 @@ module Support
return unless GDK::Telemetry.telemetry_enabled?
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - @telemetry_start
GDK::Telemetry.send_telemetry(success, telemetry_name, { duration: duration, environment: GDK::Telemetry.environment, platform: GDK::Machine.platform, architecture: GDK::Machine.architecture })
GDK::Telemetry.send_telemetry(success, telemetry_name, duration: duration)
end
end
end
......
......@@ -11,7 +11,10 @@ RSpec.describe Support::Rake::TaskWithTelemetry do
let(:telemetry) { false }
before do
allow(GDK::Telemetry).to receive(:telemetry_enabled?).and_return(telemetry)
allow(GDK::Telemetry).to receive_messages(
telemetry_enabled?: telemetry,
team_member?: true
)
end
it 'does not send telemetry' do
......@@ -29,12 +32,7 @@ RSpec.describe Support::Rake::TaskWithTelemetry do
it 'sends telemetry' do
task = new_task
expect(GDK::Telemetry).to receive(:send_telemetry).with(true, 'rake test-task', hash_including(
:duration,
environment: GDK::Telemetry.environment,
platform: GDK::Machine.platform,
architecture: GDK::Machine.architecture
))
expect(GDK::Telemetry).to receive(:send_telemetry).with(true, 'rake test-task', hash_including(:duration))
task.invoke
end
......@@ -45,12 +43,7 @@ RSpec.describe Support::Rake::TaskWithTelemetry do
raise StandardError
end
expect(GDK::Telemetry).to receive(:send_telemetry).with(false, 'rake test-task', hash_including(
:duration,
environment: GDK::Telemetry.environment,
platform: GDK::Machine.platform,
architecture: GDK::Machine.architecture
))
expect(GDK::Telemetry).to receive(:send_telemetry).with(false, 'rake test-task', hash_including(:duration))
expect { task.invoke }.to raise_error(StandardError)
end
......
......@@ -44,7 +44,8 @@ class SetupWorkspace
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
configure_gdk
success = GDK::Shellout.new('support/gitlab-remote-development/remote-development-gdk-bootstrap.sh', chdir: ROOT_DIR).execute
success = GDK::Shellout.new('support/gitlab-remote-development/remote-development-gdk-bootstrap.sh',
chdir: ROOT_DIR).execute
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
[success, duration]
......@@ -78,7 +79,7 @@ class SetupWorkspace
end
def send_telemetry(success, duration)
GDK::Telemetry.send_telemetry(success, 'setup-workspace', { duration: duration, environment: 'remote-development', platform: GDK::Machine.platform, architecture: GDK::Machine.architecture })
GDK::Telemetry.send_telemetry(success, 'setup-workspace', duration: duration)
GDK::Telemetry.flush_events
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment