Skip to content

Commit 8af763f

Browse files
authored
Support specifying the ingest host (#6)
1 parent 6ec3e91 commit 8af763f

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

fluent-plugin-logtail.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require 'date'
33

44
Gem::Specification.new do |s|
55
s.name = 'fluent-plugin-logtail'
6-
s.version = '0.1.1'
6+
s.version = '0.2.1'
77
s.date = Date.today.to_s
88
s.summary = 'Logtail.com plugin for Fluentd'
99
s.description = 'Streams Fluentd logs to the Logtail.com logging service.'

lib/fluent/plugin/out_logtail.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class LogtailOutput < Fluent::BufferedOutput
77

88
VERSION = "0.1.1".freeze
99
CONTENT_TYPE = "application/msgpack".freeze
10-
HOST = "in.logtail.com".freeze
1110
PORT = 443
1211
PATH = "/".freeze
1312
MAX_ATTEMPTS = 3.freeze
@@ -16,9 +15,11 @@ class LogtailOutput < Fluent::BufferedOutput
1615

1716
config_param :source_token, :string, secret: true
1817
config_param :ip, :string, default: nil
18+
config_param :ingesting_host, :string, default: "in.logs.betterstack.com"
1919

2020
def configure(conf)
2121
@source_token = conf["source_token"]
22+
@ingesting_host = conf["ingesting_host"]
2223
super
2324
end
2425

@@ -90,7 +91,7 @@ def force_utf8_string_values(data)
9091
end
9192

9293
def build_http_client
93-
http = Net::HTTP.new(HOST, PORT)
94+
http = Net::HTTP.new(@ingesting_host, PORT)
9495
http.use_ssl = true
9596
# Verification on Windows fails despite having a valid certificate.
9697
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

spec/fluent/plugin/out_logtail_spec.rb

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
}
99
end
1010

11+
let(:cloud_config) do
12+
%{
13+
source_token abcd1234
14+
ingesting_host s1234.eu-nbg-2.betterstackdata.com
15+
}
16+
end
17+
1118
let(:driver) do
1219
tag = "test"
1320
Fluent::Test::BufferedOutputTestDriver.new(Fluent::LogtailOutput, tag) {
@@ -19,6 +26,19 @@ def format(tag, time, record)
1926
end
2027
}.configure(config)
2128
end
29+
30+
let(:cloud_driver) do
31+
tag = "test"
32+
Fluent::Test::BufferedOutputTestDriver.new(Fluent::LogtailOutput, tag) {
33+
# v0.12's test driver assume format definition. This simulates ObjectBufferedOutput format
34+
if !defined?(Fluent::Plugin::Output)
35+
def format(tag, time, record)
36+
[time, record].to_msgpack
37+
end
38+
end
39+
}.configure(cloud_config)
40+
end
41+
2242
let(:record) do
2343
{'age' => 26, 'request_id' => '42', 'parent_id' => 'parent', 'routing_id' => 'routing'}
2444
end
@@ -28,8 +48,8 @@ def format(tag, time, record)
2848
end
2949

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

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

4868
driver.emit(record)
4969
driver.run
@@ -52,12 +72,28 @@ def format(tag, time, record)
5272
end
5373

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

5777
driver.emit(record)
5878
driver.run
5979

6080
expect(stub).to have_been_requested.times(1)
6181
end
6282
end
83+
84+
describe "#write to cloud" do
85+
it "should send a chunked request to the Logtail API" do
86+
stub = stub_request(:post, "https://s1234.eu-nbg-2.betterstackdata.com/").
87+
with(
88+
: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")),
89+
: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'}
90+
).
91+
to_return(:status => 202, :body => "", :headers => {})
92+
93+
cloud_driver.emit(record)
94+
cloud_driver.run
95+
96+
expect(stub).to have_been_requested.times(1)
97+
end
98+
end
6399
end

0 commit comments

Comments
 (0)