2018-07-05 06:18:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-24 06:25:44 -04:00
|
|
|
class SubmitUsagePingService
|
2019-08-31 15:22:19 -04:00
|
|
|
URL = 'https://version.gitlab.com/usage_data'
|
2017-05-24 06:25:44 -04:00
|
|
|
|
2017-08-01 02:46:43 -04:00
|
|
|
METRICS = %w[leader_issues instance_issues percentage_issues leader_notes instance_notes
|
|
|
|
percentage_notes leader_milestones instance_milestones percentage_milestones
|
|
|
|
leader_boards instance_boards percentage_boards leader_merge_requests
|
|
|
|
instance_merge_requests percentage_merge_requests leader_ci_pipelines
|
|
|
|
instance_ci_pipelines percentage_ci_pipelines leader_environments instance_environments
|
|
|
|
percentage_environments leader_deployments instance_deployments percentage_deployments
|
|
|
|
leader_projects_prometheus_active instance_projects_prometheus_active
|
|
|
|
percentage_projects_prometheus_active leader_service_desk_issues instance_service_desk_issues
|
|
|
|
percentage_service_desk_issues].freeze
|
|
|
|
|
2017-05-24 06:25:44 -04:00
|
|
|
def execute
|
2018-02-02 13:39:55 -05:00
|
|
|
return false unless Gitlab::CurrentSettings.usage_ping_enabled?
|
2018-09-07 10:32:28 -04:00
|
|
|
return false if User.single_user&.requires_usage_stats_consent?
|
2017-05-24 06:25:44 -04:00
|
|
|
|
2018-03-13 18:38:25 -04:00
|
|
|
response = Gitlab::HTTP.post(
|
2017-05-24 06:25:44 -04:00
|
|
|
URL,
|
|
|
|
body: Gitlab::UsageData.to_json(force_refresh: true),
|
2018-03-13 18:38:25 -04:00
|
|
|
allow_local_requests: true,
|
2017-05-24 06:25:44 -04:00
|
|
|
headers: { 'Content-type' => 'application/json' }
|
|
|
|
)
|
|
|
|
|
|
|
|
store_metrics(response)
|
|
|
|
|
|
|
|
true
|
2018-03-13 18:38:25 -04:00
|
|
|
rescue Gitlab::HTTP::Error => e
|
2019-07-10 15:26:47 -04:00
|
|
|
Rails.logger.info "Unable to contact GitLab, Inc.: #{e}" # rubocop:disable Gitlab/RailsLogger
|
2017-05-24 06:25:44 -04:00
|
|
|
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def store_metrics(response)
|
2020-01-22 07:08:40 -05:00
|
|
|
metrics = response['conv_index'] || response['dev_ops_score']
|
|
|
|
|
|
|
|
return unless metrics.present?
|
2017-05-24 06:25:44 -04:00
|
|
|
|
2019-12-03 04:09:09 -05:00
|
|
|
DevOpsScore::Metric.create!(
|
2020-01-22 07:08:40 -05:00
|
|
|
metrics.slice(*METRICS)
|
2017-05-24 06:25:44 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|