Logstash errors while executing ruby code (Ruby exception occurred: allocator undefined for Floa)

Was trying to execute below code. but logstash keeps spitting an error out.

if [received_at] and [sent_at] {
	ruby {
	  init => "require 'time'"
	  code => "
		received_by_finacle = (Time.parse(event.get('received_at').to_f)*1000).round(2);
		sent_out_by_finacle = (Time.parse(event.get('sent_at').to_f)*1000).round(2);
		event.set('delta', (sent_out_by_finacle - received_by_finacle)).to_s;
		event.set('epoch_received_at_in_milliseconds', received_by_finacle);
		event.set('epoch_sent_at_in_milliseconds', sent_out_by_finacle);
		"
	  add_tag => [ "calculated_time_difference" ]
	}
}  

Error is
[2018-10-10T22:01:05,631][ERROR][logstash.filters.ruby ] Ruby exception occurred: allocator undefined for Float
[2018-10-10T22:01:05,640][ERROR][logstash.filters.ruby ] Ruby exception occurred: allocator undefined for Float
[2018-10-10T22:01:05,643][ERROR][logstash.filters.ruby ] Ruby exception occurred: allocator undefined for Float
[2018-10-10T22:01:05,646][ERROR][logstash.filters.ruby ] Ruby exception occurred: allocator undefined for Float
[2018-10-10T22:01:05,649][ERROR][logstash.filters.ruby ] Ruby exception occurred: allocator undefined for Float

Any help will be appreciated please. I am logstash version. 6.2.3

Thanks to @Ganesh_Venkataraman. I was able to resolve this by adding "rescue nil" to the time difference. Here's what finally worked.

	date {
		match => [ "received_at", "dd/mm/yyyy HH:mm:ss.SSS" ]
		timezone => "UTC"
		target => "receivedlogtime"
	  }
	  
	date {
		match => [ "sent_at", "dd/mm/yyyy HH:mm:ss.SSS" ]
		timezone => "UTC"
		target => "sentlogtime"
	  }
	  
	  
	if [received_at] and [sent_at] {
		ruby {
			init => "require 'time'"
			code => "
				received_by_finacle   = (Time.parse(event.get('received_at')).to_f)*1000;
				sent_out_by_finacle   = (Time.parse(event.get('sent_at')).to_f)*1000;
				timetaken = (sent_out_by_finacle - received_by_finacle) rescue nil;
				event.set('time_delta',timetaken);
				event.set('epoch_received_at_in_milliseconds',received_by_finacle);
				event.set('epoch_sent_at_in_milliseconds',sent_out_by_finacle);
				"
				add_tag => [ "calculated_time_difference" ]
		}
	}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.