2021-11-22 13:10:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ServicePing
|
2022-05-13 20:08:57 -04:00
|
|
|
class DevopsReport
|
2021-11-22 13:10:55 -05:00
|
|
|
def initialize(data)
|
|
|
|
@data = data
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2021-11-30 13:14:49 -05:00
|
|
|
# `conv_index` was previously named `dev_ops_score` in
|
|
|
|
# version-gitlab-com, so we check both for backwards compatibility.
|
|
|
|
metrics = @data['conv_index'] || @data['dev_ops_score']
|
2021-11-22 13:10:55 -05:00
|
|
|
|
2021-11-30 13:14:49 -05:00
|
|
|
# Do not attempt to save a report for the first Service Ping
|
|
|
|
# response for a given GitLab instance, which comes without
|
|
|
|
# metrics.
|
|
|
|
return if metrics.keys == ['usage_data_id']
|
2021-11-22 13:10:55 -05:00
|
|
|
|
2021-11-30 13:14:49 -05:00
|
|
|
report = DevOpsReport::Metric.create(
|
|
|
|
metrics.slice(*DevOpsReport::Metric::METRICS)
|
2021-11-22 13:10:55 -05:00
|
|
|
)
|
2021-11-30 13:14:49 -05:00
|
|
|
|
2022-05-13 20:08:57 -04:00
|
|
|
unless report.persisted?
|
|
|
|
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(
|
|
|
|
ActiveRecord::RecordInvalid.new(report)
|
|
|
|
)
|
|
|
|
end
|
2021-11-22 13:10:55 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|