fluent-plugin-logtail 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0c8596cf46b0faa3a9d7e580d453d0cec5af12bd1b75d42232f72c57a834a7b
4
- data.tar.gz: 60b7f73e13bedafe63b2cbfb80338ba15644387c292312471cff7247e333df5d
3
+ metadata.gz: 6339c03a2fefcf1214248cb628ba8564a8a4bd7af09f791255a176432966da58
4
+ data.tar.gz: 1a42d046f7fa186b0fe42ea5eb85ca13ae84ba0e3e75997074aee19dc1b374ea
5
5
  SHA512:
6
- metadata.gz: 4103a98491a69624c5354facafd04735c3ba85a2ceb2d8c179435e46f9c82e0ce3376287717e830635c75842ee22aed02822d2cf1afe1f1a931dc820ae2cc063
7
- data.tar.gz: 83bb7f6e2b67ad1700f1b59b1f52efaa4d33d386e671e98af0dd7b8686df93bb44188f66a7ec42dfad10412df7bbe47323894cf11e39314e8e1fc026f0e98629
6
+ metadata.gz: 2a78ee4379f721fb0c5a689c9fb9de10c47bfae2bca4097f5e22a1a9eed2e3139c034c098a4bd22ad5f9e00c6d8eddac74c77c8403665a064dd4e237f5217e85
7
+ data.tar.gz: 4aef1ed3577e83b2c17b3e5dd23b5a54c52d105547c80eb493302134c49812154286a5dc56902beb00fb3184b0bf2df83441e999fede563f9d615e96edc864a3
@@ -3,7 +3,7 @@ require 'date'
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'fluent-plugin-logtail'
6
- s.version = '0.1.0'
6
+ s.version = '0.1.1'
7
7
  s.date = Date.today.to_s
8
8
  s.summary = 'Logtail.com plugin for Fluentd'
9
9
  s.description = 'Streams Fluentd logs to the Logtail.com logging service.'
@@ -20,7 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.required_ruby_version = Gem::Requirement.new(">= 2.4.0".freeze)
21
21
 
22
22
  s.add_runtime_dependency('fluentd', '> 1', '< 2')
23
- s.add_runtime_dependency('http', '~> 2.0', '>= 2.0.3')
24
23
 
25
24
  s.add_development_dependency('rspec', '~> 3.4')
26
25
  s.add_development_dependency('test-unit', '~> 3.3.9')
@@ -1,44 +1,29 @@
1
1
  require 'fluent/output'
2
+ require 'net/https'
2
3
 
3
4
  module Fluent
4
5
  class LogtailOutput < Fluent::BufferedOutput
5
6
  Fluent::Plugin.register_output('logtail', self)
6
7
 
7
- VERSION = "0.1.0".freeze
8
+ VERSION = "0.1.1".freeze
8
9
  CONTENT_TYPE = "application/msgpack".freeze
9
- HOST = "https://in.logtail.com".freeze
10
+ HOST = "in.logtail.com".freeze
11
+ PORT = 443
10
12
  PATH = "/".freeze
11
13
  MAX_ATTEMPTS = 3.freeze
12
14
  RETRYABLE_CODES = [429, 500, 502, 503, 504].freeze
13
- USER_AGENT = "Logtail Logstash/#{VERSION}".freeze
15
+ USER_AGENT = "Logtail Fluentd/#{VERSION}".freeze
14
16
 
15
17
  config_param :source_token, :string, secret: true
16
18
  config_param :ip, :string, default: nil
17
19
 
18
20
  def configure(conf)
19
- source_token = conf["source_token"]
20
- @headers = {
21
- "Authorization" => "Bearer #{source_token}",
22
- "Content-Type" => CONTENT_TYPE,
23
- "User-Agent" => USER_AGENT
24
- }
25
- super
26
- end
27
-
28
- def start
29
- super
30
- require 'http'
31
- HTTP.default_options = {:keep_alive_timeout => 29}
32
- @http_client = HTTP.persistent(HOST)
33
- end
34
-
35
- def shutdown
36
- @http_client.close if @http_client
21
+ @source_token = conf["source_token"]
37
22
  super
