avoid variable collision in pipeline stats api (#11059)

Fixes #11062
This commit is contained in:
João Duarte 2019-08-20 15:47:52 +01:00 committed by Joao Duarte
parent c2391b1849
commit accc636126
3 changed files with 43 additions and 3 deletions

View file

@ -65,8 +65,8 @@ module LogStash
service.agent,
service.snapshot.metric_store,
true).each_with_object({}) do |pipeline_stats, memo|
pipeline_id = pipeline_stats["id"].to_s
memo[pipeline_id] = pipeline_stats
p_id = pipeline_stats["id"].to_s
memo[p_id] = pipeline_stats
end
if pipeline_id.nil?

View file

@ -49,4 +49,41 @@ describe LogStash::Api::Commands::Stats do
end
end
describe "pipeline stats" do
let(:report_method) { :pipeline }
it "returns information on existing pipeline" do
expect(report.keys).to include(:main)
end
context "for each pipeline" do
it "returns information on pipeline" do
expect(report[:main].keys).to include(
:events,
:plugins,
:reloads,
:queue,
)
end
it "returns event information" do
expect(report[:main][:events].keys).to include(
:in,
:filtered,
:duration_in_millis,
:out,
:queue_push_duration_in_millis
)
end
end
context "when using multiple pipelines" do
before(:each) do
expect(LogStash::Config::PipelinesInfo).to receive(:format_pipelines_info).and_return([
{"id" => :main},
{"id" => :secondary},
])
end
it "contains metrics for all pipelines" do
expect(report.keys).to include(:main, :secondary)
end
end
end
end

View file

@ -24,9 +24,12 @@ shared_context "api setup" do
settings.set("config.reload.automatic", false)
@agent = make_test_agent(settings)
@agent.execute
@pipelines_registry = LogStash::PipelinesRegistry.new
pipeline_config = mock_pipeline_config(:main, "input { generator { id => '123' } } output { null {} }")
pipeline_creator = LogStash::PipelineAction::Create.new(pipeline_config, @agent.metric)
@pipelines_registry = LogStash::PipelinesRegistry.new
expect(pipeline_creator.execute(@agent, @pipelines_registry)).to be_truthy
pipeline_config = mock_pipeline_config(:secondary, "input { generator { id => '123' } } output { null {} }")
pipeline_creator = LogStash::PipelineAction::Create.new(pipeline_config, @agent.metric)
expect(pipeline_creator.execute(@agent, @pipelines_registry)).to be_truthy
end