Port 'Add uuid to usage ping' to CE

CE port of https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1521
This commit is contained in:
Sean McGivern 2017-04-05 13:49:22 +01:00 committed by Rémy Coutable
parent f5b42881c8
commit c53afeda0c
4 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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|

View File

@ -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 }

View File

@ -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)