From 2cb2bc4190af1fa83eeed249ed5f2f48da9e26e7 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Fri, 28 Feb 2025 21:38:35 +0000 Subject: [PATCH] Fix empty node stats pipelines (#17185) Fixed an issue where the `/_node/stats` API displayed empty pipeline metrics when X-Pack monitoring was enabled (cherry picked from commit 86785815bd7708d104eafc718b947eb5c2be576e) --- logstash-core/lib/logstash/api/commands/stats.rb | 6 +++--- qa/integration/services/monitoring_api.rb | 6 ++++++ x-pack/qa/integration/monitoring/direct_shipping_spec.rb | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/logstash-core/lib/logstash/api/commands/stats.rb b/logstash-core/lib/logstash/api/commands/stats.rb index cd26524b27a..5bf1b3e3a09 100644 --- a/logstash-core/lib/logstash/api/commands/stats.rb +++ b/logstash-core/lib/logstash/api/commands/stats.rb @@ -185,9 +185,9 @@ def report(stats, extended_stats = nil, opts = {}) :reloads => stats[:reloads], :queue => stats[:queue], :pipeline => { - :workers => stats[:config][:workers], - :batch_size => stats[:config][:batch_size], - :batch_delay => stats[:config][:batch_delay], + :workers => stats.dig(:config, :workers), + :batch_size => stats.dig(:config, :batch_size), + :batch_delay => stats.dig(:config, :batch_delay), } } ret[:dead_letter_queue] = stats[:dlq] if stats.include?(:dlq) diff --git a/qa/integration/services/monitoring_api.rb b/qa/integration/services/monitoring_api.rb index 76372f25b5e..34b52634f11 100644 --- a/qa/integration/services/monitoring_api.rb +++ b/qa/integration/services/monitoring_api.rb @@ -31,6 +31,12 @@ def pipeline_stats(pipeline_id) stats_response.fetch("pipelines").fetch(pipeline_id) end + def pipelines_stats + resp = Manticore.get("http://localhost:#{@port}/_node/stats/pipelines").body + stats_response = JSON.parse(resp) + stats_response.fetch("pipelines") + end + def event_stats resp = Manticore.get("http://localhost:#{@port}/_node/stats").body stats_response = JSON.parse(resp) diff --git a/x-pack/qa/integration/monitoring/direct_shipping_spec.rb b/x-pack/qa/integration/monitoring/direct_shipping_spec.rb index bded6b36100..8d6dfdb3ca0 100644 --- a/x-pack/qa/integration/monitoring/direct_shipping_spec.rb +++ b/x-pack/qa/integration/monitoring/direct_shipping_spec.rb @@ -30,6 +30,12 @@ include_examples "record monitoring data to es" + it "gives pipelines stats" do + api = MonitoringAPI.new + stats = api.pipelines_stats + expect(stats.keys).not_to be_nil + end + after :all do @logstash_service.stop unless @logstash_service.nil? @elasticsearch_service.stop unless @elasticsearch_service.nil?