summaryrefslogtreecommitdiff
path: root/app/services/service_ping/build_payload_service.rb
blob: f4ae939fd070d0c9311b9a7f1578a5342692557e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module ServicePing
  class BuildPayloadService
    def execute
      return {} unless allowed_to_report?

      raw_payload
    end

    private

    def allowed_to_report?
      product_intelligence_enabled? && !User.single_user&.requires_usage_stats_consent?
    end

    def product_intelligence_enabled?
      ::Gitlab::CurrentSettings.usage_ping_enabled?
    end

    def raw_payload
      @raw_payload ||= ::Gitlab::Usage::ServicePingReport.for(output: :all_metrics_values)
    end
  end
end

ServicePing::BuildPayloadService.prepend_mod_with('ServicePing::BuildPayloadService')