Class: Minitest::Reporters::StatsdReporter

Inherits:
BaseReporter
  • Object
show all
Defined in:
lib/minitest/reporters/statsd_reporter.rb

Constant Summary collapse

FAILING_INFRASTRUCTURE_THRESHOLD =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statsd: Minitest::Queue::Statsd, statsd_endpoint: nil, **options) ⇒ StatsdReporter

Returns a new instance of StatsdReporter.



13
14
15
16
17
18
19
20
21
# File 'lib/minitest/reporters/statsd_reporter.rb', line 13

def initialize(statsd: Minitest::Queue::Statsd, statsd_endpoint: nil, **options)
  super(options)
  @statsd = statsd.new(
    addr: statsd_endpoint,
    namespace: 'minitests.tests',
    default_tags: ["slug:#{ENV['BUILDKITE_PROJECT_SLUG']}"]
  )
  @failures = 0
end

Instance Attribute Details

#statsdObject (readonly)

Returns the value of attribute statsd.



11
12
13
# File 'lib/minitest/reporters/statsd_reporter.rb', line 11

def statsd
  @statsd
end

Instance Method Details

#record(result) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/minitest/reporters/statsd_reporter.rb', line 23

def record(result)
  if result.passed?
    @statsd.increment("passed")
  elsif result.skipped? && !result.requeued?
    @statsd.increment("skipped")
  else
    @statsd.increment('requeued') if result.requeued?

    if result.failure.is_a?(Minitest::UnexpectedError)
      @statsd.increment("unexpected_errors")
    else
      @statsd.increment("failed")
    end

    @failures += 1
  end
end

#reportObject



41
42
43
# File 'lib/minitest/reporters/statsd_reporter.rb', line 41

def report
  @statsd.increment("failing_infrastructure_threshold") if @failures >= FAILING_INFRASTRUCTURE_THRESHOLD
end