Sha256: 25a26d10590b965d8e4434b39872c1fcab026bc9ac84b9fe2f4e6cc8b6a2b0cd

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require 'fluent/plugin/out_statsd'
require 'fluent/test'

RSpec.describe Fluent::StatsdOutput do
  let(:config) do
    %{
      type statsd

      <metric>
        statsd_type increment
        statsd_key res_code_${record['hostname']}_${record['status'].to_i / 100}xx
      </metric>
    }
  end
  let(:driver) { create_driver(config) }
  let(:statsd) { double('statsd', increment: true,
                                  flush: true,
                                  'namespace=' => true,
                                  'batch_size=' => true,
                                  'batch_byte_size' => true)

               }
  let(:time) { Time.now.utc }

  before :all do
    Fluent::Test.setup
  end

  def create_driver(conf)
    Fluent::Test::BufferedOutputTestDriver.new(Fluent::StatsdOutput) {
    }.configure(conf)
  end

  def emit_events(events)
    events.each {|e| driver.emit(e, time) }
  end


  it 'should call statsd with events data and correctly handle multiple placeholders' do
    allow(Statsd).to receive(:new).and_return(statsd)

    expect(statsd).to receive(:increment).with('res_code_localhost_2xx').twice.times
    expect(statsd).to receive(:increment).with('res_code_localhost_4xx').once.times
    expect(statsd).to receive(:increment).with('res_code_localhost_5xx').once.times

    emit_events([
      {'hostname' => 'localhost', 'response_time' => 102, 'status' => '200'},
      {'hostname' => 'localhost', 'response_time' => 105, 'status' => '200'},
      {'hostname' => 'localhost', 'response_time' => 112, 'status' => '400'},
      {'hostname' => 'localhost', 'response_time' => 125, 'status' => '500'}
    ])

    driver.run
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-statsd-output-1.3.1 spec/plugin/multiple_placeholders_spec.rb