Thanks! I went back and forth on whether or not to put the ruby filter inline, or put it in a separate .rb file. I chose the latter to use the testing framework, because there are so many possible points of failure in the pipeline config file already. Testing the ruby filter by itself looks like a good idea.
The explanation of in_event
makes sense
I modified the expect
mehod as follows
expect("extracts the task array") do |events|
puts "EVENTS ARRAY:"
puts events[0].to_hash
events[0].get(["error_task_array"]).count == 2
end # expect
I can see in the output that error_task_array
has 2 elements as expected
EVENTS ARRAY:
{"error_task_array"=>["75fc", "job"], "@timestamp"=>2023-10-09T19:06:52.475893048Z, "error"=>[{"timestamp"=>1695060733555.0, "task"=>"75fc", "message"=>{"ietf-restconf:errors"=>{"error"=>[{"error-message"=>"missing element: name in thepath", "error-type"=>"application", "error-path"=>"/pathto/problem", "error-tag"=>"malformed-message"}]}}}, {"timestamp"=>1695060733570.0, "task"=>"job", "message"=>"Job has no available transitions. 6649, cb04, f5dd could have led to the workflow end task, but did not. These tasks performed in a way that the end of the workflow could not be reached."}], "name"=>"job1", "@version"=>"1"}
However the test continues to fail
[ERROR] 2023-10-09 19:15:13.373 [LogStash::Runner] expectcontext - ***TEST RAISED ERROR: 'get task array extracts the task array'*** {"exception"=>"#<TypeError: no implicit conversion of Array into String>"
I cannot figure out the proper way to get the number of elements in error_task_array
. Besides count
I also tried size
and length
.