buildkite-test_collector 2.6.1 → 2.7.1

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: 2bb798155684d3e4703de75ea06ccaf67b4f6d1b26c98459e621b34dea157e54
4
- data.tar.gz: 6eb653f87c490762cadef81b202cb5f77d900b9a628ca245fd9718307e506dd5
3
+ metadata.gz: bcfc8923f58efed71367663fffeff688fbfbf9eeb330b7876cc89b71fb3e72d7
4
+ data.tar.gz: 59df6ce58d186a12ef039a26aa372d96af142bc0f6ecd390767ec182737960d0
5
5
  SHA512:
6
- metadata.gz: d2e371578afd8e21a3736b86c5158ebc72e57f61dd771a3365ae932e16d2b0b5add98e139ffc2cfd1ac0b54b6ea08a664f1ebc4a3082e1e07ef10b5ea318fad9
7
- data.tar.gz: 817afafdd348cb3f2e4b8dd0b720a1afc6e988094bb872b1306a958eea1c9432abba0edcbbba94b920df6d415115bb60e5e55d9ccd70772d9ac71e88b0e13646
6
+ metadata.gz: 6fdc80dfdc84af033309dee9071334d5d5978d01d2515bdc3324dce5726146edb7d145867cec458232ccd9bc83c6da53638c9895f43daca3483eb19366a18c94
7
+ data.tar.gz: ae959e70dec2e553f72be5168b5df7fb69aa1e94c040fa6563f277cfcf98e979604b3e5e4fc23b413b61dac018d0628babbf8be0465e869f2ad678b9cb50bd4e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v2.7.1
4
+
5
+ - Removes test links from job logs
6
+ - Rename Test Analytics to Test Engine
7
+
8
+ ## v2.7.0
9
+
10
+ Features:
11
+
12
+ - Add configurable span filters #220 - @catkins
13
+
14
+ Fixes:
15
+
16
+ - Correctly report HTTP error during upload #223 - @zhming0
17
+
3
18
  ## v2.6.1
4
19
 
5
20
  - Fix missing failed examples if rspec hooks fail #221 - @zhming0
