Skip to content

Commit

Permalink
avoid variable collision in pipeline stats api (#11059)
Browse files Browse the repository at this point in the history
Fixes #11062
  • Loading branch information
jsvd committed Aug 20, 2019
1 parent c2391b1 commit accc636
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions logstash-core/lib/logstash/api/commands/stats.rb
Expand Up @@ -65,8 +65,8 @@ def pipeline(pipeline_id = nil, opts={})
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?
Expand Down
37 changes: 37 additions & 0 deletions logstash-core/spec/logstash/api/commands/stats_spec.rb
Expand Up @@ -49,4 +49,41 @@
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
5 changes: 4 additions & 1 deletion logstash-core/spec/support/shared_contexts.rb
Expand Up @@ -24,9 +24,12 @@
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

Expand Down

0 comments on commit accc636

Please sign in to comment.