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
This commit is contained in:
Rob Bavey 2020-04-13 14:44:42 -04:00 committed by Robert Bavey
parent a8fca3c07f
commit 2e545c75e4

View file

@ -44,11 +44,11 @@ module LogStash;
end end
def vertices def vertices
graph.getVertices.map {|v| vertex(v) } graph.getVertices.map {|v| vertex(v) }.compact
end end
def edges def edges
graph.getEdges.map {|e| edge(e) } remove_separators_from_edges(graph.getEdges)
end end
def graph def graph
@ -64,10 +64,10 @@ module LogStash;
when :queue when :queue
queue_vertex(v) queue_vertex(v)
when :separator when :separator
separator_vertex(v) nil
end end
decorate_vertex(v, hashified_vertex) decorate_vertex(v, hashified_vertex) unless hashified_vertex.nil?
end end
def vertex_type(v) def vertex_type(v)
@ -114,6 +114,24 @@ module LogStash;
{} {}
end 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) def edge(e)
e_json = { e_json = {
"from" => e.from.id, "from" => e.from.id,