buildkite-test_collector 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96fb0d0c08ff10d420388b2438ae199c7fbf72878d1fa5631c68b27e70f11cac
4
- data.tar.gz: 78846d669900e535d1e03bd7494611dd124f2c1bae59471ad41b5b0d9f1efb1b
3
+ metadata.gz: '09168f300d0d7fe87764a70906ac21693f9de504b68ac9cc547e42481d370173'
4
+ data.tar.gz: 3daa78abca6baab5cf000a01e1e49e699c02575ad7c10d4ac0d3aae9d0a760ef
5
5
  SHA512:
6
- metadata.gz: c7151f06cf10d7aeb296b9d8c9294f9cdab0b07fc01112176cdc28ad55f7b65d4aa51fcc21dfd179eb58bc6c69592583f58335dece7f3b46ac1e2ba7718da369
7
- data.tar.gz: cb1157c4a4cfaa719d852f2ac271bd09bbd25a461b4f6a9c002063d7461e3bb06e8107342cceb77dada1cda8090c3643aa3e2827aac7355fea90b51bbae4f7f0
6
+ metadata.gz: dbe1aa57f2b575a339bc2af259bdac5f73e98075b75de6dfb711f97262ea90c10284f06792e49e88462405bacc8e916fd5b6e0f138a073e4db9569cf147c5ca0
7
+ data.tar.gz: 49e27c93a9e23c4d6d38384f2a1dbe1be93d88b7e86a19b462fe942041bbac8da4e3adb47b9482f6741ed7faf96850ef4990e4733ecc21ee3f077c15d6c6176b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v1.1.2
4
+
5
+ - Remove branch reference prefix in Github Actions #136 - @gchan
6
+ - Make ruby collector work better for non-web app #128 - @JuanitoFatas
7
+ - Avoid linters complaining about double quotes #137 - @SocalNick
8
+ - Revert "Allow specifying run name prefix and suffix" #139 - @JuanitoFatas
9
+ - Update Code of Conduct contact email address #143 - @JuanitoFatas
10
+ - Suppress errors when connecting to Buildkite #145 - @swebb
11
+ - Add some design documentation to understand how the gem works #146 - @swebb
12
+ - Fix logging level from debug to error #147 - @gchan
13
+
3
14
  ## v1.1.1
4
15
 
5
16
  - Strip CR/LF from token input #127 - @gchan
data/CODE_OF_CONDUCT.md CHANGED
@@ -61,7 +61,7 @@ representative at an online or offline event.
61
61
 
62
62
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
63
  reported to the community leaders responsible for enforcement at
64
- `support+analytics@buildkite.com`.
64
+ [coc@buildkite.com](mailto:coc@buildkite.com).
65
65
  All complaints will be reviewed and investigated promptly and fairly.
66
66
 
67
67
  All community leaders are obligated to respect the privacy and security of the
data/DESIGN.md ADDED
@@ -0,0 +1,19 @@
1
+ # Design
2
+
3
+ ## Threads
4
+
5
+ The Buildkite ruby collector uses websockets and ActionCable to send and
6
+ receive data with Buildkite. Execution information starts transmitting as soon
7
+ as possible, without waiting for the test suite to finish running.
8
+
9
+ This gem uses 3 ruby threads:
10
+
11
+ * main thread: acts as the producer. It collects span data from the
12
+ test suite and enqueues it into the send queue.
13
+ * write thread: acts as the consumer. Removes data from the send queue and
14
+ sends it to Buildkite.
15
+ * read thread: receives and processes messages from Buildkite.
16
+
17
+ ## Data
18
+
19
+ Trace data is stored in spans. See [Buildkite::TestCollector::Tracer](lib/buildkite/test_collector/tracer.rb) for more information.
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or add this to your Gemfile’s test group:
22
22
 
23
23
  ```ruby
24
24
  group :test do
25
- gem "buildkite-test_collector"
25
+ gem 'buildkite-test_collector'
26
26
  end
27
27
  ```
28
28
 
@@ -34,7 +34,7 @@ Add the following code to your RSpec setup file:
34
34
 
35
35
  ```ruby
36
36
  # spec/spec_helper.rb
37
- require "buildkite/test_collector"
37
+ require 'buildkite/test_collector'
38
38
  Buildkite::TestCollector.configure(hook: :rspec)
39
39
  ```
40
40
 
@@ -50,7 +50,7 @@ Add the following code to your Minitest setup file:
50
50
 
