Class: LogStash::Compiler

Inherits:
Object
  • Object
show all
Includes:
Util::Loggable
Defined in:
lib/logstash/compiler.rb

Class Method Summary collapse

Methods included from Util::Loggable

included, #logger, #slow_logger

Class Method Details

.compile_graph(source_with_metadata, support_escapes) ⇒ Object



49
50
51
# File 'lib/logstash/compiler.rb', line 49

def self.compile_graph(, support_escapes)
  Hash[compile_imperative(, support_escapes).map {|section,icompiled| [section, icompiled.toGraph]}]
end

.compile_imperative(source_with_metadata, support_escapes) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/logstash/compiler.rb', line 33

def self.compile_imperative(, support_escapes)
  if !.is_a?(org.logstash.common.SourceWithMetadata)
    raise ArgumentError, "Expected 'org.logstash.common.SourceWithMetadata', got #{.class}"
  end

  grammar = LogStashCompilerLSCLGrammarParser.new
  config = grammar.parse(.text)

  if config.nil?
    raise ConfigurationError, grammar.failure_reason
  end

  config.process_escape_sequences = support_escapes
  config.compile()
end

.compile_sources(sources_with_metadata, support_escapes) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/logstash/compiler.rb', line 10

def self.compile_sources(, support_escapes)
  graph_sections = .map do |swm|
    self.compile_graph(swm, support_escapes)
  end

  input_graph = Graph.combine(*graph_sections.map {|s| s[:input] }).graph
  output_graph = Graph.combine(*graph_sections.map {|s| s[:output] }).graph

  filter_graph = graph_sections.reduce(nil) do |acc, s| 
    filter_section = s[:filter]

    if acc.nil? 
      filter_section
    else
      acc.chain(filter_section)
    end
  end

  original_source = .map(&:text).join("\n")

  PipelineIR.new(input_graph, filter_graph, output_graph, original_source)
end