reduce overhead of create_pipeline if config is known

This commit is contained in:
Joao Duarte 2016-05-06 09:59:55 +01:00
parent c79ca77bd8
commit 723046fb1e
2 changed files with 14 additions and 10 deletions

View file

@ -165,12 +165,15 @@ class LogStash::Agent
@collect_metric
end
def create_pipeline(settings)
begin
config = fetch_config(settings)
rescue => e
@logger.error("failed to fetch pipeline configuration", :message => e.message)
return
def create_pipeline(settings, config=nil)
if config.nil?
begin
config = fetch_config(settings)
rescue => e
@logger.error("failed to fetch pipeline configuration", :message => e.message)
return
end
end
begin
@ -189,13 +192,14 @@ class LogStash::Agent
# wrapped in @upgrade_mutex in the parent call `reload_state!`
def reload_pipeline!(id)
old_pipeline = @pipelines[id]
if old_pipeline.config_str == fetch_config(old_pipeline.original_settings)
new_config = fetch_config(old_pipeline.original_settings)
if old_pipeline.config_str == new_config
@logger.debug("no configuration change for pipeline",
:pipeline => id, :config => old_pipeline.config_str)
:pipeline => id, :config => new_config)
return
end
new_pipeline = create_pipeline(old_pipeline.original_settings)
new_pipeline = create_pipeline(old_pipeline.original_settings, new_config)
return if new_pipeline.nil?
if new_pipeline.non_reloadable_plugins.any?

View file

@ -179,7 +179,7 @@ describe LogStash::Agent do
context "when fetching a new state" do
it "upgrades the state" do
expect(subject).to receive(:fetch_config).twice.and_return(second_pipeline_config)
expect(subject).to receive(:fetch_config).and_return(second_pipeline_config)
expect(subject).to receive(:upgrade_pipeline).with(pipeline_id, kind_of(LogStash::Pipeline))
subject.send(:reload_state!)
end