Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
Signed-off-by: Athishpranav2003 <[email protected]>
  • Loading branch information
Athishpranav2003 committed Aug 2, 2024
1 parent 08389fd commit d1a545b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/fluent/plugin/in_prometheus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion spec/fluent/plugin/in_prometheus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'fluent/test/driver/input'

require 'net/http'
require 'zlib'

describe Fluent::Plugin::PrometheusInput do
CONFIG = %[
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d1a545b

Please sign in to comment.