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
2 changes: 1 addition & 1 deletion fluent-plugin-logtail.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require 'date'

Gem::Specification.new do |s|
s.name = 'fluent-plugin-logtail'
s.version = '0.1.1'
s.version = '0.2.1'
s.date = Date.today.to_s
s.summary = 'Logtail.com plugin for Fluentd'
s.description = 'Streams Fluentd logs to the Logtail.com logging service.'
Expand Down
5 changes: 3 additions & 2 deletions lib/fluent/plugin/out_logtail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class LogtailOutput < Fluent::BufferedOutput

VERSION = "0.1.1".freeze
CONTENT_TYPE = "application/msgpack".freeze
HOST = "in.logtail.com".freeze
PORT = 443
PATH = "/".freeze
MAX_ATTEMPTS = 3.freeze
Expand All @@ -16,9 +15,11 @@ class LogtailOutput < Fluent::BufferedOutput

config_param :source_token, :string, secret: true
config_param :ip, :string, default: nil
config_param :ingesting_host, :string, default: "in.logs.betterstack.com"

def configure(conf)
@source_token = conf["source_token"]
@ingesting_host = conf["ingesting_host"]
super
end

Expand Down Expand Up @@ -90,7 +91,7 @@ def force_utf8_string_values(data)
end

def build_http_client
http = Net::HTTP.new(HOST, PORT)
http = Net::HTTP.new(@ingesting_host, PORT)
http.use_ssl = true
# Verification on Windows fails despite having a valid certificate.
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
Expand Down
44 changes: 40 additions & 4 deletions spec/fluent/plugin/out_logtail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
}
end

let(:cloud_config) do
%{
source_token abcd1234
ingesting_host s1234.eu-nbg-2.betterstackdata.com
}
end

let(:driver) do
tag = "test"
Fluent::Test::BufferedOutputTestDriver.new(Fluent::LogtailOutput, tag) {
Expand All @@ -19,6 +26,19 @@ def format(tag, time, record)
end
}.configure(config)
end

let(:cloud_driver) do
tag = "test"
Fluent::Test::BufferedOutputTestDriver.new(Fluent::LogtailOutput, tag) {
# v0.12's test driver assume format definition. This simulates ObjectBufferedOutput format
if !defined?(Fluent::Plugin::Output)
def format(tag, time, record)
[time, record].to_msgpack
end
end
}.configure(cloud_config)
end

let(:record) do
{'age' => 26, 'request_id' => '42', 'parent_id' => 'parent', 'routing_id' => 'routing'}
end
Expand All @@ -28,8 +48,8 @@ def format(tag, time, record)
end

describe "#write" do
it "should send a chunked request to the Logtail API" do
stub = stub_request(:post, "https://in.logtail.com/").
it "should send a chunked request to the Logtail API using default host" do
stub = stub_request(:post, "https://in.logs.betterstack.com/").
with(
: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")),
: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'}
Expand All @@ -43,7 +63,7 @@ def format(tag, time, record)
end

it "handles 500s" do
stub = stub_request(:post, "https://in.logtail.com/").to_return(:status => 500, :body => "", :headers => {})
stub = stub_request(:post, "https://in.logs.betterstack.com/").to_return(:status => 500, :body => "", :headers => {})

driver.emit(record)
driver.run
Expand All @@ -52,12 +72,28 @@ def format(tag, time, record)
end

it "handle auth failures" do
stub = stub_request(:post, "https://in.logtail.com/").to_return(:status => 403, :body => "", :headers => {})
stub = stub_request(:post, "https://in.logs.betterstack.com/").to_return(:status => 403, :body => "", :headers => {})

driver.emit(record)
driver.run

expect(stub).to have_been_requested.times(1)
end
end

describe "#write to cloud" do
Copy link
Member

Choose a reason for hiding this comment

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

cloud infra is tested should send a chunked request to the Logtail API, here's driver instead of cloud_driver

Suggested change
describe "#write to cloud" do
describe "#should send a chunked request to the Logtail API using default host" do

it "should send a chunked request to the Logtail API" do
stub = stub_request(:post, "https://s1234.eu-nbg-2.betterstackdata.com/").
with(
: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")),
: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'}
).
to_return(:status => 202, :body => "", :headers => {})

cloud_driver.emit(record)
cloud_driver.run

expect(stub).to have_been_requested.times(1)
end
end
end
Loading