Skip to content

Commit 10e170d

Browse files
committed
avoid variable collision in pipeline stats api (#11059)
Fixes #11062
1 parent 9d80576 commit 10e170d

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

logstash-core/lib/logstash/api/commands/stats.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def pipeline(pipeline_id = nil, opts={})
6565
service.agent,
6666
service.snapshot.metric_store,
6767
true).each_with_object({}) do |pipeline_stats, memo|
68-
pipeline_id = pipeline_stats["id"].to_s
69-
memo[pipeline_id] = pipeline_stats
68+
p_id = pipeline_stats["id"].to_s
69+
memo[p_id] = pipeline_stats
7070
end
7171

7272
if pipeline_id.nil?

logstash-core/spec/logstash/api/commands/stats_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,41 @@
4949
end
5050

5151
end
52+
53+
describe "pipeline stats" do
54+
let(:report_method) { :pipeline }
55+
it "returns information on existing pipeline" do
56+
expect(report.keys).to include(:main)
57+
end
58+
context "for each pipeline" do
59+
it "returns information on pipeline" do
60+
expect(report[:main].keys).to include(
61+
:events,
62+
:plugins,
63+
:reloads,
64+
:queue,
65+
)
66+
end
67+
it "returns event information" do
68+
expect(report[:main][:events].keys).to include(
69+
:in,
70+
:filtered,
71+
:duration_in_millis,
72+
:out,
73+
:queue_push_duration_in_millis
74+
)
75+
end
76+
end
77+
context "when using multiple pipelines" do
78+
before(:each) do
79+
expect(LogStash::Config::PipelinesInfo).to receive(:format_pipelines_info).and_return([
80+
{"id" => :main},
81+
{"id" => :secondary},
82+
])
83+
end
84+
it "contains metrics for all pipelines" do
85+
expect(report.keys).to include(:main, :secondary)
86+
end
87+
end
88+
end
5289
end

logstash-core/spec/support/shared_contexts.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
settings.set("config.reload.automatic", false)
2525
@agent = make_test_agent(settings)
2626
@agent.execute
27+
@pipelines_registry = LogStash::PipelinesRegistry.new
2728
pipeline_config = mock_pipeline_config(:main, "input { generator { id => '123' } } output { null {} }")
2829
pipeline_creator = LogStash::PipelineAction::Create.new(pipeline_config, @agent.metric)
29-
@pipelines_registry = LogStash::PipelinesRegistry.new
30+
expect(pipeline_creator.execute(@agent, @pipelines_registry)).to be_truthy
31+
pipeline_config = mock_pipeline_config(:secondary, "input { generator { id => '123' } } output { null {} }")
32+
pipeline_creator = LogStash::PipelineAction::Create.new(pipeline_config, @agent.metric)
3033
expect(pipeline_creator.execute(@agent, @pipelines_registry)).to be_truthy
3134
end
3235

0 commit comments

Comments
 (0)