debian-mirror-gitlab/app/services/submit_usage_ping_service.rb

46 lines
1.6 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
class SubmitUsagePingService
2019-12-04 20:38:33 +05:30
URL = 'https://version.gitlab.com/usage_data'
2017-09-10 17:25:29 +05:30
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
def execute
2018-03-17 18:26:18 +05:30
return false unless Gitlab::CurrentSettings.usage_ping_enabled?
2018-11-20 20:47:30 +05:30
return false if User.single_user&.requires_usage_stats_consent?
2017-09-10 17:25:29 +05:30
2018-03-26 14:24:53 +05:30
response = Gitlab::HTTP.post(
2017-09-10 17:25:29 +05:30
URL,
body: Gitlab::UsageData.to_json(force_refresh: true),
2018-03-26 14:24:53 +05:30
allow_local_requests: true,
2017-09-10 17:25:29 +05:30
headers: { 'Content-type' => 'application/json' }
)
store_metrics(response)
true
2018-03-26 14:24:53 +05:30
rescue Gitlab::HTTP::Error => e
2019-09-30 21:07:59 +05:30
Rails.logger.info "Unable to contact GitLab, Inc.: #{e}" # rubocop:disable Gitlab/RailsLogger
2017-09-10 17:25:29 +05:30
false
end
private
def store_metrics(response)
return unless response['conv_index'].present?
ConversationalDevelopmentIndex::Metric.create!(
response['conv_index'].slice(*METRICS)
)
end
end