51
51
  ```ruby
52
52
  # test/test_helper.rb
53
- require "buildkite/test_collector"
53
+ require 'buildkite/test_collector'
54
54
  Buildkite::TestCollector.configure(hook: :minitest)
55
55
  ```
56
56
 
@@ -94,6 +94,8 @@ bundle exec rspec
94
94
 
95
95
  Useful resources for developing collectors include the [Buildkite Test Analytics docs](https://buildkite.com/docs/test-analytics).
96
96
 
97
+ See [DESIGN.md](DESIGN.md) for an overview of the design of this gem.
98
+
97
99
  ## 👩‍💻 Contributing
98
100
 
99
101
  Bug reports and pull requests are welcome on GitHub at https://github.com/buildkite/test-collector-ruby
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "securerandom"
4
-
5
3
  class Buildkite::TestCollector::CI
6
4
  def self.env
7
5
  new.env
@@ -39,9 +37,7 @@ class Buildkite::TestCollector::CI
39
37
  "debug" => ENV["BUILDKITE_ANALYTICS_DEBUG_ENABLED"],
40
38
  "version" => Buildkite::TestCollector::VERSION,
41
39
  "collector" => Buildkite::TestCollector::NAME,
42
- "run_name_prefix" => ENV["BUILDKITE_ANALYTICS_RUN_NAME_PREFIX"],
43
- "run_name_suffix" => ENV["BUILDKITE_ANALYTICS_RUN_NAME_SUFFIX"],
44
- }.compact
40
+ }.compact
45
41
  end
46
42
 
47
43
  def generic
@@ -69,7 +65,7 @@ class Buildkite::TestCollector::CI
69
65
  "CI" => "github_actions",
70
66
  "key" => "#{ENV["GITHUB_ACTION"]}-#{ENV["GITHUB_RUN_NUMBER"]}-#{ENV["GITHUB_RUN_ATTEMPT"]}",
71
67
  "url" => File.join("https://github.com", ENV["GITHUB_REPOSITORY"], "actions/runs", ENV["GITHUB_RUN_ID"]),
72
- "branch" => ENV["GITHUB_REF"],
68
+ "branch" => ENV["GITHUB_REF_NAME"],
73
69
  "commit_sha" => ENV["GITHUB_SHA"],
74
70
  "number" => ENV["GITHUB_RUN_NUMBER"],
75
71
  }
@@ -0,0 +1,4 @@
1
+ module Buildkite::TestCollector
2
+ class Error < StandardError; end
3
+ class TimeoutError < ::Timeout::Error; end
4
+ end
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "minitest"
4
4
 
5
- require_relative "../uploader"
6
5
  require_relative "../minitest_plugin"
7
6
 
8
7
  Buildkite::TestCollector.uploader = Buildkite::TestCollector::Uploader
@@ -13,4 +12,4 @@ end
13
12
 
14
13
  Buildkite::TestCollector.enable_tracing!
15
14
 
16
- Buildkite::TestCollector::Uploader.configure
15
+ Buildkite::TestCollector.safe { Buildkite::TestCollector::Uploader.configure }
@@ -3,7 +3,6 @@
3
3
  require "rspec/core"
4
4
  require "rspec/expectations"
5
5
 
6
- require_relative "../uploader"
7
6
  require_relative "../rspec_plugin/reporter"
8
7
  require_relative "../rspec_plugin/trace"
9
8
 
@@ -13,7 +12,7 @@ RSpec.configure do |config|
13
12
  config.before(:suite) do
14
13
  config.add_formatter Buildkite::TestCollector::RSpecPlugin::Reporter
15
14
 
16
- Buildkite::TestCollector::Uploader.configure
15
+ Buildkite::TestCollector.safe { Buildkite::TestCollector::Uploader.configure }
17
16
  end
18
17
 
19
18
  config.around(:each) do |example|
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "logger"
4
- require "time"
5
-
6
3
  module Buildkite::TestCollector
7
4
  class Logger < ::Logger
8
5
  class Formatter < ::Logger::Formatter
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/hash/indifferent_access"
4
-
5
3
  module Buildkite::TestCollector::MinitestPlugin
6
4
  class Trace
7
5
  attr_accessor :example
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Minitest finds this file before setup code
4
+ require_relative "tracer"
5
+
3
6
  require_relative "minitest_plugin/reporter"
4
7
  require_relative "minitest_plugin/trace"
