Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gzip POST bodies #257

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/influxdb/client/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'cgi'
require 'net/http'
require 'net/https'
require 'zlib'

module InfluxDB
# rubocop:disable Metrics/MethodLength
Expand All @@ -22,7 +23,8 @@ def get(url, options = {})
end

def post(url, data)
headers = { "Content-Type" => "application/octet-stream" }
headers = { "Content-Type" => "application/octet-stream",
"Content-Encoding" => "gzip" }
connect_with_retry do |http|
response = do_request http, Net::HTTP::Post.new(url, headers), data

Expand Down Expand Up @@ -70,7 +72,7 @@ def connect_with_retry

def do_request(http, req, data = nil)
req.basic_auth config.username, config.password if basic_auth?
req.body = data if data
req.body = Zlib.gzip(data, level: Zlib::BEST_SPEED) if data
http.request(req)
end

Expand Down
6 changes: 3 additions & 3 deletions spec/influxdb/cases/retry_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
stub_request(:post, "http://influxdb.test:9999/write").with(
query: { u: "username", p: "password", precision: 's', db: database },
headers: { "Content-Type" => "application/octet-stream" },
body: body
body: Zlib.gzip(body, level: 1)
).to_raise(Timeout::Error)
end

Expand Down Expand Up @@ -76,7 +76,7 @@
.with(
query: { u: "username", p: "password", precision: 's', db: database },
headers: { "Content-Type" => "application/octet-stream" },
body: body
body: Zlib.gzip(body, level: 1)
)
.to_raise(Timeout::Error).then
.to_raise(Timeout::Error).then
Expand All @@ -95,7 +95,7 @@
stub_request(:post, "http://influxdb.test:9999/write").with(
query: { u: "username", p: "password", precision: 's', db: database },
headers: { "Content-Type" => "application/octet-stream" },
body: body
body: Zlib.gzip(body, level: 1)
).to_return(status: 401)

expect { client.write_point(series, data) }.to raise_error(InfluxDB::AuthenticationError)
Expand Down
24 changes: 12 additions & 12 deletions spec/influxdb/cases/write_points_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
before do
stub_request(:post, "http://influxdb.test:9999/write").with(
query: { u: "username", p: "password", precision: 's', db: database },
headers: { "Content-Type" => "application/octet-stream" },
body: body
headers: { "Content-Type" => "application/octet-stream", "Content-Encoding" => "gzip" },
body: Zlib.gzip(body, level: 1)
).to_return(status: 204)
end

Expand Down Expand Up @@ -63,8 +63,8 @@
before do
stub_request(:post, "http://influxdb.test:9999/write").with(
query: { u: "username", p: "password", precision: 's', db: database },
headers: { "Content-Type" => "application/octet-stream" },
body: body
headers: { "Content-Type" => "application/octet-stream", "Content-Encoding" => "gzip" },
body: Zlib.gzip(body, level: 1)
).to_return(status: 204)
end

Expand All @@ -89,8 +89,8 @@
before do
stub_request(:post, "http://influxdb.test:9999/write").with(
query: { u: "username", p: "password", precision: 's', db: database },
headers: { "Content-Type" => "application/octet-stream" },
body: body
headers: { "Content-Type" => "application/octet-stream", "Content-Encoding" => "gzip" },
body: Zlib.gzip(body, level: 1)
).to_return(status: 204)
end

Expand Down Expand Up @@ -118,8 +118,8 @@
before do
stub_request(:post, "http://influxdb.test:9999/write").with(
query: { u: "username", p: "password", precision: 'ms', db: database },
headers: { "Content-Type" => "application/octet-stream" },
body: body
headers: { "Content-Type" => "application/octet-stream", "Content-Encoding" => "gzip" },
body: Zlib.gzip(body, level: 1)
).to_return(status: 204)
end
it "should POST multiple points" do
Expand All @@ -144,8 +144,8 @@
before do
stub_request(:post, "http://influxdb.test:9999/write").with(
query: { u: "username", p: "password", precision: 's', db: database, rp: 'rp_1_hour' },
headers: { "Content-Type" => "application/octet-stream" },
body: body
headers: { "Content-Type" => "application/octet-stream", "Content-Encoding" => "gzip" },
body: Zlib.gzip(body, level: 1)
).to_return(status: 204)
end
it "should POST multiple points" do
Expand All @@ -170,8 +170,8 @@
before do
stub_request(:post, "http://influxdb.test:9999/write").with(
query: { u: "username", p: "password", precision: 's', db: 'overriden_db' },
headers: { "Content-Type" => "application/octet-stream" },
body: body
headers: { "Content-Type" => "application/octet-stream", "Content-Encoding" => "gzip" },
body: Zlib.gzip(body, level: 1)
).to_return(status: 204)
end
it "should POST multiple points" do
Expand Down
2 changes: 1 addition & 1 deletion spec/influxdb/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

it "POST" do
stub_request(:post, stub_url).with(headers: auth_header).to_return(status: 204)
expect(subject.post(url, {})).to be_a(Net::HTTPNoContent)
expect(subject.post(url, "{}")).to be_a(Net::HTTPNoContent)
end
end

Expand Down