Skip to content
Merged
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
9 changes: 6 additions & 3 deletions lib/logtail/log_devices/http.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "base64"
require "msgpack"
require "net/https"
require "zlib"

require "logtail/config"
require "logtail/log_devices/http/flushable_dropping_sized_queue"
Expand Down Expand Up @@ -168,7 +169,7 @@ def verify_delivery!
You can enable internal Logtail debug logging with the following:

Logtail::Config.instance.debug_logger = ::Logger.new(STDOUT)
MESSAGE
MESSAGE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this got autoformatted

end
end

Expand All @@ -179,7 +180,7 @@ def verify_delivery!
You can enable internal debug logging with the following:

Logtail::Config.instance.debug_logger = ::Logger.new(STDOUT)
MESSAGE
MESSAGE
end

private
Expand All @@ -205,8 +206,10 @@ def build_request(msgs)
req = Net::HTTP::Post.new(path)
req['Authorization'] = authorization_payload
req['Content-Type'] = CONTENT_TYPE
req['Content-Encoding'] = 'gzip'
req['User-Agent'] = USER_AGENT
req.body = msgs.map { |msg| force_utf8_encoding(msg.to_hash) }.to_msgpack
uncompressed = msgs.map { |msg| force_utf8_encoding(msg.to_hash) }.to_msgpack
req.body = Zlib::Deflate.deflate(uncompressed, Zlib::BEST_SPEED)
req
end

Expand Down
2 changes: 1 addition & 1 deletion lib/logtail/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Logtail
VERSION = "0.1.15"
VERSION = "0.1.16"
end
21 changes: 12 additions & 9 deletions spec/logtail/log_devices/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
request_queue = http.instance_variable_get(:@request_queue)
request_attempt = request_queue.deq
expect(request_attempt.request).to be_kind_of(Net::HTTP::Post)
expect(request_attempt.request.body).to start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT"))
decompressed_body = Zlib::Inflate.inflate(request_attempt.request.body)
expect(decompressed_body).to start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT"))

message_queue = http.instance_variable_get(:@msg_queue)
expect(message_queue.size).to eq(0)
Expand All @@ -126,14 +127,16 @@

it "should deliver requests on an interval" do
stub = stub_request(:post, "https://in.logs.betterstack.com/").
with(
:body => start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT")),
:headers => {
'Authorization' => 'Bearer MYKEY',
'Content-Type' => 'application/msgpack',
'User-Agent' => "Logtail Ruby/#{Logtail::VERSION} (HTTP)"
}
).
with do |request|
decompressed_body = Zlib::Inflate.inflate(request.body)
expect(decompressed_body).to start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT"))

expect(request.headers['Authorization']).to eq('Bearer MYKEY')
expect(request.headers['Content-Type']).to eq('application/msgpack')
expect(request.headers['User-Agent']).to eq("Logtail Ruby/#{Logtail::VERSION} (HTTP)")

true
end.
to_return(:status => 200, :body => "", :headers => {})

http = described_class.new("MYKEY", flush_interval: 0.1)
Expand Down
Loading