class CC::Analyzer::StatsdContainerListener

Attributes

repo_id[R]
statsd[R]

Public Class Methods

new(statsd, repo_id: nil) click to toggle source

rubocop:disable Lint/MissingSuper

# File lib/cc/analyzer/statsd_container_listener.rb, line 5
def initialize(statsd, repo_id: nil)
  @statsd = statsd
  @repo_id = repo_id
end

Public Instance Methods

finished(engine, _details, result) click to toggle source
# File lib/cc/analyzer/statsd_container_listener.rb, line 15
def finished(engine, _details, result)
  timing(engine, "time", result.duration)
  increment(engine, "finished")

  if result.timed_out?
    timing(engine, "time", result.duration)
    increment(engine, "result.error")
    increment(engine, "result.error.timeout")
  elsif result.maximum_output_exceeded?
    increment(engine, "result.error")
    increment(engine, "result.error.output_exceeded")
  elsif result.exit_status.nonzero?
    increment(engine, "result.error")
  else
    increment(engine, "result.success")
  end
end
started(engine, _details) click to toggle source

rubocop:enable Lint/MissingSuper

# File lib/cc/analyzer/statsd_container_listener.rb, line 11
def started(engine, _details)
  increment(engine, "started")
end

Private Instance Methods

engine_channel_present?(engine) click to toggle source
# File lib/cc/analyzer/statsd_container_listener.rb, line 66
def engine_channel_present?(engine)
  engine.respond_to?(:channel) && engine.channel
end
engine_tags(engine) click to toggle source
# File lib/cc/analyzer/statsd_container_listener.rb, line 59
def engine_tags(engine)
  ["engine:#{engine.name}"].tap do |tags|
    tags << "channel:#{engine.channel}" if engine_channel_present?(engine)
    tags << "repo_id:#{repo_id}" if repo_id.present?
  end
end
increment(engine, action) click to toggle source
# File lib/cc/analyzer/statsd_container_listener.rb, line 37
def increment(engine, action)
  tags = engine_tags(engine)
  metric = metric_name(action)

  # rubocop:disable Style/HashSyntax
  statsd.increment(metric, tags: tags)
  # rubocop:enable Style/HashSyntax
end
metric_name(action) click to toggle source
# File lib/cc/analyzer/statsd_container_listener.rb, line 55
def metric_name(action)
  "engines.#{action}"
end
timing(engine, action, millis) click to toggle source
# File lib/cc/analyzer/statsd_container_listener.rb, line 46
def timing(engine, action, millis)
  tags = engine_tags(engine)
  metric = metric_name(action)

  # rubocop:disable Style/HashSyntax
  statsd.timing(metric, millis, tags: tags)
  # rubocop:enable Style/HashSyntax
end