Class: LogStash::StateResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/state_resolver.rb

Overview

In the beginning I was using this code as a method in the Agent class directly But with the plugins system I think we should be able to swap what kind of action would be run.

Lets take the example of dynamic source, where the pipeline config and settings are located and managed outside of the machine.

Instance Method Summary collapse

Constructor Details

#initialize(metric) ⇒ StateResolver

Returns a new instance of StateResolver.



9
10
11
# File 'lib/logstash/state_resolver.rb', line 9

def initialize(metric)
  @metric = metric
end

Instance Method Details

#resolve(pipelines_registry, pipeline_configs) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/logstash/state_resolver.rb', line 13

def resolve(pipelines_registry, pipeline_configs)
  actions = []

  pipeline_configs.each do |pipeline_config|
    pipeline = pipelines_registry.get_pipeline(pipeline_config.pipeline_id)

    if pipeline.nil?
      actions << LogStash::PipelineAction::Create.new(pipeline_config, @metric)
    else
      if pipeline_config != pipeline.pipeline_config
        actions << LogStash::PipelineAction::Reload.new(pipeline_config, @metric)
      end
    end
  end

  configured_pipelines = pipeline_configs.collect(&:pipeline_id)

  # If one of the running pipeline is not in the pipeline_configs, we assume that we need to
  # stop it.
  pipelines_registry.running_pipelines.keys
    .select { |pipeline_id| !configured_pipelines.include?(pipeline_id) }
    .each { |pipeline_id| actions << LogStash::PipelineAction::Stop.new(pipeline_id) }

  actions.sort # See logstash/pipeline_action.rb
end