Closed warmfusion closed 8 years ago
Looks like i might be able to emulate this failure mode using a simple test json object based on this stackoverflow query
I Got what is issue. I think there are two ways, drop or force encode with warning.
Dropping with warnings might be the safest approach as forcing encoding might change the meaning of the messages being sent.
If the messages are dropped at least they can be reviewed and fixed by an end-user - just need to make sure they're dropped with a clear indication of why they were dropped.
Where about's should I be looking to apply changes?
I'm thinking it might be around here; https://github.com/giraffi/fluent-plugin-amqp/blob/master/lib/fluent/plugin/out_amqp.rb#L84-L90
Is it as simple as wrapping the JSON.dump in a begin/rescue and throwing a log warning for encoding errors?
wrapping the JSON.dump in a begin/rescue and throwing a log
I seemed it's might better.
I'm not sure I understand what you mean...?
Ah, sorry. Could you try to wrap JSON.dump ?
Going to manually hack this into some of our servers;
begin
data = JSON.dump( data ) unless data.is_a?( String )
log.debug "Sending message #{data}, :key => #{routing_key( tag)} :headers => #{headers(tag,time)}"
@exch.publish(data, :key => routing_key( tag ), :persistent => @persistent, :headers => headers( tag, time ))
rescue JSON::GeneratorError => e
log.error "Failure converting data object to json string: #{e.message}"
# Debug only - otherwise we may pollute the fluent logs with unparseable events and loop
log.debug "JSON.dump failure converting [#{data}]"
end
It looks good enough to avoid crash. Could you create new PR?
I'm not 100% on the sequence of events that result in this scenario, but heres what I think happens...
Configuration
Message showing error