Logstash::Outputs::Redis: JSON-encode message outside of Redis reconnect

Fixes LOGSTASH-712
This commit is contained in:
Laust Rud Jacobsen 2012-11-19 11:15:22 +01:00
parent defc9b9c61
commit 60fc1693d4
2 changed files with 34 additions and 2 deletions

View file

@ -155,12 +155,14 @@ class LogStash::Outputs::Redis < LogStash::Outputs::Base
return
end
event_key_and_payload = [event.sprintf(@key), event.to_json]
begin
@redis ||= connect
if @data_type == 'list'
@redis.rpush event.sprintf(@key), event.to_json
@redis.rpush *event_key_and_payload
else
@redis.publish event.sprintf(@key), event.to_json
@redis.publish *event_key_and_payload
end
rescue => e
@logger.warn("Failed to send event to redis", :event => event,

View file

@ -46,5 +46,35 @@ describe LogStash::Outputs::Redis do
insist { redis.llen(key) } == 0
end # agent
end
describe "skips a message which can't be encoded as json" do
key = 10.times.collect { rand(10).to_s }.join("")
config <<-CONFIG
input {
generator {
message => "\xAD\u0000"
count => 1
type => "generator"
}
}
output {
redis {
host => "127.0.0.1"
key => "#{key}"
data_type => list
}
}
CONFIG
agent do
# Query redis directly and inspect the goodness.
redis = Redis.new(:host => "127.0.0.1")
# The list should contain no elements.
insist { redis.llen(key) } == 0
end # agent
end
end