gzip metrics
This commit is contained in:
parent
a5140aa55c
commit
fc1fd12581
|
@ -2,6 +2,8 @@
|
|||
|
||||
require 'webrick'
|
||||
require 'timeout'
|
||||
require 'zlib'
|
||||
require 'stringio'
|
||||
|
||||
module PrometheusExporter::Server
|
||||
class WebServer
|
||||
|
@ -22,7 +24,16 @@ module PrometheusExporter::Server
|
|||
res['ContentType'] = 'text/plain; charset=utf-8'
|
||||
if req.path == '/metrics'
|
||||
res.status = 200
|
||||
res.body = metrics
|
||||
if req.header["accept-encoding"].to_s.include?("gzip")
|
||||
sio = StringIO.new
|
||||
writer = Zlib::GzipWriter.new(sio)
|
||||
writer.write(metrics)
|
||||
writer.close
|
||||
res.body = sio.string
|
||||
res.header["content-encoding"] = "gzip"
|
||||
else
|
||||
res.body = metrics
|
||||
end
|
||||
elsif req.path == '/send-metrics'
|
||||
handle_metrics(req, res)
|
||||
else
|
||||
|
|
|
@ -90,7 +90,16 @@ class PrometheusExporterTest < Minitest::Test
|
|||
|
||||
assert_match(/199/, collector.prometheus_metrics_text)
|
||||
|
||||
body = Net::HTTP.get(URI("http://localhost:#{port}/metrics"))
|
||||
body = nil
|
||||
|
||||
Net::HTTP.new("localhost", port).start do |http|
|
||||
request = Net::HTTP::Get.new "/metrics"
|
||||
|
||||
http.request(request) do |response|
|
||||
assert_equal(["gzip"], response.to_hash["content-encoding"])
|
||||
body = response.body
|
||||
end
|
||||
end
|
||||
assert_match(/199/, body)
|
||||
|
||||
one_minute = Time.now + 60
|
||||
|
|
Loading…
Reference in New Issue