From 2e545c75e47cf13a693bca8c44bb6be2a9f63bc9 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Mon, 13 Apr 2020 14:44:42 -0400 Subject: [PATCH] Remove separator vertices and associated edges from serialized output The separator vertices are an implementation detail of the serialized output of the LIR, and are not meaningful to the pipeline viewer. This commit removes the separator vertices, and reworks the edges to account for this. Fixes #11779 --- .../lib/logstash/config/lir_serializer.rb | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/logstash-core/lib/logstash/config/lir_serializer.rb b/logstash-core/lib/logstash/config/lir_serializer.rb index 9826d3217..506f9c57d 100644 --- a/logstash-core/lib/logstash/config/lir_serializer.rb +++ b/logstash-core/lib/logstash/config/lir_serializer.rb @@ -26,7 +26,7 @@ module LogStash; def self.serialize(lir_pipeline) self.new(lir_pipeline).serialize end - + def initialize(lir_pipeline) @lir_pipeline = lir_pipeline end @@ -44,11 +44,11 @@ module LogStash; end def vertices - graph.getVertices.map {|v| vertex(v) } + graph.getVertices.map {|v| vertex(v) }.compact end def edges - graph.getEdges.map {|e| edge(e) } + remove_separators_from_edges(graph.getEdges) end def graph @@ -64,10 +64,10 @@ module LogStash; when :queue queue_vertex(v) when :separator - separator_vertex(v) + nil end - decorate_vertex(v, hashified_vertex) + decorate_vertex(v, hashified_vertex) unless hashified_vertex.nil? end def vertex_type(v) @@ -114,6 +114,24 @@ module LogStash; {} end + # For separators, create new edges going between the incoming and all of the outgoing edges, and remove + # the separator vertices from the serialized output. + def remove_separators_from_edges(edges) + edges_with_separators_removed = [] + edges.each do |e| + if vertex_type(e.to) == :separator + e.to.getOutgoingEdges.each do |outgoing| + edges_with_separators_removed << edge(org.logstash.config.ir.graph.PlainEdge.new(e.from, outgoing.to)) + end + elsif vertex_type(e.from) == :separator + # Skip the edges coming from the 'from' separator + else + edges_with_separators_removed << edge(e) + end + end + edges_with_separators_removed + end + def edge(e) e_json = { "from" => e.from.id,