logstash-output-http 5.2.3 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/LICENSE +199 -10
- data/README.md +1 -1
- data/docs/index.asciidoc +23 -2
- data/lib/logstash/outputs/http.rb +36 -14
- data/logstash-output-http.gemspec +2 -2
- data/spec/outputs/http_spec.rb +234 -22
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd850256e5336762a98ed5cc4ae699ddcc1c3c3bcb9e5382b033aa21aebd5fea
|
4
|
+
data.tar.gz: '08b1450d6eadd6ea8e7a9451d781c4fd78c3d7b199751616c1e74cabc75e3899'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11dce3822d80720abedca11fe586cb8d4c8384e44cb793da13bba509c571c48bf8b617a0545297fb49a8cd254d5374e5b4702dddf607e4bad04eaaf07b24e0d0
|
7
|
+
data.tar.gz: 62546e31fc1386c48a0b77c25f5e13093fc63bfc371ea1924ebc8737ec26b4855c4c0bd40cebbd5a2eac82288315da436c46772793c2fc86adcf848d79cfadd9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 5.4.0
|
2
|
+
- Introduce retryable unknown exceptions for "connection reset by peer" and "timeout" [#127](https://github.com/logstash-plugins/logstash-output-http/pull/127)
|
3
|
+
|
4
|
+
## 5.3.0
|
5
|
+
- Feat: support ssl_verification_mode option [#126](https://github.com/logstash-plugins/logstash-output-http/pull/126)
|
6
|
+
|
7
|
+
## 5.2.5
|
8
|
+
- Reduce amount of default logging on a failed request [#122](https://github.com/logstash-plugins/logstash-output-http/pull/122)
|
9
|
+
|
10
|
+
## 5.2.4
|
11
|
+
- Relax dependency on http_client mixin since current major works on both
|
12
|
+
|
1
13
|
## 5.2.3
|
2
14
|
- Fixed handling of empty `retryable_codes` [#99](https://github.com/logstash-plugins/logstash-output-http/pull/99)
|
3
15
|
|
data/LICENSE
CHANGED
@@ -1,13 +1,202 @@
|
|
1
|
-
Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
6
5
|
|
7
|
-
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2020 Elastic and contributors
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Logstash Plugin
|
2
2
|
|
3
|
-
[![Travis Build Status](https://travis-ci.
|
3
|
+
[![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-output-http.svg)](https://travis-ci.com/logstash-plugins/logstash-output-http)
|
4
4
|
|
5
5
|
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
6
6
|
|
data/docs/index.asciidoc
CHANGED
@@ -66,6 +66,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
66
66
|
| <<plugins-{type}s-{plugin}-retry_non_idempotent>> |<<boolean,boolean>>|No
|
67
67
|
| <<plugins-{type}s-{plugin}-retryable_codes>> |<<number,number>>|No
|
68
68
|
| <<plugins-{type}s-{plugin}-socket_timeout>> |<<number,number>>|No
|
69
|
+
| <<plugins-{type}s-{plugin}-ssl_verification_mode>> |<<string,string>>|No
|
69
70
|
| <<plugins-{type}s-{plugin}-truststore>> |a valid filesystem path|No
|
70
71
|
| <<plugins-{type}s-{plugin}-truststore_password>> |<<password,password>>|No
|
71
72
|
| <<plugins-{type}s-{plugin}-truststore_type>> |<<string,string>>|No
|
@@ -86,7 +87,10 @@ output plugins.
|
|
86
87
|
|
87
88
|
How many times should the client retry a failing URL. We highly recommend NOT setting this value
|
88
89
|
to zero if keepalive is enabled. Some servers incorrectly end keepalives early requiring a retry!
|
89
|
-
|
90
|
+
Only IO related failures will be retried, such as connection timeouts and unreachable hosts.
|
91
|
+
Valid but non 2xx HTTP responses will always be retried, regardless of the value of this setting,
|
92
|
+
unless `retry_failed` is set.
|
93
|
+
Note: if `retry_non_idempotent` is NOT set only GET, HEAD, PUT, DELETE, OPTIONS, and TRACE requests will be retried.
|
90
94
|
|
91
95
|
[id="plugins-{type}s-{plugin}-cacert"]
|
92
96
|
===== `cacert`
|
@@ -316,6 +320,7 @@ Set this to false if you don't want this output to retry failed requests
|
|
316
320
|
* Default value is `false`
|
317
321
|
|
318
322
|
If `automatic_retries` is enabled this will cause non-idempotent HTTP verbs (such as POST) to be retried.
|
323
|
+
This only affects connectivity related errors (see related `automatic_retries` setting).
|
319
324
|
|
320
325
|
[id="plugins-{type}s-{plugin}-retryable_codes"]
|
321
326
|
===== `retryable_codes`
|
@@ -333,6 +338,22 @@ If encountered as response codes this plugin will retry these requests
|
|
333
338
|
|
334
339
|
Timeout (in seconds) to wait for data on the socket. Default is `10s`
|
335
340
|
|
341
|
+
[id="plugins-{type}s-{plugin}-ssl_verification_mode"]
|
342
|
+
===== `ssl_verification_mode`
|
343
|
+
|
344
|
+
* Value type is <<string,string>>
|
345
|
+
* Supported values are: `full`, `none`
|
346
|
+
* Default value is `full`
|
347
|
+
|
348
|
+
Controls the verification of server certificates.
|
349
|
+
The `full` option verifies that the provided certificate is signed by a trusted authority (CA)
|
350
|
+
and also that the server’s hostname (or IP address) matches the names identified within the certificate.
|
351
|
+
|
352
|
+
The `none` setting performs no verification of the server’s certificate.
|
353
|
+
This mode disables many of the security benefits of SSL/TLS and should only be used after cautious consideration.
|
354
|
+
It is primarily intended as a temporary diagnostic mechanism when attempting to resolve TLS errors.
|
355
|
+
Using `none` in production environments is strongly discouraged.
|
356
|
+
|
336
357
|
[id="plugins-{type}s-{plugin}-truststore"]
|
337
358
|
===== `truststore`
|
338
359
|
|
@@ -384,4 +405,4 @@ See https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache
|
|
384
405
|
[id="plugins-{type}s-{plugin}-common-options"]
|
385
406
|
include::{include_path}/{type}.asciidoc[]
|
386
407
|
|
387
|
-
:default_codec!:
|
408
|
+
:default_codec!:
|
@@ -23,6 +23,12 @@ class LogStash::Outputs::Http < LogStash::Outputs::Base
|
|
23
23
|
::Manticore::SocketTimeout
|
24
24
|
]
|
25
25
|
|
26
|
+
RETRYABLE_UNKNOWN_EXCEPTION_STRINGS = [
|
27
|
+
/Connection reset by peer/i,
|
28
|
+
/Read Timed out/i
|
29
|
+
]
|
30
|
+
|
31
|
+
|
26
32
|
# This output lets you send events to a
|
27
33
|
# generic HTTP(S) endpoint
|
28
34
|
#
|
@@ -138,10 +144,11 @@ class LogStash::Outputs::Http < LogStash::Outputs::Base
|
|
138
144
|
end
|
139
145
|
|
140
146
|
def log_retryable_response(response)
|
147
|
+
retry_msg = @retry_failed ? 'will retry' : "won't retry"
|
141
148
|
if (response.code == 429)
|
142
|
-
@logger.debug? && @logger.debug("Encountered a 429 response,
|
149
|
+
@logger.debug? && @logger.debug("Encountered a 429 response, #{retry_msg}. This is not serious, just flow control via HTTP")
|
143
150
|
else
|
144
|
-
@logger.warn("Encountered a retryable HTTP request in HTTP output,
|
151
|
+
@logger.warn("Encountered a retryable HTTP request in HTTP output, #{retry_msg}", :code => response.code, :body => response.body)
|
145
152
|
end
|
146
153
|
end
|
147
154
|
|
@@ -252,16 +259,22 @@ class LogStash::Outputs::Http < LogStash::Outputs::Base
|
|
252
259
|
|
253
260
|
rescue => exception
|
254
261
|
will_retry = retryable_exception?(exception)
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
262
|
+
log_params = {
|
263
|
+
:url => url,
|
264
|
+
:method => @http_method,
|
265
|
+
:message => exception.message,
|
266
|
+
:class => exception.class.name,
|
267
|
+
:will_retry => will_retry
|
268
|
+
}
|
269
|
+
if @logger.debug?
|
270
|
+
# backtraces are big
|
271
|
+
log_params[:backtrace] = exception.backtrace
|
272
|
+
# headers can have sensitive data
|
273
|
+
log_params[:headers] = headers
|
274
|
+
# body can be big and may have sensitive data
|
275
|
+
log_params[:body] = body
|
276
|
+
end
|
277
|
+
log_failure("Could not fetch URL", log_params)
|
265
278
|
|
266
279
|
if will_retry
|
267
280
|
return :retry, event, attempt
|
@@ -288,12 +301,21 @@ class LogStash::Outputs::Http < LogStash::Outputs::Base
|
|
288
301
|
end
|
289
302
|
|
290
303
|
def retryable_exception?(exception)
|
291
|
-
|
304
|
+
retryable_manticore_exception?(exception) || retryable_unknown_exception?(exception)
|
305
|
+
end
|
306
|
+
|
307
|
+
def retryable_manticore_exception?(exception)
|
308
|
+
RETRYABLE_MANTICORE_EXCEPTIONS.any? {|me| exception.is_a?(me)}
|
309
|
+
end
|
310
|
+
|
311
|
+
def retryable_unknown_exception?(exception)
|
312
|
+
exception.is_a?(::Manticore::UnknownException) &&
|
313
|
+
RETRYABLE_UNKNOWN_EXCEPTION_STRINGS.any? { |snippet| exception.message =~ snippet }
|
292
314
|
end
|
293
315
|
|
294
316
|
# This is split into a separate method mostly to help testing
|
295
317
|
def log_failure(message, opts)
|
296
|
-
@logger.error(
|
318
|
+
@logger.error(message, opts)
|
297
319
|
end
|
298
320
|
|
299
321
|
# Format the HTTP body
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-output-http'
|
3
|
-
s.version = '5.
|
3
|
+
s.version = '5.4.0'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = "Sends events to a generic HTTP or HTTPS endpoint"
|
6
6
|
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
# Gem dependencies
|
22
22
|
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
23
|
-
s.add_runtime_dependency "logstash-mixin-http_client", ">=
|
23
|
+
s.add_runtime_dependency "logstash-mixin-http_client", ">= 7.1.0", "< 8.0.0"
|
24
24
|
|
25
25
|
s.add_development_dependency 'logstash-devutils'
|
26
26
|
s.add_development_dependency 'sinatra'
|
data/spec/outputs/http_spec.rb
CHANGED
@@ -3,6 +3,9 @@ require "logstash/outputs/http"
|
|
3
3
|
require "logstash/codecs/plain"
|
4
4
|
require "thread"
|
5
5
|
require "sinatra"
|
6
|
+
require "webrick"
|
7
|
+
require "webrick/https"
|
8
|
+
require 'openssl'
|
6
9
|
require_relative "../supports/compressed_requests"
|
7
10
|
|
8
11
|
PORT = rand(65535-1024) + 1025
|
@@ -22,9 +25,20 @@ class TestApp < Sinatra::Base
|
|
22
25
|
# on the fly uncompress gzip content
|
23
26
|
use CompressedRequests
|
24
27
|
|
25
|
-
|
28
|
+
set :environment, :production
|
29
|
+
set :sessions, false
|
30
|
+
|
31
|
+
@@server_settings = {
|
32
|
+
:AccessLog => [], # disable WEBrick logging
|
33
|
+
:Logger => WEBrick::BasicLog::new(nil, WEBrick::BasicLog::FATAL)
|
34
|
+
}
|
35
|
+
|
26
36
|
def self.server_settings
|
27
|
-
|
37
|
+
@@server_settings
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.server_settings=(settings)
|
41
|
+
@@server_settings = settings
|
28
42
|
end
|
29
43
|
|
30
44
|
def self.multiroute(methods, path, &block)
|
@@ -72,31 +86,22 @@ class TestApp < Sinatra::Base
|
|
72
86
|
end
|
73
87
|
end
|
74
88
|
|
75
|
-
RSpec.configure do
|
89
|
+
RSpec.configure do
|
76
90
|
#http://stackoverflow.com/questions/6557079/start-and-call-ruby-http-server-in-the-same-script
|
77
|
-
def
|
91
|
+
def start_app_and_wait(app, opts = {})
|
78
92
|
queue = Queue.new
|
79
93
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
queue.push("started")
|
85
|
-
end
|
86
|
-
rescue => e
|
87
|
-
puts "Error in webserver thread #{e}"
|
88
|
-
# ignore
|
94
|
+
Thread.start do
|
95
|
+
begin
|
96
|
+
app.start!({ server: 'WEBrick', port: PORT }.merge opts) do |server|
|
97
|
+
queue.push(server)
|
89
98
|
end
|
99
|
+
rescue => e
|
100
|
+
warn "Error starting app: #{e.inspect}" # ignore
|
90
101
|
end
|
91
|
-
|
92
|
-
t.daemon = true
|
93
|
-
t.start
|
94
|
-
queue.pop # blocks until the run! callback runs
|
95
|
-
end
|
102
|
+
end
|
96
103
|
|
97
|
-
|
98
|
-
sinatra_run_wait(TestApp, :port => PORT, :server => 'webrick')
|
99
|
-
puts "Test webserver on port #{PORT}"
|
104
|
+
queue.pop # blocks until the start! callback runs
|
100
105
|
end
|
101
106
|
end
|
102
107
|
|
@@ -104,6 +109,15 @@ describe LogStash::Outputs::Http do
|
|
104
109
|
# Wait for the async request to finish in this spinlock
|
105
110
|
# Requires pool_max to be 1
|
106
111
|
|
112
|
+
before(:all) do
|
113
|
+
@server = start_app_and_wait(TestApp)
|
114
|
+
end
|
115
|
+
|
116
|
+
after(:all) do
|
117
|
+
@server.shutdown # WEBrick::HTTPServer
|
118
|
+
TestApp.stop! rescue nil
|
119
|
+
end
|
120
|
+
|
107
121
|
let(:port) { PORT }
|
108
122
|
let(:event) {
|
109
123
|
LogStash::Event.new({"message" => "hi"})
|
@@ -112,6 +126,44 @@ describe LogStash::Outputs::Http do
|
|
112
126
|
let(:method) { "post" }
|
113
127
|
|
114
128
|
shared_examples("verb behavior") do |method|
|
129
|
+
|
130
|
+
shared_examples("failure log behaviour") do
|
131
|
+
it "logs failure" do
|
132
|
+
expect(subject).to have_received(:log_failure).with(any_args)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "does not log headers" do
|
136
|
+
expect(subject).to have_received(:log_failure).with(anything, hash_not_including(:headers))
|
137
|
+
end
|
138
|
+
|
139
|
+
it "does not log the message body" do
|
140
|
+
expect(subject).to have_received(:log_failure).with(anything, hash_not_including(:body))
|
141
|
+
end
|
142
|
+
|
143
|
+
context "with debug log level" do
|
144
|
+
before :all do
|
145
|
+
@current_log_level = LogStash::Logging::Logger.get_logging_context.get_root_logger.get_level.to_s.downcase
|
146
|
+
LogStash::Logging::Logger.configure_logging "debug"
|
147
|
+
end
|
148
|
+
after :all do
|
149
|
+
LogStash::Logging::Logger.configure_logging @current_log_level
|
150
|
+
end
|
151
|
+
|
152
|
+
it "logs a failure" do
|
153
|
+
expect(subject).to have_received(:log_failure).with(any_args)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "logs headers" do
|
157
|
+
expect(subject).to have_received(:log_failure).with(anything, hash_including(:headers))
|
158
|
+
end
|
159
|
+
|
160
|
+
it "logs the body" do
|
161
|
+
expect(subject).to have_received(:log_failure).with(anything, hash_including(:body))
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
115
167
|
let(:verb_behavior_config) { {"url" => url, "http_method" => method, "pool_max" => 1} }
|
116
168
|
subject { LogStash::Outputs::Http.new(verb_behavior_config) }
|
117
169
|
|
@@ -169,7 +221,7 @@ describe LogStash::Outputs::Http do
|
|
169
221
|
|
170
222
|
context "with ignorable failing requests" do
|
171
223
|
let(:url) { "http://localhost:#{port}/bad"}
|
172
|
-
let(:verb_behavior_config) { super.merge("ignorable_codes" => [400]) }
|
224
|
+
let(:verb_behavior_config) { super().merge("ignorable_codes" => [400]) }
|
173
225
|
|
174
226
|
before do
|
175
227
|
subject.multi_receive([event])
|
@@ -197,10 +249,98 @@ describe LogStash::Outputs::Http do
|
|
197
249
|
expect(subject).to have_received(:send_event).exactly(3).times
|
198
250
|
end
|
199
251
|
end
|
252
|
+
end
|
253
|
+
|
254
|
+
context "on retryable unknown exception" do
|
255
|
+
before :each do
|
256
|
+
raised = false
|
257
|
+
original_method = subject.client.method(:send)
|
258
|
+
allow(subject).to receive(:send_event).and_call_original
|
259
|
+
expect(subject.client).to receive(:send) do |*args|
|
260
|
+
unless raised
|
261
|
+
raised = true
|
262
|
+
raise ::Manticore::UnknownException.new("Read timed out")
|
263
|
+
end
|
264
|
+
original_method.call(args)
|
265
|
+
end
|
266
|
+
subject.multi_receive([event])
|
267
|
+
end
|
268
|
+
|
269
|
+
include_examples("failure log behaviour")
|
270
|
+
|
271
|
+
it "retries" do
|
272
|
+
expect(subject).to have_received(:send_event).exactly(2).times
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context "on non-retryable unknown exception" do
|
277
|
+
before :each do
|
278
|
+
raised = false
|
279
|
+
original_method = subject.client.method(:send)
|
280
|
+
allow(subject).to receive(:send_event).and_call_original
|
281
|
+
expect(subject.client).to receive(:send) do |*args|
|
282
|
+
unless raised
|
283
|
+
raised = true
|
284
|
+
raise ::Manticore::UnknownException.new("broken")
|
285
|
+
end
|
286
|
+
original_method.call(args)
|
287
|
+
end
|
288
|
+
subject.multi_receive([event])
|
289
|
+
end
|
290
|
+
|
291
|
+
include_examples("failure log behaviour")
|
292
|
+
|
293
|
+
it "does not retry" do
|
294
|
+
expect(subject).to have_received(:send_event).exactly(1).times
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
context "on non-retryable exception" do
|
299
|
+
before :each do
|
300
|
+
raised = false
|
301
|
+
original_method = subject.client.method(:send)
|
302
|
+
allow(subject).to receive(:send_event).and_call_original
|
303
|
+
expect(subject.client).to receive(:send) do |*args|
|
304
|
+
unless raised
|
305
|
+
raised = true
|
306
|
+
raise RuntimeError.new("broken")
|
307
|
+
end
|
308
|
+
original_method.call(args)
|
309
|
+
end
|
310
|
+
subject.multi_receive([event])
|
311
|
+
end
|
312
|
+
|
313
|
+
include_examples("failure log behaviour")
|
314
|
+
|
315
|
+
it "does not retry" do
|
316
|
+
expect(subject).to have_received(:send_event).exactly(1).times
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
context "on retryable exception" do
|
321
|
+
before :each do
|
322
|
+
raised = false
|
323
|
+
original_method = subject.client.method(:send)
|
324
|
+
allow(subject).to receive(:send_event).and_call_original
|
325
|
+
expect(subject.client).to receive(:send) do |*args|
|
326
|
+
unless raised
|
327
|
+
raised = true
|
328
|
+
raise ::Manticore::Timeout.new("broken")
|
329
|
+
end
|
330
|
+
original_method.call(args)
|
331
|
+
end
|
332
|
+
subject.multi_receive([event])
|
333
|
+
end
|
334
|
+
|
335
|
+
it "retries" do
|
336
|
+
expect(subject).to have_received(:send_event).exactly(2).times
|
337
|
+
end
|
200
338
|
|
339
|
+
include_examples("failure log behaviour")
|
201
340
|
end
|
202
341
|
end
|
203
342
|
|
343
|
+
|
204
344
|
LogStash::Outputs::Http::VALID_METHODS.each do |method|
|
205
345
|
context "when using '#{method}'" do
|
206
346
|
include_examples("verb behavior", method)
|
@@ -362,3 +502,75 @@ describe LogStash::Outputs::Http do
|
|
362
502
|
end
|
363
503
|
end
|
364
504
|
end
|
505
|
+
|
506
|
+
describe LogStash::Outputs::Http do # different block as we're starting web server with TLS
|
507
|
+
|
508
|
+
@@default_server_settings = TestApp.server_settings.dup
|
509
|
+
|
510
|
+
before do
|
511
|
+
cert, key = WEBrick::Utils.create_self_signed_cert 2048, [["CN", ssl_cert_host]], "Logstash testing"
|
512
|
+
TestApp.server_settings = @@default_server_settings.merge({
|
513
|
+
:SSLEnable => true,
|
514
|
+
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
|
515
|
+
:SSLCertificate => cert,
|
516
|
+
:SSLPrivateKey => key
|
517
|
+
})
|
518
|
+
|
519
|
+
TestApp.last_request = nil
|
520
|
+
|
521
|
+
@server = start_app_and_wait(TestApp)
|
522
|
+
end
|
523
|
+
|
524
|
+
after do
|
525
|
+
@server.shutdown # WEBrick::HTTPServer
|
526
|
+
|
527
|
+
TestApp.stop! rescue nil
|
528
|
+
TestApp.server_settings = @@default_server_settings
|
529
|
+
end
|
530
|
+
|
531
|
+
let(:ssl_cert_host) { 'localhost' }
|
532
|
+
|
533
|
+
let(:port) { PORT }
|
534
|
+
let(:url) { "https://localhost:#{port}/good" }
|
535
|
+
let(:method) { "post" }
|
536
|
+
|
537
|
+
let(:config) { { "url" => url, "http_method" => method } }
|
538
|
+
|
539
|
+
subject { LogStash::Outputs::Http.new(config) }
|
540
|
+
|
541
|
+
before { subject.register }
|
542
|
+
after { subject.close }
|
543
|
+
|
544
|
+
let(:last_request) { TestApp.last_request }
|
545
|
+
let(:last_request_body) { last_request.body.read }
|
546
|
+
|
547
|
+
let(:event) { LogStash::Event.new("message" => "hello!") }
|
548
|
+
|
549
|
+
context 'with default (full) verification' do
|
550
|
+
|
551
|
+
let(:config) { super() } # 'ssl_verification_mode' => 'full'
|
552
|
+
|
553
|
+
it "does NOT process the request (due client protocol exception)" do
|
554
|
+
# Manticore's default verification does not accept self-signed certificates!
|
555
|
+
Thread.start do
|
556
|
+
subject.multi_receive [ event ]
|
557
|
+
end
|
558
|
+
sleep 1.5
|
559
|
+
|
560
|
+
expect(last_request).to be nil
|
561
|
+
end
|
562
|
+
|
563
|
+
end
|
564
|
+
|
565
|
+
context 'with verification disabled' do
|
566
|
+
|
567
|
+
let(:config) { super().merge 'ssl_verification_mode' => 'none' }
|
568
|
+
|
569
|
+
it "should process the request" do
|
570
|
+
subject.multi_receive [ event ]
|
571
|
+
expect(last_request_body).to include '"message":"hello!"'
|
572
|
+
end
|
573
|
+
|
574
|
+
end
|
575
|
+
|
576
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-output-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -35,10 +35,10 @@ dependencies:
|
|
35
35
|
requirements:
|
36
36
|
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
38
|
+
version: 7.1.0
|
39
39
|
- - "<"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 8.0.0
|
42
42
|
name: logstash-mixin-http_client
|
43
43
|
prerelease: false
|
44
44
|
type: :runtime
|
@@ -46,10 +46,10 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 7.1.0
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
52
|
+
version: 8.0.0
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
requirement: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
@@ -132,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
|
-
|
136
|
-
rubygems_version: 2.6.13
|
135
|
+
rubygems_version: 3.1.6
|
137
136
|
signing_key:
|
138
137
|
specification_version: 4
|
139
138
|
summary: Sends events to a generic HTTP or HTTPS endpoint
|