From cf93bbad8f2b673baff42c441aa3be33d7a7eadc Mon Sep 17 00:00:00 2001 From: Stan Hu <stanhu@gmail.com> Date: Wed, 20 Jul 2016 10:04:33 -0700 Subject: [PATCH] Display the JSON payload in settings page for EE usage ping --- CHANGELOG-EE | 1 + app/helpers/license_helper.rb | 19 +++++++++++++++++ .../application_settings/_form.html.haml | 3 ++- app/workers/gitlab_usage_ping_worker.rb | 21 +------------------ spec/helpers/license_helper_spec.rb | 18 ++++++++++++++++ spec/workers/gitlab_usage_ping_worker_spec.rb | 16 -------------- 6 files changed, 41 insertions(+), 37 deletions(-) diff --git a/CHANGELOG-EE b/CHANGELOG-EE index c005d1a88adcb..a4686a29b93e5 100644 --- a/CHANGELOG-EE +++ b/CHANGELOG-EE @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.10.0 (unreleased) + - Add EE license usage ping !557 - Rename Git Hooks to Push Rules - Fix EE keys fingerprint add index migration if came from CE - Add todos for MR approvers !547 diff --git a/app/helpers/license_helper.rb b/app/helpers/license_helper.rb index c61da2eac31c2..a09e1656b61ff 100644 --- a/app/helpers/license_helper.rb +++ b/app/helpers/license_helper.rb @@ -17,6 +17,25 @@ def license_message(signed_in: signed_in?, is_admin: (current_user && current_us end end + def license_usage_data + usage_data = { version: Gitlab::VERSION, + active_user_count: current_active_user_count } + license = License.current + + if license + usage_data[:license_md5] = Digest::MD5.hexdigest(license.data) + usage_data[:historical_max_users] = max_historical_user_count + usage_data[:licensee] = license.licensee + usage_data[:license_user_count] = license.user_count + usage_data[:license_starts_at] = license.starts_at + usage_data[:license_expires_at] = license.expires_at + usage_data[:license_add_ons] = license.add_ons + usage_data[:recorded_at] = Time.now + end + + usage_data + end + private def no_license_message(signed_in, is_admin) diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index a8e15a4f70797..a381da0eb7b04 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -63,7 +63,8 @@ Usage ping enabled .help-block Every week GitLab will report license usage back to GitLab, Inc. - Disable this option if you do not want this to occur. + Disable this option if you do not want this to occur. This is the JSON payload that will be sent: + %pre.js-syntax-highlight.code.highlight= Gitlab::Highlight.highlight('payload.json', license_usage_data.to_json) .form-group .col-sm-offset-2.col-sm-10 .checkbox diff --git a/app/workers/gitlab_usage_ping_worker.rb b/app/workers/gitlab_usage_ping_worker.rb index 27fe2465055ff..3d0649c551e31 100644 --- a/app/workers/gitlab_usage_ping_worker.rb +++ b/app/workers/gitlab_usage_ping_worker.rb @@ -16,7 +16,7 @@ def perform begin HTTParty.post(url, - body: data.to_json, + body: license_usage_data.to_json, headers: { 'Content-type' => 'application/json' } ) rescue HTTParty::Error => e @@ -28,25 +28,6 @@ def try_obtain_lease Gitlab::ExclusiveLease.new('gitlab_usage_ping_worker:ping', timeout: LEASE_TIMEOUT).try_obtain end - def data - usage_data = { version: Gitlab::VERSION, - active_user_count: current_active_user_count } - license = License.current - - if license - usage_data[:license_md5] = Digest::MD5.hexdigest(license.data) - usage_data[:historical_max_users] = max_historical_user_count - usage_data[:licensee] = license.licensee - usage_data[:license_user_count] = license.user_count - usage_data[:license_starts_at] = license.starts_at - usage_data[:license_expires_at] = license.expires_at - usage_data[:license_add_ons] = license.add_ons - usage_data[:recorded_at] = Time.now - end - - usage_data - end - def url 'https://version.gitlab.com/usage_data' end diff --git a/spec/helpers/license_helper_spec.rb b/spec/helpers/license_helper_spec.rb index f2a94a79cd275..17e0459f258fa 100644 --- a/spec/helpers/license_helper_spec.rb +++ b/spec/helpers/license_helper_spec.rb @@ -20,4 +20,22 @@ end end end + + describe '#license_usage_data' do + it "gathers license data" do + data = license_usage_data + license = License.current + + expect(data[:license_md5]).to eq(Digest::MD5.hexdigest(license.data)) + expect(data[:version]).to eq(Gitlab::VERSION) + expect(data[:licensee]).to eq(license.licensee) + expect(data[:active_user_count]).to eq(User.active.count) + expect(data[:licensee]).to eq(license.licensee) + expect(data[:license_user_count]).to eq(license.user_count) + expect(data[:license_starts_at]).to eq(license.starts_at) + expect(data[:license_expires_at]).to eq(license.expires_at) + expect(data[:license_add_ons]).to eq(license.add_ons) + expect(data[:recorded_at]).to be_a(Time) + end + end end diff --git a/spec/workers/gitlab_usage_ping_worker_spec.rb b/spec/workers/gitlab_usage_ping_worker_spec.rb index 0447af1ae55a7..8821df3d81e8d 100644 --- a/spec/workers/gitlab_usage_ping_worker_spec.rb +++ b/spec/workers/gitlab_usage_ping_worker_spec.rb @@ -3,22 +3,6 @@ describe GitlabUsagePingWorker do subject { GitlabUsagePingWorker.new } - it "gathers license data" do - data = subject.data - license = License.current - - expect(data[:license_md5]).to eq(Digest::MD5.hexdigest(license.data)) - expect(data[:version]).to eq(Gitlab::VERSION) - expect(data[:licensee]).to eq(license.licensee) - expect(data[:active_user_count]).to eq(User.active.count) - expect(data[:licensee]).to eq(license.licensee) - expect(data[:license_user_count]).to eq(license.user_count) - expect(data[:license_starts_at]).to eq(license.starts_at) - expect(data[:license_expires_at]).to eq(license.expires_at) - expect(data[:license_add_ons]).to eq(license.add_ons) - expect(data[:recorded_at]).to be_a(Time) - end - it "sends POST request" do stub_application_setting(usage_ping_enabled: true) -- GitLab