38
23
  end
39
24
 
40
25
  def format(tag, time, record)
41
- record.merge("dt" => Time.at(time).utc.iso8601).to_msgpack
26
+ force_utf8_string_values(record.merge("dt" => Time.at(time).utc.iso8601)).to_msgpack
42
27
  end
43
28
 
44
29
  def write(chunk)
@@ -52,11 +37,19 @@ module Fluent
52
37
  return false
53
38
  end
54
39
 
40
+ http = build_http_client
55
41
  body = chunk.read
56
- response = @http_client.headers(@headers).post(PATH, body: body)
57
- response.flush
58
- code = response.code
59
42
 
43
+ begin
44
+ resp = http.start do |conn|
45
+ req = build_request(body)
46
+ conn.request(req)
47
+ end
48
+ ensure
49
+ http.finish if http.started?
50
+ end
51
+
52
+ code = resp.code.to_i
60
53
  if code >= 200 && code <= 299
61
54
  true
62
55
  elsif RETRYABLE_CODES.include?(code)
@@ -76,5 +69,38 @@ module Fluent
76
69
  sleep_for = sleep_for <= 60 ? sleep_for : 60
77
70
  (sleep_for / 2) + (rand(0..sleep_for) / 2)
78
71
  end
72
+
73
+ def force_utf8_string_values(data)
74
+ data.transform_values do |val|
75
+ if val.is_a?(Hash)
76
+ force_utf8_string_values(val)
77
+ elsif val.respond_to?(:force_encoding)
78
+ val.force_encoding('UTF-8')
79
+ else
80
+ val
81
+ end
82
+ end
83
+ end
84
+
85
+ def build_http_client
86
+ http = Net::HTTP.new(HOST, PORT)
87
+ http.use_ssl = true
88
+ # Verification on Windows fails despite having a valid certificate.
89
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
90
+ http.read_timeout = 30
91
+ http.ssl_timeout = 10
92
+ http.open_timeout = 10
93
+ http
94
+ end
95
+
96
+ def build_request(body)
97
+ path = '/'
98
+ req = Net::HTTP::Post.new(path)
99
+ req["Authorization"] = "Bearer #{@source_token}"
100
+ req["Content-Type"] = CONTENT_TYPE
101
+ req["User-Agent"] = USER_AGENT
102
+ req.body = body
103
+ req
104
+ end
79
105
  end
80
106
  end
@@ -32,9 +32,9 @@ describe Fluent::LogtailOutput do
32
32
  stub = stub_request(:post, "https://in.logtail.com/").
33
33
  with(
34
34
  :body => start_with("\x85\xA3age\x1A\xAArequest_id\xA242\xA9parent_id\xA6parent\xAArouting_id\xA7routing\xA2dt\xB4".force_encoding("ASCII-8BIT")),
35
- :headers => {'Authorization'=>'Bearer abcd1234', 'Connection'=>'Keep-Alive', 'Content-Type'=>'application/msgpack', 'User-Agent'=>'Logtail Logstash/0.1.0'}
35
+ :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'}
36
36
  ).
37
- to_return(:status => 200, :body => "", :headers => {})
37
+ to_return(:status => 202, :body => "", :headers => {})
38
38
 
39
39
  driver.emit(record)
40
40
  driver.run
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-logtail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logtail.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-31 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -30,26 +30,6 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'
33
- - !ruby/object:Gem::Dependency
34
- name: http
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '2.0'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 2.0.3
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '2.0'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 2.0.3
53
33
  - !ruby/object:Gem::Dependency
54
34
  name: rspec
55
35
  requirement: !ruby/object:Gem::Requirement