Sha256: 11df280852c3b7783fcb6476d59553acdfe1fa8d1b7263faf64f621468e1141e

Contents?: true

Size: 1.52 KB

Versions: 62

Compression:

Stored size: 1.52 KB

Contents

module CC
  module Analyzer
    class StatsdContainerListener < ContainerListener
      def initialize(statsd)
        @statsd = statsd
      end

      def started(engine, _details)
        increment(engine, "started")
      end

      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

      private

      attr_reader :statsd

      def increment(engine, metric)
        statsd.increment("engines.#{metric}")
        statsd.increment("engines.names.#{engine.name}.#{metric}")
        if engine.respond_to?(:channel) && engine.channel
          statsd.increment("engines.names.#{engine.name}.#{engine.channel}.#{metric}")
        end
      end

      def timing(engine, metric, ms)
        statsd.timing("engines.#{metric}", ms)
        statsd.timing("engines.names.#{engine.name}.#{metric}", ms)
        if engine.respond_to?(:channel) && engine.channel
          statsd.timing("engines.names.#{engine.name}.#{engine.channel}.#{metric}", ms)
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 2 rubygems

Version Path
codeclimate-0.75.0 lib/cc/analyzer/statsd_container_listener.rb
codeclimate-0.74.0 lib/cc/analyzer/statsd_container_listener.rb