From d1a545bc0f5dec49dac1a1078bc4b3fcd34eb90d Mon Sep 17 00:00:00 2001 From: Athishpranav2003 Date: Fri, 2 Aug 2024 10:14:44 +0530 Subject: [PATCH] Addressed comments Signed-off-by: Athishpranav2003 --- lib/fluent/plugin/in_prometheus.rb | 6 +++--- spec/fluent/plugin/in_prometheus_spec.rb | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/fluent/plugin/in_prometheus.rb b/lib/fluent/plugin/in_prometheus.rb index 9bc01d6..ab201de 100644 --- a/lib/fluent/plugin/in_prometheus.rb +++ b/lib/fluent/plugin/in_prometheus.rb @@ -188,7 +188,7 @@ def start_webrick end def all_metrics - response_headers(::Prometheus::Client::Formats::Text.marshal(@registry)) + response(::Prometheus::Client::Formats::Text.marshal(@registry)) rescue => e [500, { 'Content-Type' => 'text/plain' }, e.to_s] end @@ -201,7 +201,7 @@ def all_workers_metrics full_result.add_metrics(resp.body) end end - response_headers(full_result.get_metrics) + response(full_result.get_metrics) rescue => e [500, { 'Content-Type' => 'text/plain' }, e.to_s] end @@ -230,7 +230,7 @@ def do_request(host:, port:, secure:) end end - def response_headers(metrics) + def response(metrics) body = nil case @content_encoding when :gzip diff --git a/spec/fluent/plugin/in_prometheus_spec.rb b/spec/fluent/plugin/in_prometheus_spec.rb index 0e73b9b..08caae0 100644 --- a/spec/fluent/plugin/in_prometheus_spec.rb +++ b/spec/fluent/plugin/in_prometheus_spec.rb @@ -3,6 +3,7 @@ require 'fluent/test/driver/input' require 'net/http' +require 'zlib' describe Fluent::Plugin::PrometheusInput do CONFIG = %[ @@ -226,6 +227,7 @@ registry.counter(:test,docstring: "Testing metrics") unless registry.exist?(:test) Net::HTTP.start("127.0.0.1", port) do |http| req = Net::HTTP::Get.new("/metrics") + req['accept-encoding'] = nil res = http.request(req) expect(res.body).to include("test Testing metrics") end @@ -243,8 +245,10 @@ registry.counter(:test,docstring: "Testing metrics") unless registry.exist?(:test) Net::HTTP.start("127.0.0.1", port) do |http| req = Net::HTTP::Get.new("/metrics") + req['accept-encoding'] = nil res = http.request(req) - expect(res.body).to include("test Testing metrics") + gzip = Zlib::GzipReader.new(StringIO.new(res.body.to_s)) + expect(gzip.read).to include("test Testing metrics") end end end