Sha256: 0c51656bbdee36de7d29cd53279b6bb5db01b7865a77c39bb4f6d407cf91d44b

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

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

RSpec.describe Fluent::StatsdOutput do
  let(:config) do
    %{
      type statsd
      namespace a.b.c

      <metric>
        statsd_type timing
        statsd_key res_time
        statsd_val ${record['response_time']}
      </metric>

      <metric>
        statsd_type increment
        statsd_key res_code_${record['status'].to_i / 100}xx
      </metric>
    }
  end
  let(:driver) { create_driver(config) }
  let(:statsd) { double('statsd', increment: true, timing: true, 'namespace=' => 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' do
    allow(Statsd).to receive(:new).and_return(statsd)

    expect(statsd).to receive(:namespace=).with('a.b.c')

    expect(statsd).to receive(:increment).with('res_code_2xx').twice.times
    expect(statsd).to receive(:increment).with('res_code_4xx').once.times
    expect(statsd).to receive(:increment).with('res_code_5xx').once.times
    expect(statsd).to receive(:timing).with('res_time', 102).ordered
    expect(statsd).to receive(:timing).with('res_time', 105).ordered
    expect(statsd).to receive(:timing).with('res_time', 112).ordered
    expect(statsd).to receive(:timing).with('res_time', 125).ordered

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

    driver.run
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fluent-plugin-statsd-output-1.1.1 spec/plugin/out_statsd_spec.rb
fluent-plugin-statsd-output-1.1.0 spec/plugin/out_statsd_spec.rb