Class: Gitlab::RSpecMetricsExporter::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/rspec_metrics_exporter/client.rb

Defined Under Namespace

Classes: ResponseError

Constant Summary collapse

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

Constructor Details

#initialize(url:, token:) ⇒ Client

Returns a new instance of Client.



17
18
19
20
# File 'lib/gitlab/rspec_metrics_exporter/client.rb', line 17

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.

Parameters:

  • tests (Array<Hash>)

Returns:

  • (Boolean)

    true when every batch succeeds (or input is empty)

Raises:



29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/rspec_metrics_exporter/client.rb', line 29

def post_tests(tests) # rubocop:disable Naming/PredicateMethod
  tests.each_slice(MAX_BATCH_SIZE) do |batch|
    response = post_batch(batch)
    next if (200..299).cover?(response.code.to_i)

    raise ResponseError, "Observer request failed with status #{response.code}: #{response.body}"
  end

  true
end