Class: GitlabQuality::TestTooling::TestMetricsExporter::Client
- Inherits:
-
Object
- Object
- GitlabQuality::TestTooling::TestMetricsExporter::Client
- Defined in:
- lib/gitlab_quality/test_tooling/test_metrics_exporter/client.rb
Constant Summary collapse
- ResponseError =
Class.new(StandardError)
- TESTS_PATH =
"/api/v1/tests"- MAX_BATCH_SIZE =
Observer enforces a per-request cap; batch above this size to avoid silent failures.
10_000
Instance Method Summary collapse
-
#initialize(url:, token:) ⇒ Client
constructor
A new instance of Client.
-
#post_tests(tests) ⇒ Boolean
POST array of test metric records to the observer service.
Constructor Details
#initialize(url:, token:) ⇒ Client
Returns a new instance of Client.
16 17 18 19 |
# File 'lib/gitlab_quality/test_tooling/test_metrics_exporter/client.rb', line 16 def initialize(url:, token:) @url = url @token = token end |
Instance Method Details
#post_tests(tests) ⇒ Boolean
POST array of test metric records to the observer service. Wraps each batch as { “tests” => […] } and splits oversized payloads into chunks of at most MAX_BATCH_SIZE records.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gitlab_quality/test_tooling/test_metrics_exporter/client.rb', line 28 def post_tests(tests) tests.each_slice(MAX_BATCH_SIZE) do |batch| response = HTTParty.post( "#{url.to_s.chomp('/')}#{TESTS_PATH}", body: { tests: batch }.to_json, headers: { "X-Gitlab-Token" => token, "Content-Type" => "application/json" } ) raise ResponseError, "Observer request failed with status #{response.code}: #{response.body}" unless response.success? end true end |