From bacc4ac771bbfc107bb5a330db1d3eee97af78ac Mon Sep 17 00:00:00 2001 From: andsel Date: Thu, 18 Dec 2025 12:20:54 +0100 Subject: [PATCH 1/3] Clear batch metrics from the collector during pipeline restart. --- logstash-core/lib/logstash/instrument/collector.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/logstash-core/lib/logstash/instrument/collector.rb b/logstash-core/lib/logstash/instrument/collector.rb index a1a7fc3c071..6f11705eb3a 100644 --- a/logstash-core/lib/logstash/instrument/collector.rb +++ b/logstash-core/lib/logstash/instrument/collector.rb @@ -117,6 +117,8 @@ def snapshot_metric end def clear(keypath) + puts "Clearing metrics at path #{keypath}" + puts ">>> call stack Compiler#compile_sources"; caller.each { |frame| puts "#{frame}"} @metric_store.prune(keypath) end end From 04bbe5c511ebbc821e8a8aac873eaa0e48f27c71 Mon Sep 17 00:00:00 2001 From: andsel Date: Thu, 18 Dec 2025 17:47:19 +0100 Subject: [PATCH 2/3] [Test] Add test to verify the batch metrics should be cleared (fails, fix comes in the next commit) --- logstash-core/lib/logstash/instrument/collector.rb | 2 -- logstash-core/spec/logstash/java_pipeline_spec.rb | 14 +++++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/logstash-core/lib/logstash/instrument/collector.rb b/logstash-core/lib/logstash/instrument/collector.rb index 6f11705eb3a..a1a7fc3c071 100644 --- a/logstash-core/lib/logstash/instrument/collector.rb +++ b/logstash-core/lib/logstash/instrument/collector.rb @@ -117,8 +117,6 @@ def snapshot_metric end def clear(keypath) - puts "Clearing metrics at path #{keypath}" - puts ">>> call stack Compiler#compile_sources"; caller.each { |frame| puts "#{frame}"} @metric_store.prune(keypath) end end diff --git a/logstash-core/spec/logstash/java_pipeline_spec.rb b/logstash-core/spec/logstash/java_pipeline_spec.rb index fa2ededdcad..0594e13407c 100644 --- a/logstash-core/spec/logstash/java_pipeline_spec.rb +++ b/logstash-core/spec/logstash/java_pipeline_spec.rb @@ -1665,18 +1665,30 @@ def build_pipeline_string_config(dummyinput_config) end context "of a running pipeline" do - let(:pipeline_settings) { { "pipeline.batch.size" => 1, "pipeline.workers" => 1, "pipeline.id" => pipeline_id, "metric.collect" => true } } + let(:pipeline_settings) { { + "pipeline.batch.size" => 1, + "pipeline.workers" => 1, + "pipeline.id" => pipeline_id, + "metric.collect" => true, + "pipeline.batch.metrics.sampling_mode" => "full" + } } it "should clear the pipeline metrics" do dummyinput.keep_running.make_true expect { pipeline.start }.to_not raise_error + collected_metric = subject.metric.collector.snapshot_metric.metric_store.get_with_path("stats/pipelines") + expect(collected_metric[:stats][:pipelines][pipeline_id.to_sym]).to include(:batch) pipeline.shutdown expect(pipeline).to have_received(:clear_pipeline_metrics) expect(pipeline).to have_received(:stop_inputs) expect(pipeline).to have_received(:wait_for_shutdown) + + # Take a snapshot from metrics and verify the batch metrics have been cleared + collected_metric = subject.metric.collector.snapshot_metric.metric_store.get_with_path("stats/pipelines") + expect(collected_metric[:stats][:pipelines][pipeline_id.to_sym]).to_not include(:batch) end end From 2b0226014b91959921760c4984669931931b0dd9 Mon Sep 17 00:00:00 2001 From: andsel Date: Thu, 18 Dec 2025 17:53:15 +0100 Subject: [PATCH 3/3] Fix, clear collectors metrics for pipeline batch part. --- logstash-core/lib/logstash/java_pipeline.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/logstash-core/lib/logstash/java_pipeline.rb b/logstash-core/lib/logstash/java_pipeline.rb index de1c64bd0e1..455aaec6220 100644 --- a/logstash-core/lib/logstash/java_pipeline.rb +++ b/logstash-core/lib/logstash/java_pipeline.rb @@ -548,6 +548,7 @@ def clear_pipeline_metrics collector.clear("stats/pipelines/#{pipeline_id}/plugins") collector.clear("stats/pipelines/#{pipeline_id}/events") collector.clear("stats/pipelines/#{pipeline_id}/flow") + collector.clear("stats/pipelines/#{pipeline_id}/batch") end end