Class: Gitlab::RSpecMetricsExporter::Client
- Inherits:
-
Object
- Object
- Gitlab::RSpecMetricsExporter::Client
- 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
-
#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.
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.
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 |