data/CODEOWNERS CHANGED
@@ -1 +1 @@
1
- * @buildkite/test-analytics
1
+ * @buildkite/test-engine
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- buildkite-test_collector (2.6.1)
4
+ buildkite-test_collector (2.7.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  **DEPRECATION NOTICE**
4
4
  Versions prior to 2.1.x are unsupported and will not work after mid-2023. Please upgrade to the latest version.
5
5
 
6
- Official [Buildkite Test Analytics](https://buildkite.com/test-analytics) collectors for Ruby test frameworks ✨
6
+ Official [Buildkite Test Engine](https://buildkite.com/platform/test-engine) collectors for Ruby test frameworks ✨
7
7
 
8
8
  ⚒ **Supported test frameworks:** RSpec, Minitest, and [more coming soon](https://github.com/buildkite/test-collector-ruby/issues?q=is%3Aissue+is%3Aopen+label%3A%22test+frameworks%22).
9
9
 
@@ -68,13 +68,13 @@ BUILDKITE_ANALYTICS_TOKEN=xyz rake
68
68
  Add the `BUILDKITE_ANALYTICS_TOKEN` secret to your CI, push your changes to a branch, and open a pull request 🎉
69
69
 
70
70
  ```bash
71
- git checkout -b add-buildkite-test-analytics
72
- git commit -am "Add Buildkite Test Analytics"
73
- git push origin add-buildkite-test-analytics
71
+ git checkout -b add-buildkite-test-engine
72
+ git commit -am "Add Buildkite Test Engine"
73
+ git push origin add-buildkite-test-engine
74
74
  ```
75
75
 
76
76
  ### VCR
77
- If your test suites use [VCR](https://github.com/vcr/vcr) to stub network requests, you'll need to modify the config to allow actual network requests to Test Analytics.
77
+ If your test suites use [VCR](https://github.com/vcr/vcr) to stub network requests, you'll need to modify the config to allow actual network requests to Test Engine.
78
78
 
79
79
  ```
80
80
  VCR.configure do |c|
@@ -119,7 +119,7 @@ And run the tests:
119
119
  bundle exec rspec
120
120
  ```
121
121
 
122
- Useful resources for developing collectors include the [Buildkite Test Analytics docs](https://buildkite.com/docs/test-analytics).
122
+ Useful resources for developing collectors include the [Buildkite Test Engine docs](https://buildkite.com/docs/test-engine).
123
123
 
124
124
  See [DESIGN.md](DESIGN.md) for an overview of the design of this gem.
125
125
 
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Buildkite"]
9
9
  spec.email = ["support+analytics@buildkite.com"]
10
10
 
11
- spec.summary = "Track test executions and report to Buildkite Test Analytics"
11
+ spec.summary = "Track test executions and report to Buildkite Test Engine"
12
12
  spec.homepage = "https://github.com/buildkite/test-collector-ruby"
13
13
  spec.license = "MIT"
14
14
 
@@ -38,7 +38,13 @@ module Buildkite::TestCollector
38
38
 
39
39
  contact.body = compressed_body.string
40
40
 
41
- http.request(contact)
41
+ response = http.request(contact)
42
+
43
+ if response.is_a?(Net::HTTPSuccess)
44
+ response
45
+ else
46
+ raise "HTTP Request Failed: #{response.code} #{response.message}"
47
+ end
42
48
  end
43
49
 
44
50
  def metadata
@@ -5,7 +5,6 @@ require "rspec/expectations"
5
5
 
6
6
  require_relative "../rspec_plugin/reporter"
7
7
  require_relative "../rspec_plugin/trace"
8
- require_relative "../test_links_plugin/formatter"
9
8
 
10
9
  Buildkite::TestCollector.uploader = Buildkite::TestCollector::Uploader
11
10
 
@@ -58,7 +58,6 @@ module Buildkite::TestCollector
58
58
  def initialize(min_duration: nil)
59
59
  @top = Span.new(:top, MonotonicTime.call, nil, {})
60
60
  @stack = [@top]
61
- @min_duration = min_duration
62
61
  end
63
62
 
64
63
  def enter(section, **detail)
@@ -69,17 +68,17 @@ module Buildkite::TestCollector
69
68
 
70
69
  def leave
71
70
  current_span.end_at = MonotonicTime.call
72
- duration = current_span.duration
73
71
  @stack.pop
74
- current_span.children.pop if @min_duration && duration < @min_duration
72
+
73
+ current_span.children.pop unless retain_span?(current_span.children.last)
74
+
75
75
  nil # avoid ambiguous return type/value
76
76
  end
77
77
 
78
78
  def backfill(section, duration, **detail)
79
- return if @min_duration && duration < @min_duration
80
79
  now = MonotonicTime.call
81
80
  new_entry = Span.new(section, now - duration, now, detail)
82
- current_span.children << new_entry
81
+ current_span.children << new_entry if retain_span?(new_entry)
83
82
  end
84
83
 
85
84
  def current_span
@@ -95,5 +94,15 @@ module Buildkite::TestCollector
95
94
  def history
96
95
  @top.as_hash
97
96
  end
97
+
98
+ private
99
+
100
+ def retain_span?(span)
101
+ return true unless Buildkite::TestCollector.span_filters
102
+
103
+ Buildkite::TestCollector.span_filters.all? do |filter|
104
+ filter.call(span)
105
+ end
106
+ end
98
107
  end
99
108
  end
@@ -25,7 +25,8 @@ module Buildkite::TestCollector
25
25
  OpenSSL::SSL::SSLError,
26
26
  OpenSSL::SSL::SSLErrorWaitReadable,
27
27
  EOFError,
28
- Errno::ETIMEDOUT
28
+ Errno::ETIMEDOUT,
29
+ # TODO: some retries for server-side error would be great.
29
30
  ]
30
31
 
31
32
  def self.tracer
@@ -38,7 +39,7 @@ module Buildkite::TestCollector
38
39
  http = Buildkite::TestCollector::HTTPClient.new(Buildkite::TestCollector.url)
39
40
 
40
41
  Thread.new do
41
- response = begin
42
+ begin
42
43
  upload_attempts ||= 0
43
44
  http.post_json(data)
44
45
  rescue *Buildkite::TestCollector::Uploader::RETRYABLE_UPLOAD_ERRORS => e
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Buildkite
4
4
  module TestCollector
5
- VERSION = "2.6.1"
5
+ VERSION = "2.7.1"
6
6
  NAME = "buildkite-test_collector"
7
7
  end
8
8
  end
@@ -28,7 +28,6 @@ module Buildkite
28
28
  module TestCollector
29
29
  DEFAULT_URL = "https://analytics-api.buildkite.com/v1/uploads"
30
30
  DEFAULT_UPLOAD_BATCH_SIZE = 500
31
-
32
31
  class << self
33
32
  attr_accessor :api_token
34
33
  attr_accessor :url
@@ -39,6 +38,7 @@ module Buildkite
39
38
  attr_accessor :env
40
39
  attr_accessor :batch_size
41
40
  attr_accessor :trace_min_duration
41
+ attr_accessor :span_filters
42
42
  end
43
43
 
44
44
  def self.configure(hook:, token: nil, url: nil, tracing_enabled: true, artifact_path: nil, env: {})
@@ -54,6 +54,11 @@ module Buildkite
54
54
  Float(trace_min_ms_string) / 1000
55
55
  end
56
56
 
57
+ self.span_filters = []
58
+ unless self.trace_min_duration.nil?
59
+ self.span_filters << MinDurationSpanFilter.new(self.trace_min_duration)
60
+ end
61
+
57
62
  self.hook_into(hook)
58
63
  end
59
64
 
@@ -84,5 +89,15 @@ module Buildkite
84
89
  Buildkite::TestCollector::Uploader.tracer&.backfill(:sql, finish - start, **{ query: payload[:sql] })
85
90
  end
86
91
  end
92
+
93
+ class MinDurationSpanFilter
94
+ def initialize(min_duration)
95
+ @min_duration = min_duration
96
+ end
97
+
98
+ def call(span)
99
+ span.duration > @min_duration
100
+ end
101
+ end
87
102
  end
88
103
  end
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: 2.6.1
4
+ version: 2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Buildkite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-09 00:00:00.000000000 Z
11
+ date: 2024-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -88,7 +88,6 @@ files:
88
88
  - lib/buildkite/test_collector/rspec_plugin/reporter.rb
89
89
  - lib/buildkite/test_collector/rspec_plugin/trace.rb
90
90
  - lib/buildkite/test_collector/session.rb
91
- - lib/buildkite/test_collector/test_links_plugin/formatter.rb
92
91
  - lib/buildkite/test_collector/tracer.rb
93
92
  - lib/buildkite/test_collector/uploader.rb
94
93
  - lib/buildkite/test_collector/uuid.rb
@@ -118,5 +117,5 @@ requirements: []
118
117
  rubygems_version: 3.5.11
119
118
  signing_key:
120
119
  specification_version: 4
121
- summary: Track test executions and report to Buildkite Test Analytics
120
+ summary: Track test executions and report to Buildkite Test Engine
122
121
  test_files: []
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Buildkite::TestCollector::TestLinksPlugin
4
- class Formatter
5
- RSpec::Core::Formatters.register self, :dump_failures
6
-
7
- def initialize(output)
8
- @output = output
9
- end
10
-
11
- def dump_failures(notification)
12
- # Do not display summary if no failed examples
13
- return if notification.failed_examples.empty?
14
-
15
- # Check if a Test Analytics token is set
16
- return unless Buildkite::TestCollector.api_token
17
-
18
- metadata = fetch_metadata
19
-
20
- # return if metadata was not fetched successfully
21
- return if metadata.nil?
22
-
23
- # return if suite url is nil
24
- return if metadata['suite_url'].nil?
25
-
26
- @output << "\n\n🔥 \x1b[31mTest Analytics failures 🔥\n"
27
- @output << '_____________________________'
28
- @output << "\n\n"
29
-
30
- @output << notification.failed_examples.map do |example|
31
- failed_example_output(example, metadata['suite_url'])
32
- end.join("\n")
33
-
34
- @output << "\n\n"
35
- end
36
-
37
- private
38
-
39
- def generate_scope_name_digest(scope, name)
40
- Digest::SHA256.hexdigest(scope + name)
41
- end
42
-
43
- def failed_example_output(example, url)
44
- scope = example.example_group.metadata[:full_description]
45
- name = example.description
46
- scope_name_digest = generate_scope_name_digest(scope, name)
47
- test_url = "#{url}/tests/#{scope_name_digest}"
48
- "🔗 \x1b[4m\x1b[37m#{%(\x1b]1339;url=#{test_url};content="#{scope} #{name}"\x07)}\x1b[m"
49
- end
50
-
51
- def fetch_metadata
52
- return unless Buildkite::TestCollector.api_token
53
-
54
- http = Buildkite::TestCollector::HTTPClient.new(Buildkite::TestCollector.url)
55
- response = http.metadata
56
-
57
- JSON.parse(response.body) if response.code == '200'
58
- rescue StandardError => e
59
- # We don't need to output anything here
60
- end
61
- end
62
- end