Skip to content

Commit

Permalink
Merge pull request #192 from buildkite/pie-1650/stop-sending-uuid
Browse files Browse the repository at this point in the history
Stop sending execution id
  • Loading branch information
niceking authored May 17, 2023
2 parents ff83cd1 + d43e719 commit 05f35da
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/buildkite/test_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module TestCollector
require "time"
require "timeout"
require "tmpdir"
require "securerandom"

require "active_support/core_ext/object/blank"
require "active_support/core_ext/hash/indifferent_access"
Expand All @@ -26,6 +25,7 @@ module TestCollector
require_relative "test_collector/object"
require_relative "test_collector/tracer"
require_relative "test_collector/session"
require_relative "test_collector/uuid"

module Buildkite
module TestCollector
Expand Down
4 changes: 2 additions & 2 deletions lib/buildkite/test_collector/ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def ci_env

{
"CI" => nil,
"key" => SecureRandom.uuid,
"key" => Buildkite::TestCollector::UUID.call,
}
end

Expand All @@ -44,7 +44,7 @@ def analytics_env
def generic
{
"CI" => "generic",
"key" => SecureRandom.uuid,
"key" => Buildkite::TestCollector::UUID.call,
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/buildkite/test_collector/library_hooks/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

config.after(:suite) do
if Buildkite::TestCollector.artifact_path
filename = File.join(Buildkite::TestCollector.artifact_path, "buildkite-test-collector-rspec-#{SecureRandom.uuid}.json.gz")
filename = File.join(Buildkite::TestCollector.artifact_path, "buildkite-test-collector-rspec-#{Buildkite::TestCollector::UUID.call}.json.gz")
data_set = { results: Buildkite::TestCollector.uploader.traces.values.map(&:as_hash) }
File.open(filename, "wb") do |f|
gz = Zlib::GzipWriter.new(f)
Expand Down
4 changes: 1 addition & 3 deletions lib/buildkite/test_collector/minitest_plugin/trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Buildkite::TestCollector::MinitestPlugin
class Trace
attr_accessor :example
attr_writer :failure_reason, :failure_expanded
attr_reader :id, :history
attr_reader :history

RESULT_CODES = {
'.' => 'passed',
Expand All @@ -16,7 +16,6 @@ class Trace
FILE_PATH_REGEX = /^(.*?\.(rb|feature))/

def initialize(example, history:)
@id = SecureRandom.uuid
@example = example
@history = history
end
Expand All @@ -31,7 +30,6 @@ def source_location

def as_hash
strip_invalid_utf8_chars(
id: id,
scope: example.class.name,
name: example.name,
location: location,
Expand Down
4 changes: 1 addition & 3 deletions lib/buildkite/test_collector/rspec_plugin/trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
module Buildkite::TestCollector::RSpecPlugin
class Trace
attr_accessor :example, :failure_reason, :failure_expanded
attr_reader :id, :history
attr_reader :history

FILE_PATH_REGEX = /^(.*?\.(rb|feature))/

def initialize(example, history:, failure_reason: nil, failure_expanded: [])
@id = SecureRandom.uuid
@example = example
@history = history
@failure_reason = failure_reason
Expand All @@ -25,7 +24,6 @@ def result

def as_hash
strip_invalid_utf8_chars(
id: id,
scope: example.example_group.metadata[:full_description],
name: example.description,
location: example.location,
Expand Down
12 changes: 12 additions & 0 deletions lib/buildkite/test_collector/uuid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "securerandom"

class Buildkite::TestCollector::UUID
GET_UUID = SecureRandom.method(:uuid)
private_constant :GET_UUID

def self.call
GET_UUID.call
end
end
6 changes: 3 additions & 3 deletions spec/test_collector/ci_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe Buildkite::TestCollector::CI do
describe ".env" do
let(:ci) { "true" }
let(:key) { SecureRandom.uuid }
let(:key) { Buildkite::TestCollector::UUID.call }
let(:url) { "http://example.com" }
let(:branch) { "not-main" }
let(:sha) { "a2c5ef54" }
Expand Down Expand Up @@ -239,7 +239,7 @@
before do
fake_env("CI", ci)

allow(SecureRandom).to receive(:uuid) { "845ac829-2ab3-4bbb-9e24-3529755a6d37" }
allow(Buildkite::TestCollector::UUID).to receive(:call) { "845ac829-2ab3-4bbb-9e24-3529755a6d37" }
end

it "returns all env" do
Expand Down Expand Up @@ -287,7 +287,7 @@

context "when not running on a CI platform" do
before do
allow(SecureRandom).to receive(:uuid) { "845ac829-2ab3-4bbb-9e24-3529755a6d37" }
allow(Buildkite::TestCollector::UUID).to receive(:call) { "845ac829-2ab3-4bbb-9e24-3529755a6d37" }
end

it "returns all env" do
Expand Down
1 change: 0 additions & 1 deletion spec/test_collector/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
},
"format": "json",
"data": [{
"id": trace.id,
"scope": "i love to eat pies",
"name": "mince and cheese",
"location": "123 Pie St",
Expand Down

0 comments on commit 05f35da

Please sign in to comment.