fluent-plugin-http 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/fluent/plugin/out_http.rb +36 -16
  3. metadata +22 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 06eb1f3844b3acb3defcd95799816b80407ec3fc
4
- data.tar.gz: 560e89a57bb879563d10106738e26ebdc3a33679
2
+ SHA256:
3
+ metadata.gz: d88d022ba37439ff21cff59e0bd324c078b4626b24e9850d0b8b5f3200f54846
4
+ data.tar.gz: ac659d21eee4da63c7082cc67f1a2f7141075bd6f35f7c6cedb098fc3cf8e189
5
5
  SHA512:
6
- metadata.gz: ec9675ab52b62d921e94d8c2a10bf2c9b14b8808cb606d648d23c64678b22471b243d9275165d562c22cb63ab883b37008395f31af048e507a41e57aeb4fbd3e
7
- data.tar.gz: 0ed6223fcd2c1afb7adfa16c7d9a8d8277e9dc8ee4e7eb2fee6ad97be7bab75e33bde5c297a56ca56a44aa3bc905a3632b89ad7e4801fe225ffd38b940a29815
6
+ metadata.gz: d6882a0898632b3422fe58817c035e32428273ea8043783c1d693f2bc758cc8ff224728a909d2980f6e2eee2c78d75777bd8c417d4f8384736ea3c5378d5806f
7
+ data.tar.gz: 2c04dfbae65ce4253dbff47863a82fd4de4c9e1f87adab79c1fc85eef68d9c1bd60886fba48589259169d3d73cbfa700a1397ec9747e64775b069337291d3a0b
@@ -20,6 +20,9 @@ module Fluent
20
20
  desc 'Authorization token'
21
21
  config_param :authorization_token, :string, default: nil, secret: true
22
22
 
23
+ desc 'Keep-alive timeout'
24
+ config_param :keep_alive_timeout, :float, default: 60.0
25
+
23
26
  def initialize
24
27
  require 'fluent/plugin/http/error'
25
28
 
@@ -36,16 +39,7 @@ module Fluent
36
39
  @url = validate_url(url)
37
40
  @accept_status_code = validate_accept_status_code(accept_status_code)
38
41
  @authorization_token = validate_authorization_token(authorization_token)
39
- end
40
-
41
- # Hook method that is called at the startup
42
- #
43
- # @return void
44
- def start
45
- super
46
-
47
- is_https = url.scheme == 'https'
48
- @http = Net::HTTP.start(url.host, url.port, use_ssl: is_https)
42
+ @keep_alive_timeout = validate_keep_alive_timeout(keep_alive_timeout)
49
43
  end
50
44
 
51
45
  # Hook method that is called at the shutdown
@@ -54,7 +48,7 @@ module Fluent
54
48
  def shutdown
55
49
  super
56
50
 
57
- http.finish
51
+ disconnect
58
52
  end
59
53
 
60
54
  # Serializes the event
@@ -73,6 +67,8 @@ module Fluent
73
67
  # formatted events
74
68
  # @return void
75
69
  def write(chunk)
70
+ return if chunk.empty?
71
+
76
72
  records = []
77
73
 
78
74
  chunk.msgpack_each do |tag_time_record|
@@ -80,7 +76,7 @@ module Fluent
80
76
  end
81
77
 
82
78
  post_records = post_records_request(records)
83
- response = http.request(post_records)
79
+ response = connect.request(post_records)
84
80
 
85
81
  return if accept_status_code.include?(response.code)
86
82
  raise ResponseError.error(post_records, response)
@@ -88,12 +84,30 @@ module Fluent
88
84
 
89
85
  private
90
86
 
91
- attr_reader :http
87
+ JSON_MIME_TYPE = 'application/json'.freeze
88
+ private_constant :JSON_MIME_TYPE
92
89
 
93
- JSON_MIME_TYPE = 'application/json'
94
- USER_AGENT = 'FluentPluginHTTP'
90
+ USER_AGENT = 'FluentPluginHTTP'.freeze
91
+ private_constant :USER_AGENT
95
92
 
96
- private_constant :USER_AGENT, :JSON_MIME_TYPE
93
+ HTTPS_SCHEME = 'https'.freeze
94
+ private_constant :HTTPS_SCHEME
95
+
96
+ def connect
97
+ @http ||= Net::HTTP.start(
98
+ url.host,
99
+ url.port,
100
+ use_ssl: url.scheme == HTTPS_SCHEME,
101
+ keep_alive_timeout: keep_alive_timeout
102
+ )
103
+ end
104
+
105
+ def disconnect
106
+ return unless defined?(@http)
107
+ return unless @http
108
+
109
+ @http.finish
110
+ end
97
111
 
98
112
  def post_records_request(records)
99
113
  Net::HTTP::Post.new(url).tap do |request|
@@ -139,5 +153,11 @@ module Fluent
139
153
 
140
154
  raise Fluent::ConfigError, "Invalid authorization token: #{value.inspect}"
141
155
  end
156
+
157
+ def validate_keep_alive_timeout(value)
158
+ return value if value >= 0
159
+
160
+ raise Fluent::ConfigError, "Invalid keep-alive timeout: #{value.inspect}"
161
+ end
142
162
  end
143
163
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2017-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: oj
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '3.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,75 +53,75 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.7'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '11.3'
61
+ version: '0.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '11.3'
68
+ version: '0.10'
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry
70
+ name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.10'
75
+ version: '11.3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.10'
82
+ version: '11.3'
83
83
  - !ruby/object:Gem::Dependency
84
- name: test-unit
84
+ name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.2'
89
+ version: '0.51'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '3.2'
96
+ version: '0.51'
97
97
  - !ruby/object:Gem::Dependency
98
- name: webmock
98
+ name: test-unit
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '2.1'
103
+ version: '3.2'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '2.1'
110
+ version: '3.2'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rubocop
112
+ name: webmock
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.45'
117
+ version: '2.1'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.45'
124
+ version: '2.1'
125
125
  description:
126
126
  email:
127
127
  executables: []
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 2.6.8
153
+ rubygems_version: 2.7.1
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Fluentd output plugin that sends event records via HTTP