summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-04-05 13:49:22 +0100
committerRémy Coutable <remy@rymai.me>2017-04-14 15:20:55 +0200
commitc53afeda0c2ee0cda89c235c9e8799baa1cfdc1a (patch)
tree7efaef06c5ec20fc87fe6dadf1a794c8ef00f187
parentf5b42881c88678cd85ea7743fdffa400105b4b8d (diff)
downloadgitlab-ce-c53afeda0c2ee0cda89c235c9e8799baa1cfdc1a.tar.gz
Port 'Add uuid to usage ping' to CE
CE port of https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1521
-rw-r--r--db/migrate/20170328010804_add_uuid_to_application_settings.rb16
-rw-r--r--db/schema.rb1
-rw-r--r--lib/gitlab/usage_data.rb5
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb4
4 files changed, 24 insertions, 2 deletions
diff --git a/db/migrate/20170328010804_add_uuid_to_application_settings.rb b/db/migrate/20170328010804_add_uuid_to_application_settings.rb
new file mode 100644
index 00000000000..5dfcc751c7b
--- /dev/null
+++ b/db/migrate/20170328010804_add_uuid_to_application_settings.rb
@@ -0,0 +1,16 @@
+class AddUuidToApplicationSettings < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_column :application_settings, :uuid, :string
+ execute("UPDATE application_settings SET uuid = #{quote(SecureRandom.uuid)}")
+ end
+
+ def down
+ remove_column :application_settings, :uuid
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 7c5bb94dfb0..1c592dd5d6d 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -117,6 +117,7 @@ ActiveRecord::Schema.define(version: 20170408033905) do
t.boolean "unique_ips_limit_enabled", default: false, null: false
t.decimal "polling_interval_multiplier", default: 1.0, null: false
t.boolean "usage_ping_enabled", default: true, null: false
+ t.string "uuid"
end
create_table "audit_events", force: :cascade do |t|
diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb
index ae1ae82ab4c..46875908fa3 100644
--- a/lib/gitlab/usage_data.rb
+++ b/lib/gitlab/usage_data.rb
@@ -1,5 +1,7 @@
module Gitlab
class UsageData
+ include Gitlab::CurrentSettings
+
class << self
def data
Rails.cache.fetch('usage_data', expires_in: 1.hour) { uncached_data }
@@ -45,7 +47,8 @@ module Gitlab
end
def license_usage_data
- usage_data = { version: Gitlab::VERSION,
+ usage_data = { uuid: current_application_settings.uuid,
+ version: Gitlab::VERSION,
active_user_count: User.active.count,
recorded_at: Time.now,
mattermost_enabled: Gitlab.config.mattermost.enabled }
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index 2cb5d49c4c1..920135f79b4 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -12,9 +12,10 @@ describe Gitlab::UsageData do
expect(subject.keys).to match_array(%i(
active_user_count
counts
- version
recorded_at
mattermost_enabled
+ version
+ uuid
))
end
@@ -57,6 +58,7 @@ describe Gitlab::UsageData do
subject { Gitlab::UsageData.license_usage_data }
it "gathers license data" do
+ expect(subject[:uuid]).to eq(current_application_settings.uuid)
expect(subject[:version]).to eq(Gitlab::VERSION)
expect(subject[:active_user_count]).to eq(User.active.count)
expect(subject[:recorded_at]).to be_a(Time)