fluent-plugin-dynamic-logzio 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8baa565dfe450a9a0ee127d5e8e4b355bd7b578ef67677eebd3e3255e36b61d5
4
+ data.tar.gz: 853ef36b6fbb5727bd822097d24d719be0e3463f89f5b5933c2d2829018c009a
5
+ SHA512:
6
+ metadata.gz: d06f4ee4122b849e20a28b7b744c6b2cb3104e51fc201f3238a699a811d4fefd111e9e48e0e0f837abe21d9d3eb3c8bc5d916fa8121647743102546e114776e3
7
+ data.tar.gz: 1a4475b570cddfd2608cc8b3c5b69ab8ff25f75505e244a7bd3f80a442eabecedc3bbf85d0e935199d12094c63b484b37ee0a48726bfbea113f95043b2eb1d39
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ *.swp
4
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-logzio.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
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 [yyyy] [name of copyright owner]
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 ADDED
@@ -0,0 +1,80 @@
1
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-logzio.svg)](https://badge.fury.io/rb/fluent-plugin-logzio)
2
+
3
+ Logz.io plugin for [Fluentd](http://www.fluentd.org)
4
+ =============
5
+ With fluent-plugin-logzio you will be able to use [Logz.io](http://logz.io) as output the logs you collect with Fluentd.
6
+
7
+ ## Requirements
8
+
9
+ | fluent-plugin-logzio | Fluentd | Ruby |
10
+ |---------------------------|-------------|--------|
11
+ | >= 0.0.15 | >= v0.14.0 | >= 2.1 |
12
+ | < 0.0.15 | >= v0.12.0 | >= 1.9 |
13
+
14
+ ## Getting Started
15
+ * Install [Fluentd](http://www.fluentd.org/download)
16
+ * gem install fluent-plugin-logzio
17
+ * Make sure you have an account with Logz.io.
18
+ * Configure Fluentd as below:
19
+
20
+ ### FluentD 1.0-style Example Configuration
21
+
22
+ This is an **example** only. Your needs in production may vary!
23
+
24
+ ```
25
+ <match **>
26
+ @type logzio_buffered
27
+
28
+ endpoint_url https://listener.logz.io:8071?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&type=my_type
29
+
30
+ output_include_time true
31
+ output_include_tags true
32
+ http_idle_timeout 10
33
+
34
+ <buffer>
35
+ @type memory
36
+ flush_thread_count 4
37
+ flush_interval 3s
38
+ chunk_limit_size 16m # Logz.io bulk limit is decoupled from chunk_limit_size. Set whatever you want.
39
+ queue_limit_length 4096
40
+ </buffer>
41
+ </match>
42
+ ```
43
+
44
+ ### FluentD 0.12-style Example Configuration
45
+
46
+ This is an **example** only. Your needs in production may vary!
47
+
48
+ ```
49
+ <match your_match>
50
+ @type logzio_buffered
51
+ endpoint_url https://listener.logz.io:8071?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&type=my_type
52
+ output_include_time true
53
+ output_include_tags true
54
+ output_tags_fieldname @log_name
55
+ buffer_type file
56
+ buffer_path /path/to/buffer/file
57
+ flush_interval 10s
58
+ buffer_chunk_limit 64m # Logz.io bulk limit is decoupled from buffer_chunk_limit. Set whatever you want.
59
+ </match>
60
+ ```
61
+
62
+ ## Parameters
63
+ * **endpoint_url** the url to Logz.io input where `xxx-xxxx...` is your Logz.io access token, and `my_type` is the type of your logs in Logz.io.
64
+ * **output_include_time** should the appender add a timestamp to your logs on their process time. (recommended).
65
+ * **output_include_tags** should the appender add the fluentd tag to the document, called "fluentd_tag" (which can be renamed, see next point).
66
+ * **output_tags_fieldname** set the tag's fieldname, defaults to "fluentd_tag".
67
+ * **http_idle_timeout** timeout in seconds that the http persistent connection will stay open without traffic.
68
+ * **retry_count** How many times to resend failed bulks. Defaults to 4 times.
69
+ * **retry_sleep** How long to sleep initially between retries, exponential step-off. Initial default is 2s.
70
+ * **bulk_limit** Limit to the size of the Logz.io upload bulk. Defaults to 1000000 bytes leaving about 24kB for overhead.
71
+ * **bulk_limit_warning_limit** Limit to the size of the Logz.io warning message when a record exceeds bulk_limit to prevent a recursion when Fluent warnings are sent to the Logz.io output. Defaults to nil (no truncation).
72
+
73
+ ## Release Notes
74
+ - 0.0.18: Support proxy_uri and proxy_cert in the configuration file. Put logzio output plugin class under Fluent::Plugin module and thus work with multi workers.
75
+ - 0.0.17: Optional truncate log messages when they are exceeding bulk size in warning logs
76
+ - 0.0.16: More fluentD 1.0+ adjustments
77
+ - 0.0.15: Support FluentD 1.0+. Split the chunk into bulk uploads, decoupling `chunk_limit_size`/`buffer_chunk_limit` from Logz.io bulk limit. Tunable `bulk_limit` and initial `retry_sleep`.
78
+ - 0.0.14: Refactor send function to handle more cases, and retry in case of logzio connection failure.
79
+ - 0.0.13: BREAKING - Removed non-buffered version. It's really not efficient, and should just not be used. If you are using this version, you should change to the buffered one.
80
+ - 0.0.12: Catch exception when parsing YAML to ignore (instead of crash) not valid logs.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'fluent-plugin-dynamic-logzio'
7
+ s.version = '0.0.1'
8
+ s.authors = ['Yury Kotov', 'Roi Rav-Hon', 'Arcadiy Ivanov', 'Stewart Powell']
9
+ s.email = ['bairkan@gmail.com', 'roi@logz.io', 'arcadiy@ivanov.biz', 'stewart.powell@gmail.com']
10
+ s.homepage = 'https://github.com/jwplayer'
11
+ s.summary = %q{Fluentd plugin for output to Logz.io with the ability to dynamically generate certain values}
12
+ s.description = %q{Fluentd pluging (fluent.org) for output to Logz.io (logz.io)}
13
+ s.license = 'Apache-2.0'
14
+
15
+ s.rubyforge_project = 'fluent-plugin-logzio'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.require_paths = ['lib']
20
+ s.required_ruby_version = Gem::Requirement.new('>= 2.1.0')
21
+
22
+ s.add_dependency 'net-http-persistent', '~> 2.9'
23
+ s.add_runtime_dependency 'fluentd', ['>= 0.14.0', '< 2']
24
+ s.add_development_dependency 'rake', '~> 12.3'
25
+ s.add_development_dependency 'bundler', '~> 1.16'
26
+ s.add_development_dependency 'rspec', '~> 3.7'
27
+ s.add_development_dependency 'test-unit', '~> 3.2'
28
+ end
@@ -0,0 +1,178 @@
1
+ require 'time'
2
+ require 'fluent/plugin/output'
3
+
4
+ module Fluent::Plugin
5
+ class LogzioOutputBuffered < Output
6
+ Fluent::Plugin.register_output('logzio_buffered', self)
7
+
8
+ helpers :compat_parameters
9
+
10
+ config_param :logzio_url, :string, default: 'https://listener.logz.io:8071?'
11
+ config_param :token, :string, default: nil
12
+ config_param :log_type, :string, default: '&type=my_type'
13
+
14
+ config_param :output_include_time, :bool, default: true
15
+ config_param :output_include_tags, :bool, default: true
16
+ config_param :retry_count, :integer, default: 4 # How many times to resend failed bulks. Undocumented because not suppose to be changed
17
+ config_param :retry_sleep, :integer, default: 2 # How long to sleep initially between retries, exponential step-off
18
+ config_param :bulk_limit, :integer, default: 1000000 # Make sure submission to LogzIO does not exceed 1MB limit and leave some overhead
19
+ config_param :bulk_limit_warning_limit, :integer, default: nil # If fluent warnings are sent to the Logzio output, truncating is necessary to prevent a recursion
20
+ config_param :http_idle_timeout, :integer, default: 5
21
+ config_param :output_tags_fieldname, :string, default: 'fluentd_tags'
22
+ config_param :proxy_uri, :string, default: nil
23
+ config_param :proxy_cert, :string, default: nil
24
+
25
+
26
+ def configure(conf)
27
+ super
28
+ compat_parameters_convert(conf, :buffer)
29
+
30
+ if conf['proxy_uri']
31
+ log.debug "Proxy #{@proxy_uri}"
32
+ ENV['http_proxy'] = @proxy_uri
33
+ end
34
+
35
+ if conf['proxy_cert']
36
+ log.debug "Proxy #{@proxy_cert}"
37
+ ENV['SSL_CERT_FILE'] = @proxy_cert
38
+ end
39
+
40
+ end
41
+
42
+ def start
43
+ super
44
+ require 'net/http/persistent'
45
+
46
+
47
+ if @log_type
48
+ log_type = record[@log_type] || @log_type
49
+ end
50
+
51
+ @logzio_endpoint = "#{@logzio_url}token=#{@token}&type=#{@log_type}"
52
+
53
+
54
+ @uri = URI @logzio_endpoint
55
+ @http = Net::HTTP::Persistent.new 'fluent-plugin-logzio', :ENV
56
+ @http.headers['Content-Type'] = 'text/plain'
57
+ @http.idle_timeout = @http_idle_timeout
58
+ @http.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
59
+
60
+ log.debug "Started Logz.io shipper.."
61
+ end
62
+
63
+ def shutdown
64
+ super
65
+ end
66
+
67
+ def formatted_to_msgpack_binary?
68
+ true
69
+ end
70
+
71
+ def multi_workers_ready?
72
+ true
73
+ end
74
+
75
+ def format(tag, time, record)
76
+ if time.is_a?(Fluent::EventTime)
77
+ sec_frac = time.to_f
78
+ else
79
+ sec_frac = time * 1.0
80
+ end
81
+ [tag, sec_frac, record].to_msgpack
82
+ end
83
+
84
+ def write(chunk)
85
+ encode_chunk(chunk) { |bulk_records, bulk_size|
86
+ send_bulk(bulk_records, bulk_size)
87
+ }
88
+ end
89
+
90
+ def encode_chunk(chunk)
91
+ records = []
92
+ bulk_size = 0
93
+ chunk.each { |tag, time, record|
94
+ record['@timestamp'] ||= Time.at(time).iso8601(3) if @output_include_time
95
+ record[@output_tags_fieldname] ||= tag.to_s if @output_include_tags
96
+
97
+ begin
98
+ json_record = Yajl.dump(record)
99
+ record_size = json_record.size + (1 if !records.empty?).to_i # Accounting for trailing "\n"
100
+ rescue
101
+ log.error "Adding record #{record} to buffer failed. Exception: #{$!}"
102
+ next
103
+ end
104
+
105
+ if record_size > @bulk_limit
106
+ if @bulk_limit_warning_limit.is_a?(Integer)
107
+ log.warn "Record with size #{record_size} exceeds #{@bulk_limit} and can't be sent to Logz.io. Record starts with (truncated at #{@bulk_limit_warning_limit} characters): #{json_record[0,@bulk_limit_warning_limit]}"
108
+ # Send the full message to debug facility
109
+ log.debug "Record with size #{record_size} exceeds #{@bulk_limit} and can't be sent to Logz.io. Record is: #{json_record}"
110
+ else
111
+ log.warn "Record with size #{record_size} exceeds #{@bulk_limit} and can't be sent to Logz.io. Record is: #{json_record}"
112
+ end
113
+ next
114
+ end
115
+ if bulk_size + record_size > @bulk_limit
116
+ yield(records, bulk_size)
117
+ records = []
118
+ bulk_size = 0
119
+ end
120
+ records.push(json_record)
121
+ bulk_size += record_size
122
+ }
123
+ if records
124
+ yield(records, bulk_size)
125
+ end
126
+ end
127
+
128
+ def send_bulk(bulk_records, bulk_size)
129
+ log.debug "Sending a bulk of #{bulk_records.size} records, size #{bulk_size}B to Logz.io"
130
+
131
+ # Setting our request
132
+ post = Net::HTTP::Post.new @uri.request_uri
133
+
134
+ # Logz.io bulk http endpoint expecting log line with \n delimiter
135
+ post.body = bulk_records.join("\n")
136
+
137
+ sleep_interval = @retry_sleep
138
+
139
+ begin
140
+ @retry_count.times do |counter|
141
+ should_retry = true
142
+ begin
143
+ response = @http.request @uri, post
144
+ if response.code != '200'
145
+ if response.code == '401'
146
+ log.error "You are not authorized with Logz.io! Token OK? dropping logs..."
147
+ should_retry = false
148
+ elsif response.code == '400'
149
+ log.info "Got 400 code from Logz.io. This means that some of your logs are too big, or badly formatted. Response: #{response.body}"
150
+ should_retry = false
151
+ else
152
+ log.debug "Got HTTP #{response.code} from Logz.io, not giving up just yet (Try #{counter + 1}/#{@retry_count})"
153
+ end
154
+ else
155
+ log.debug "Successfully sent bulk of #{bulk_records.size} records, size #{bulk_size}B to Logz.io"
156
+ should_retry = false
157
+ end
158
+ rescue StandardError => e
159
+ log.debug "Error connecting to Logz.io. Got exception: #{e} (Try #{counter + 1}/#{@retry_count})"
160
+ end
161
+
162
+ if should_retry
163
+ if counter == @retry_count - 1
164
+ log.error "Could not send your bulk after #{retry_count} tries Sorry! Your bulk is: #{post.body}"
165
+ break
166
+ end
167
+ sleep(sleep_interval)
168
+ sleep_interval *= 2
169
+ else
170
+ return
171
+ end
172
+ end
173
+ rescue Exception => e
174
+ log.error "Got unexpected exception! Here: #{e}"
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fluent::Plugin::LogzioOutputBuffered' do
4
+ let(:driver) { Fluent::Test::Driver::Output.new(Fluent::Plugin::LogzioOutputBuffered).configure(config) }
5
+ let(:config) do
6
+ %[
7
+ endpoint_url https://logz.io?token=123
8
+ output_include_time false
9
+ ]
10
+ end
11
+
12
+ include_context 'output context'
13
+ include_examples 'output examples'
14
+
15
+ describe 'feed' do
16
+ before(:each) do
17
+ expect(request).to receive(:body=).with('{"field1":50,"otherfield":99,"fluentd_tags":"test"}' + "\n" + '{"field1":150,"otherfield":199,"fluentd_tags":"test"}')
18
+ expect(Net::HTTP::Post).to receive(:new).with('/?token=123').once.and_return(request)
19
+ expect_any_instance_of(Net::HTTP::Persistent).to receive(:request).once.and_return(response)
20
+ end
21
+
22
+ it 'adds messages to the buffer' do
23
+ driver.run(default_tag: 'test') do
24
+ driver.feed(time, record1)
25
+ driver.feed(time, record2)
26
+ end
27
+
28
+ expect(driver.formatted).to eq([['test', 0.0, {'field1' => 50, 'otherfield' => 99}].to_msgpack,
29
+ ['test', 0.0, {'field1' => 150, 'otherfield' => 199}].to_msgpack])
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fluent::Plugin::LogzioOutputBuffered' do
4
+ let(:driver) { Fluent::Test::Driver::Output.new(Fluent::Plugin::LogzioOutputBuffered).configure(config) }
5
+ let(:config) do
6
+ %[
7
+ endpoint_url https://logz.io?token=123
8
+ output_include_time false
9
+ bulk_limit 70
10
+ ]
11
+ end
12
+
13
+ include_context 'output context'
14
+ include_examples 'output examples'
15
+
16
+ describe 'feed' do
17
+ before(:each) do
18
+ expect(request).to receive(:body=).with('{"field1":50,"otherfield":99,"fluentd_tags":"test"}')
19
+ expect(Net::HTTP::Post).to receive(:new).with('/?token=123').once.and_return(request)
20
+ expect_any_instance_of(Net::HTTP::Persistent).to receive(:request).and_return(response)
21
+ expect(request).to receive(:body=).with('{"field1":150,"otherfield":199,"fluentd_tags":"test"}')
22
+ expect(Net::HTTP::Post).to receive(:new).with('/?token=123').once.and_return(request)
23
+ expect_any_instance_of(Net::HTTP::Persistent).to receive(:request).and_return(response)
24
+ end
25
+
26
+ it 'adds messages to the buffer' do
27
+ driver.run(default_tag: 'test') do
28
+ driver.feed(time, record1)
29
+ driver.feed(time, record2)
30
+ end
31
+
32
+ expect(driver.formatted).to eq([['test', 0.0, {'field1' => 50, 'otherfield' => 99}].to_msgpack,
33
+ ['test', 0.0, {'field1' => 150, 'otherfield' => 199}].to_msgpack])
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fluent::Plugin::LogzioOutputBuffered' do
4
+ let(:driver) { Fluent::Test::Driver::Output.new(Fluent::Plugin::LogzioOutputBuffered).configure(config) }
5
+ let(:config) do
6
+ %[
7
+ endpoint_url https://logz.io?token=123
8
+ output_include_time false
9
+ bulk_limit 52
10
+ ]
11
+ end
12
+
13
+ include_context 'output context'
14
+ include_examples 'output examples'
15
+
16
+ describe 'feed' do
17
+ before(:each) do
18
+ expect(request).to receive(:body=).with('{"field1":50,"otherfield":99,"fluentd_tags":"test"}').once
19
+ expect(Net::HTTP::Post).to receive(:new).with('/?token=123').once.and_return(request)
20
+ expect_any_instance_of(Net::HTTP::Persistent).to receive(:request).once.and_return(response)
21
+ end
22
+
23
+ it 'adds messages to the buffer' do
24
+ driver.run(default_tag: 'test') do
25
+ driver.feed(time, record1)
26
+ driver.feed(time, record2)
27
+ end
28
+
29
+ expect(driver.formatted).to eq([['test', 0.0, {'field1' => 50, 'otherfield' => 99}].to_msgpack,
30
+ ['test', 0.0, {'field1' => 150, 'otherfield' => 199}].to_msgpack])
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,128 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Allows RSpec to persist some state between runs in order to support
54
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
55
+ # you configure your source control system to ignore this file.
56
+ config.example_status_persistence_file_path = "spec/examples.txt"
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended. For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63
+ config.disable_monkey_patching!
64
+
65
+ # This setting enables warnings. It's recommended, but in some cases may
66
+ # be too noisy due to issues in dependencies.
67
+ config.warnings = true
68
+
69
+ # Many RSpec users commonly either run the entire suite or an individual
70
+ # file, and it's useful to allow more verbose output when running an
71
+ # individual spec file.
72
+ if config.files_to_run.one?
73
+ # Use the documentation formatter for detailed output,
74
+ # unless a formatter has already been configured
75
+ # (e.g. via a command-line flag).
76
+ config.default_formatter = 'doc'
77
+ end
78
+
79
+ # Print the 10 slowest examples and example groups at the
80
+ # end of the spec run, to help surface which specs are running
81
+ # particularly slow.
82
+ config.profile_examples = 10
83
+
84
+ # Run specs in random order to surface order dependencies. If you find an
85
+ # order dependency and want to debug it, you can fix the order by providing
86
+ # the seed, which is printed after each run.
87
+ # --seed 1234
88
+ config.order = :random
89
+
90
+ # Seed global randomization in this process using the `--seed` CLI option.
91
+ # Setting this allows you to use `--seed` to deterministically reproduce
92
+ # test failures related to randomization by passing the same `--seed` value
93
+ # as the one that triggered the failure.
94
+ Kernel.srand config.seed
95
+ =end
96
+ require 'net/http/persistent'
97
+ require 'serverengine'
98
+
99
+ require 'fluent/test'
100
+ require 'fluent/test/driver/output'
101
+
102
+ require 'fluent/plugin/out_logzio_buffered'
103
+ end
104
+
105
+ RSpec.shared_examples 'output examples' do |request_block|
106
+ describe 'endpoint url' do
107
+ subject { instance.endpoint_url }
108
+
109
+ it { should eq 'https://logz.io?token=123' }
110
+ end
111
+ end
112
+
113
+ RSpec.shared_context 'output context' do
114
+ before(:all) { Fluent::Test.setup }
115
+ let(:instance) { driver.instance }
116
+
117
+ let(:time) { 0 }
118
+ let(:record1) { {'field1' => 50, 'otherfield' => 99} }
119
+ let(:record2) { {'field1' => 150, 'otherfield' => 199} }
120
+ let(:request) { double }
121
+ let(:response) do
122
+ response = double
123
+
124
+ allow(response).to receive(:code).and_return('200')
125
+
126
+ response
127
+ end
128
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-dynamic-logzio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yury Kotov
8
+ - Roi Rav-Hon
9
+ - Arcadiy Ivanov
10
+ - Stewart Powell
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2018-10-10 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: net-http-persistent
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.9'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.9'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fluentd
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.14.0
37
+ - - "<"
38
+ - !ruby/object:Gem::Version
39
+ version: '2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.14.0
47
+ - - "<"
48
+ - !ruby/object:Gem::Version
49
+ version: '2'
50
+ - !ruby/object:Gem::Dependency
51
+ name: rake
52
+ requirement: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '12.3'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '12.3'
64
+ - !ruby/object:Gem::Dependency
65
+ name: bundler
66
+ requirement: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '1.16'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.16'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '3.7'
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '3.7'
92
+ - !ruby/object:Gem::Dependency
93
+ name: test-unit
94
+ requirement: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '3.2'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '3.2'
106
+ description: Fluentd pluging (fluent.org) for output to Logz.io (logz.io)
107
+ email:
108
+ - bairkan@gmail.com
109
+ - roi@logz.io
110
+ - arcadiy@ivanov.biz
111
+ - stewart.powell@gmail.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files: []
115
+ files:
116
+ - ".gitignore"
117
+ - ".rspec"
118
+ - Gemfile
119
+ - LICENSE
120
+ - README.md
121
+ - Rakefile
122
+ - fluent-plugin-logzio.gemspec
123
+ - lib/fluent/plugin/out_logzio_buffered.rb
124
+ - spec/lib/fluent/plugin/out_logzio_buffered_spec.rb
125
+ - spec/lib/fluent/plugin/out_logzio_multi_bulk_spec.rb
126
+ - spec/lib/fluent/plugin/out_logzio_record_too_large_spec.rb
127
+ - spec/spec_helper.rb
128
+ homepage: https://github.com/jwplayer
129
+ licenses:
130
+ - Apache-2.0
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 2.1.0
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project: fluent-plugin-logzio
148
+ rubygems_version: 2.7.6
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Fluentd plugin for output to Logz.io with the ability to dynamically generate
152
+ certain values
153
+ test_files:
154
+ - spec/lib/fluent/plugin/out_logzio_buffered_spec.rb
155
+ - spec/lib/fluent/plugin/out_logzio_multi_bulk_spec.rb
156
+ - spec/lib/fluent/plugin/out_logzio_record_too_large_spec.rb
157
+ - spec/spec_helper.rb