5
8
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "time"
4
-
5
3
  module Buildkite::TestCollector::RSpecPlugin
6
4
  class Reporter
7
5
  RSpec::Core::Formatters.register self, :example_passed, :example_failed, :example_pending, :dump_summary
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/hash/indifferent_access"
4
-
5
3
  module Buildkite::TestCollector::RSpecPlugin
6
4
  class Trace
7
5
  attr_accessor :example, :failure_reason, :failure_expanded
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "socket_connection"
4
-
5
3
  module Buildkite::TestCollector
6
4
  class Session
7
5
  # Picked 75 as the magic timeout number as it's longer than the TCP timeout of 60s 🤷‍♀️
@@ -13,11 +11,11 @@ module Buildkite::TestCollector
13
11
  class InitialConnectionFailure < StandardError; end
14
12
 
15
13
  DISCONNECTED_EXCEPTIONS = [
16
- SocketConnection::HandshakeError,
14
+ Buildkite::TestCollector::SocketConnection::HandshakeError,
15
+ Buildkite::TestCollector::TimeoutError,
16
+ Buildkite::TestCollector::SocketConnection::SocketError,
17
17
  RejectedSubscription,
18
- TimeoutError,
19
18
  InitialConnectionFailure,
20
- SocketConnection::SocketError
21
19
  ]
22
20
 
23
21
  def initialize(url, authorization_header, channel)
@@ -41,7 +39,7 @@ module Buildkite::TestCollector
41
39
  begin
42
40
  reconnection_count += 1
43
41
  connect
44
- rescue TimeoutError, InitialConnectionFailure => e
42
+ rescue Buildkite::TestCollector::TimeoutError, InitialConnectionFailure => e
45
43
  Buildkite::TestCollector.logger.warn("buildkite-test_collector could not establish an initial connection with Buildkite due to #{e}. Attempting retry #{reconnection_count} of #{MAX_RECONNECTION_ATTEMPTS}...")
46
44
  if reconnection_count > MAX_RECONNECTION_ATTEMPTS
47
45
  Buildkite::TestCollector.logger.error "buildkite-test_collector could not establish an initial connection with Buildkite due to #{e.message} after #{MAX_RECONNECTION_ATTEMPTS} attempts. You may be missing some data for this test suite, please contact support if this issue persists."
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "socket"
4
- require "openssl"
5
- require "json"
6
-
7
3
  module Buildkite::TestCollector
8
4
  class SocketConnection
9
5
  class HandshakeError < StandardError; end
@@ -65,7 +61,7 @@ module Buildkite::TestCollector
65
61
 
66
62
  # Setting up a new thread that listens on the socket, and processes incoming
67
63
  # comms from the server
68
- @thread = Thread.new do
64
+ @read_thread = Thread.new do
69
65
  Buildkite::TestCollector.logger.debug("listening in on socket")
70
66
  frame = WebSocket::Frame::Incoming::Client.new
71
67
 
@@ -82,7 +78,7 @@ module Buildkite::TestCollector
82
78
  rescue EOFError => e
83
79
  Buildkite::TestCollector.logger.warn("#{e}")
84
80
  if @socket
85
- Buildkite::TestCollector.logger.warn("attempting disconnected flow")
81
+ Buildkite::TestCollector.logger.error("attempting disconnected flow")
86
82
  @session.disconnected(self)
87
83
  disconnect
88
84
  end
@@ -151,7 +147,7 @@ module Buildkite::TestCollector
151
147
  socket = @socket
152
148
  @socket = nil
153
149
  socket&.close
154
- @thread&.join unless @thread == Thread.current
150
+ @read_thread&.join unless @read_thread == Thread.current
155
151
  end
156
152
  end
157
153
  end
@@ -1,8 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/hash/indifferent_access"
4
-
5
3
  module Buildkite::TestCollector
4
+ # Traces the execution of an application by creating and storing spans of information.
5
+ #
6
+ # This class contains two data structures:
7
+ #
8
+ # - A stack (called @stack) that traces the entering & leaving of each part of the application.
9
+ # - A tree made up of many Span nodes. Each Span is a node in the tree. Each
10
+ # span is also stored in the stack. The root of the tree is called @top and
11
+ # is stored at @stack[0].
12
+ #
13
+ # When the trace is complete the stack MUST contain a single node @top, which
14
+ # is the root of the tree (see #finalize). The tree is converted into a hash
15
+ # in #as_json which recursively calls #as_json on all of it's children.
6
16
  class Tracer
