Skip to content

Commit

Permalink
Adding config and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
achied committed Oct 16, 2012
1 parent 37e9510 commit 366bc5a
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ GEM
i18n (0.6.1)
iobuffer (1.1.2)
json (1.7.5)
mock_redis (0.5.3)
msgpack (0.4.7)
multi_json (1.3.6)
rack (1.4.1)
Expand All @@ -60,7 +61,6 @@ GEM
rack (>= 1.0)
rake (0.9.2.2)
redis (3.0.2)
rr (1.0.4)
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
Expand All @@ -82,5 +82,5 @@ PLATFORMS

DEPENDENCIES
fluent-plugin-fnordmetric!
mock_redis
rake (>= 0.9.2)
rr (>= 1.0.0)
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ fnordmetric plugin for fluent Event Collector
Setup the fnordmetric output:

~~~~~
<match test.*>
<match fnordmetric.*>
type fnordmetric
redis_url redis://localhost:6379
redis_prefix fnordmetric
event_queue_ttl 120
event_data_ttl 2592000
</match>
~~~~~

2 changes: 1 addition & 1 deletion fluent-plugin-fnordmetric.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Gem::Specification.new do |gem|
gem.add_dependency "fnordmetric", "1.0.0"

gem.add_development_dependency "rake", ">= 0.9.2"
gem.add_development_dependency "rr", ">= 1.0.0"
gem.add_development_dependency "mock_redis"
end
23 changes: 12 additions & 11 deletions lib/fluent/plugin/out_fnordmetric.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
module Fluent
class FnordmetricOutPut < Output
class FnordMetricOutput < Output
Fluent::Plugin.register_output("fnordmetric", self)

def initialize
require 'fnordmetric'
attr_reader :api

FnordMetric.options = {
:event_queue_ttl => 10,
:event_data_ttl => 10,
:session_data_ttl => 1,
:redis_prefix => "fnordmetric"
}
config_param :redis_url, :string, :default => "redis://localhost:6379"
config_param :redis_prefix, :string, :default => "fnordmetric"
config_param :event_queue_ttl, :integer, :default => 120
config_param :event_data_ttl, :integer, :default => 3600*24*30

@api = FnordMetric::API.new
def initialize
require 'fnordmetric'
super
end

def configure(conf)
@api = FnordMetric::API.new(conf)
super
end

Expand All @@ -25,13 +24,15 @@ def start
end

def shutdown
@api.disconnect
super
end

def emit(tag, es, chain)
es.each { |time,record|
@api.event(:_type => :tag, :info => record)
@api.event(:_type => tag, :info => record)
}
chain.next
end
end
end
45 changes: 42 additions & 3 deletions test/plugin/out_fnordmetric.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
require 'test/unit'
require 'fluent/test'
require 'lib/fluent/plugin/out_fnordmetric'
require 'test_helper'

class FnordMetricOutputTest < Test::Unit::TestCase

CONFIG = %[
redis_url redis://localhost:6379
redis_prefix fnordmetric
event_queue_ttl 120
event_data_ttl 2592000
]

def setup
require 'lib/fluent/plugin/out_fnordmetric'
require 'fnordmetric'
FnordMetric::API.send(:include, RedisWrapper)
end


def create_driver(conf=CONFIG)
Fluent::Test::OutputTestDriver.new(Fluent::FnordMetricOutput).configure(conf)
end

def test_configure
d = create_driver
assert_equal 'redis://localhost:6379', d.instance.redis_url
assert_equal 'fnordmetric', d.instance.redis_prefix
assert_equal 120, d.instance.event_queue_ttl
assert_equal 2592000, d.instance.event_data_ttl
end

def test_event
d = create_driver
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
d.tag = "fnordmetric"
d.emit({"a"=>1}, time)
event_id = d.instance.api.redis.lpop("#{d.instance.redis_prefix}-queue")
event = d.instance.api.redis.get "#{d.instance.redis_prefix}-event-#{event_id}"
event_json = JSON.parse(event)
assert_equal event_json["_type"], d.tag
assert_equal event_json["info"], {"a"=>1}
end

end
42 changes: 22 additions & 20 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'test/unit'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'test/unit'
require 'fluent/test'
unless ENV.has_key?('VERBOSE')
nulllogger = Object.new
nulllogger.instance_eval {|obj|
def method_missing(method, *args)
# pass
end
}
$log = nulllogger
end
require 'mock_redis'

class Test::Unit::TestCase
end

module RedisWrapper

def self.included base

base.class_eval do

attr_reader :redis
@@opts = nil

def connect
@redis = MockRedis.new(:url => @@opts[:redis_url])
end

end

end

end

0 comments on commit 366bc5a

Please sign in to comment.