From a7007caac31dc9d48812b34e1c642554d77065c2 Mon Sep 17 00:00:00 2001 From: niceking Date: Mon, 17 Apr 2023 11:03:22 +1200 Subject: [PATCH 1/3] gzip body of upload request --- lib/buildkite/test_collector/http_client.rb | 11 ++++++++++- spec/test_collector/http_client_spec.rb | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/buildkite/test_collector/http_client.rb b/lib/buildkite/test_collector/http_client.rb index ae5b6cc..384b77c 100644 --- a/lib/buildkite/test_collector/http_client.rb +++ b/lib/buildkite/test_collector/http_client.rb @@ -19,16 +19,25 @@ def post_json(data) contact = Net::HTTP::Post.new(contact_uri.path, { "Authorization" => authorization_header, "Content-Type" => "application/json", + "Content-Encoding" => "gzip", }) data_set = data.map(&:as_hash) - contact.body = { + body = { run_env: Buildkite::TestCollector::CI.env, format: "json", data: data_set }.to_json + compressed_body = StringIO.new + + writer = Zlib::GzipWriter.new(compressed_body) + writer.write(body) + writer.close + + contact.body = compressed_body.string + http.request(contact) end diff --git a/spec/test_collector/http_client_spec.rb b/spec/test_collector/http_client_spec.rb index e44175c..9fed5e1 100644 --- a/spec/test_collector/http_client_spec.rb +++ b/spec/test_collector/http_client_spec.rb @@ -46,7 +46,7 @@ allow(Net::HTTP).to receive(:new).and_return(http_double) allow(http_double).to receive(:use_ssl=) - allow(Net::HTTP::Post).to receive(:new).with("buildkite.localhost", {"Authorization"=>"Token token=\"my-cool-token\"", "Content-Type"=>"application/json"}).and_return(post_double) + allow(Net::HTTP::Post).to receive(:new).with("buildkite.localhost", {"Authorization"=>"Token token=\"my-cool-token\"", "Content-Encoding"=>"gzip", "Content-Type"=>"application/json"}).and_return(post_double) allow(ENV).to receive(:[]).and_call_original fake_env("BUILDKITE_ANALYTICS_KEY", "build-123") From d81849a58bc95ee7c07fe41c4995940e7d1910e1 Mon Sep 17 00:00:00 2001 From: niceking Date: Wed, 19 Apr 2023 14:24:08 +1200 Subject: [PATCH 2/3] use ECR Public Gallery via pull-through cache for image --- buildkite.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildkite.yaml b/buildkite.yaml index e400aa6..dbde11b 100644 --- a/buildkite.yaml +++ b/buildkite.yaml @@ -5,4 +5,4 @@ steps: - "bundle exec rake" plugins: - docker#v3.7.0: - image: ruby:latest + image: 445615400570.dkr.ecr.us-east-1.amazonaws.com/ecr-public/docker/library/ruby:3.1.4 From 723d021dff49ca7101a66353cf14db628a4c9f5e Mon Sep 17 00:00:00 2001 From: niceking Date: Wed, 19 Apr 2023 14:33:18 +1200 Subject: [PATCH 3/3] change spec to expect compressed body --- spec/test_collector/http_client_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/test_collector/http_client_spec.rb b/spec/test_collector/http_client_spec.rb index 9fed5e1..9891e9e 100644 --- a/spec/test_collector/http_client_spec.rb +++ b/spec/test_collector/http_client_spec.rb @@ -39,7 +39,17 @@ "failure_expanded": [], "history": "pie lore" }] - } + }.to_json + end + + let(:compressed_body) do + str = StringIO.new + + writer = Zlib::GzipWriter.new(str) + writer.write(request_body) + writer.close + + str.string end before do @@ -62,7 +72,7 @@ describe "#post_json" do it "sends the right data" do - expect(post_double).to receive(:body=).with(request_body.to_json) + expect(post_double).to receive(:body=).with(compressed_body) expect(http_double).to receive(:request).with(post_double) subject.post_json([trace]) end