Skip to content

Commit 778fc64

Browse files
authored
Merge pull request #4 from section/messagepack-array-prefix
Add messagepack array prefix so that multiple records will be processed.
2 parents 3135ea3 + d49388d commit 778fc64

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/fluent/plugin/out_logtail.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ def deliver(chunk, attempt)
3838
end
3939

4040
http = build_http_client
41-
body = chunk.read
41+
records=0
42+
chunk.each do
43+
records=records+1
44+
end
45+
body = [0xdd,records].pack("CN")
46+
body << chunk.read
4247

4348
begin
4449
resp = http.start do |conn|
4550
req = build_request(body)
51+
log.debug("sending #{req.body.length} bytes to logtail")
4652
conn.request(req)
4753
end
4854
ensure
@@ -51,6 +57,7 @@ def deliver(chunk, attempt)
5157

5258
code = resp.code.to_i
5359
if code >= 200 && code <= 299
60+
log.debug "POST request to logtail was responded to with status code #{code}"
5461
true
5562
elsif RETRYABLE_CODES.include?(code)
5663
sleep_time = sleep_for_attempt(attempt)

spec/fluent/plugin/out_logtail_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def format(tag, time, record)
3131
it "should send a chunked request to the Logtail API" do
3232
stub = stub_request(:post, "https://in.logtail.com/").
3333
with(
34-
:body => start_with("\x85\xA3age\x1A\xAArequest_id\xA242\xA9parent_id\xA6parent\xAArouting_id\xA7routing\xA2dt\xB4".force_encoding("ASCII-8BIT")),
34+
:body => start_with("\xDD\x00\x00\x00\x01\x85\xA3age\x1A\xAArequest_id\xA242\xA9parent_id\xA6parent\xAArouting_id\xA7routing\xA2dt\xB4".force_encoding("ASCII-8BIT")),
3535
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer abcd1234', 'Content-Type'=>'application/msgpack', 'User-Agent'=>'Logtail Fluentd/0.1.1'}
3636
).
3737
to_return(:status => 202, :body => "", :headers => {})

0 commit comments

Comments
 (0)