diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-22 21:10:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-22 21:10:55 +0300 |
commit | 39cc8695fc20e17f4989fa99aa9fafc00f9e2953 (patch) | |
tree | 66c4e9cb60b92f2b82737710789a0f99cbcfb58a /app/services/service_ping | |
parent | ad765b15d8b18af8ebf26a740f679a9b3c543c1a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/service_ping')
-rw-r--r-- | app/services/service_ping/devops_report_service.rb | 29 | ||||
-rw-r--r-- | app/services/service_ping/submit_service.rb | 40 |
2 files changed, 41 insertions, 28 deletions
diff --git a/app/services/service_ping/devops_report_service.rb b/app/services/service_ping/devops_report_service.rb new file mode 100644 index 00000000000..4c5bce17b71 --- /dev/null +++ b/app/services/service_ping/devops_report_service.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module ServicePing + class DevopsReportService + 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 initialize(data) + @data = data + end + + def execute + metrics = @data['conv_index'] || @data['dev_ops_score'] # leaving dev_ops_score here, as the data comes from the gitlab-version-com + + return unless metrics.except('usage_data_id').present? + + DevOpsReport::Metric.create!( + metrics.slice(*METRICS) + ) + end + end +end diff --git a/app/services/service_ping/submit_service.rb b/app/services/service_ping/submit_service.rb index 63e01603d47..d3d9dcecb2b 100644 --- a/app/services/service_ping/submit_service.rb +++ b/app/services/service_ping/submit_service.rb @@ -6,29 +6,23 @@ module ServicePing STAGING_BASE_URL = 'https://gitlab-services-version-gitlab-com-staging.gs-staging.gitlab.org' USAGE_DATA_PATH = 'usage_data' - 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 - SubmissionError = Class.new(StandardError) + def initialize(skip_db_write: false) + @skip_db_write = skip_db_write + end + def execute return unless ServicePing::ServicePingSettings.product_intelligence_enabled? begin usage_data = BuildPayloadService.new.execute - raw_usage_data, response = submit_usage_data_payload(usage_data) + response = submit_usage_data_payload(usage_data) rescue StandardError return unless Gitlab::CurrentSettings.usage_ping_enabled? usage_data = Gitlab::UsageData.data(force_refresh: true) - raw_usage_data, response = submit_usage_data_payload(usage_data) + response = submit_usage_data_payload(usage_data) end version_usage_data_id = response.dig('conv_index', 'usage_data_id') || response.dig('dev_ops_score', 'usage_data_id') @@ -37,9 +31,11 @@ module ServicePing raise SubmissionError, "Invalid usage_data_id in response: #{version_usage_data_id}" end - raw_usage_data.update_version_metadata!(usage_data_id: version_usage_data_id) - - store_metrics(response) + unless @skip_db_write + raw_usage_data = save_raw_usage_data(usage_data) + raw_usage_data.update_version_metadata!(usage_data_id: version_usage_data_id) + DevopsReportService.new(response).execute + end end def url @@ -60,13 +56,11 @@ module ServicePing def submit_usage_data_payload(usage_data) raise SubmissionError, 'Usage data is blank' if usage_data.blank? - raw_usage_data = save_raw_usage_data(usage_data) - response = submit_payload(usage_data) raise SubmissionError, "Unsuccessful response code: #{response.code}" unless response.success? - [raw_usage_data, response] + response end def save_raw_usage_data(usage_data) @@ -75,16 +69,6 @@ module ServicePing end end - def store_metrics(response) - metrics = response['conv_index'] || response['dev_ops_score'] # leaving dev_ops_score here, as the response data comes from the gitlab-version-com - - return unless metrics.except('usage_data_id').present? - - DevOpsReport::Metric.create!( - metrics.slice(*METRICS) - ) - end - # See https://gitlab.com/gitlab-org/gitlab/-/issues/233615 for details def base_url Rails.env.production? ? PRODUCTION_BASE_URL : STAGING_BASE_URL |