7
17
  # https://github.com/buildkite/test-collector-ruby/issues/131
8
18
  class MonotonicTime
@@ -1,20 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "openssl"
4
- require "websocket"
5
-
6
- require_relative "tracer"
7
- require_relative "network"
8
- require_relative "object"
9
- require_relative "session"
10
- require_relative "ci"
11
- require_relative "http_client"
12
-
13
- require "active_support"
14
- require "active_support/notifications"
15
-
16
- require "securerandom"
17
-
18
3
  module Buildkite::TestCollector
19
4
  class Uploader
20
5
  def self.traces
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Buildkite
4
4
  module TestCollector
5
- VERSION = "1.1.1"
5
+ VERSION = "1.1.2"
6
6
  NAME = "buildkite-test_collector"
7
7
  end
8
8
  end
@@ -1,16 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ module Buildkite
4
+ module TestCollector
5
+ end
6
+ end
7
+
8
+ require "json"
9
+ require "logger"
10
+ require "net/http"
11
+ require "openssl"
12
+ require "time"
3
13
  require "timeout"
4
14
  require "tmpdir"
15
+ require "securerandom"
16
+ require "socket"
17
+ require "websocket"
18
+
19
+ require "active_support/core_ext/object/blank"
20
+ require "active_support/core_ext/hash/indifferent_access"
21
+ require "active_support/notifications"
5
22
 
6
23
  require_relative "test_collector/version"
24
+ require_relative "test_collector/error"
7
25
  require_relative "test_collector/logger"
26
+ require_relative "test_collector/ci"
27
+ require_relative "test_collector/http_client"
28
+ require_relative "test_collector/uploader"
29
+ require_relative "test_collector/network"
30
+ require_relative "test_collector/object"
31
+ require_relative "test_collector/tracer"
32
+ require_relative "test_collector/socket_connection"
33
+ require_relative "test_collector/session"
8
34
 
9
35
  module Buildkite
10
36
  module TestCollector
11
- class Error < StandardError; end
12
- class TimeoutError < ::Timeout::Error; end
13
-
14
37
  DEFAULT_URL = "https://analytics-api.buildkite.com/v1/uploads"
15
38
 
16
39
  class << self
@@ -78,5 +101,12 @@ module Buildkite
78
101
  Buildkite::TestCollector::Uploader.tracer&.backfill(:sql, finish - start, **{ query: payload[:sql] })
79
102
  end
80
103
  end
104
+
105
+ def self.safe(&block)
106
+ block.call
107
+ rescue StandardError => e
108
+ logger.error("Buildkite::TestCollector received exception: #{e}")
109
+ logger.error("Backtrace:\n#{e.backtrace.join("\n")}")
110
+ end
81
111
  end
82
112
  end
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Minitest finds this file before setup code
4
+ require_relative "../buildkite/test_collector"
5
+ require_relative "../buildkite/test_collector/minitest_plugin/reporter"
6
+
1
7
  module Minitest
2
8
  def self.plugin_buildkite_collector_init(options)
3
9
  if defined?(Buildkite::TestCollector::MinitestPlugin) && Buildkite::TestCollector.respond_to?(:uploader)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildkite-test_collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Buildkite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-30 00:00:00.000000000 Z
11
+ date: 2022-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -84,6 +84,7 @@ files:
84
84
  - CHANGELOG.md
85
85
  - CODEOWNERS
86
86
  - CODE_OF_CONDUCT.md
87
+ - DESIGN.md
87
88
  - Gemfile
88
89
  - Gemfile.lock
89
90
  - LICENSE.txt
@@ -95,6 +96,7 @@ files:
95
96
  - buildkite.yaml
96
97
  - lib/buildkite/test_collector.rb
97
98
  - lib/buildkite/test_collector/ci.rb
99
+ - lib/buildkite/test_collector/error.rb
98
100
  - lib/buildkite/test_collector/http_client.rb
99
101
  - lib/buildkite/test_collector/library_hooks/minitest.rb
100
102
  - lib/buildkite/test_collector/library_hooks/rspec.rb
@@ -133,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
135
  - !ruby/object:Gem::Version
134
136
  version: '0'
135
137
  requirements: []
136
- rubygems_version: 3.3.3
138
+ rubygems_version: 3.1.6
137
139
  signing_key:
138
140
  specification_version: 4
139
141
  summary: Track test executions and report to Buildkite Test Analytics