fluent-plugin-logzio 0.0.22 → 0.2.0.pre.test1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f6e13567cce456b4bf9efe5ec2fcc72d9ab50648
4
- data.tar.gz: 9c92ef500e341c040349be13f9ac4d2ea8a3ea96
2
+ SHA256:
3
+ metadata.gz: 8ff307f46dc9f34f4f4cdd60374c340c81ab328c6e1485d8cf77d7c833709b9e
4
+ data.tar.gz: 286c954bb9c4a1e1ead99edf25e96a77556254b58afdb74dcccba4773e1a0a10
5
5
  SHA512:
6
- metadata.gz: '09062c96178f0d3b42b2e5c9ace511b029ae3508e3beca477916b80b806e83f6ccb15bf94ce52eabebc2cce3e5a10d4b1009cf0c26e13752259578dac0e35479'
7
- data.tar.gz: b84d592569e502023fb318fbe2f1408a9049156740233ab67aeca0b0c0333a5c8ca39cf79eb641494fde4c9326fa28b65ae472feecea8724418243906dceed32
6
+ metadata.gz: 85ff70985c0fda5b6220c8cf6e0fa1306525940828c03c75d097bebe9cda65e6e6097f020454c06e4b17137d02a7b77c1bf492c5e0261f2dad45336357e554ab
7
+ data.tar.gz: dafe99b38c2d4f9e33efa7c71334d21c6493318b9d407a90cb13a5d9b0877df36af0bc047f166697ec0b816be3b79018298a6a4742a78191c5836dfd275b0515
@@ -0,0 +1,8 @@
1
+ repos:
2
+ - repo: https://github.com/cycodehq-public/cycode-cli
3
+ rev: 0.1.6
4
+ hooks:
5
+ - id: cycode
6
+ language_version: python3
7
+ stages:
8
+ - commit
data/README.md CHANGED
@@ -69,12 +69,24 @@ This is an **example** only. Your needs in production may vary!
69
69
  * **retry_sleep** How long to sleep initially between retries, exponential step-off. Initial default is 2s.
70
70
  * **bulk_limit** Limit to the size of the Logz.io upload bulk. Defaults to 1000000 bytes leaving about 24kB for overhead.
71
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
- * **proxy_uri** Your proxy uri. Default is nil
73
- * **proxy_cert** Your proxy cert. Default is nil
74
- * **gzip** should the plugin ship the logs in gzip compression. Default is false
72
+ * **proxy_uri** Your proxy uri. Default is nil. For example: "`my.ip:12345`".
73
+ * **proxy_cert** Your proxy cert. Default is nil.
74
+ * **gzip** should the plugin ship the logs in gzip compression. Default is false.
75
+
76
+
77
+ ## Plugin metrics:
78
+
79
+ | Metric Name | Description | Type | Example |
80
+ | --- | --- | --- | --- |
81
+ | `logzio_status_codes` | Status codes received from Logz.io | Gauge | `logzio_status_codes{type="logzio_buffered",plugin_id="out_logzio",status_code="500"}` |
75
82
 
76
83
 
77
84
  ## Release Notes
85
+ - **0.2.0**:
86
+ - Do not retry on 400 and 401. For 400 - try to fix log and resend.
87
+ - Generate a metric (`logzio_status_codes`) for response codes from Logz.io.
88
+ - **0.1.0**:
89
+ - Use fluentd's retry instead of retry in code (raise exception on non-2xx response).
78
90
  - 0.0.22: Update gem `net-http-persistent` to 4.x.
79
91
  - 0.0.21: Update gem `net-http-persistent` to 3.x.
80
92
  - 0.0.20: Support gzip compression
@@ -4,8 +4,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'fluent-plugin-logzio'
7
- s.version = '0.0.22'
8
- s.authors = ['Yury Kotov', 'Roi Rav-Hon', 'Arcadiy Ivanov', 'Miri Ignatiev']
7
+ s.version = '0.2.0-test1'
8
+ s.authors = ['Yury Kotov', 'Roi Rav-Hon', 'Arcadiy Ivanov', 'Miri Bar']
9
9
  s.email = ['bairkan@gmail.com', 'roi@logz.io', 'arcadiy@ivanov.biz', 'miri.ignatiev@logz.io']
10
10
  s.homepage = 'https://github.com/logzio/fluent-plugin-logzio'
11
11
  s.summary = %q{Fluentd plugin for output to Logz.io}
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency 'net-http-persistent', '~> 4.0'
23
23
  s.add_runtime_dependency 'fluentd', ['>= 0.14.0', '< 2']
24
+ s.add_runtime_dependency 'prometheus-client', '>= 2.1.0'
24
25
  s.add_development_dependency 'rake', '~> 12.3'
25
26
  s.add_development_dependency 'bundler', '~> 1.16'
26
27
  s.add_development_dependency 'rspec', '~> 3.7'
@@ -6,6 +6,7 @@ require 'stringio'
6
6
  module Fluent::Plugin
7
7
  class LogzioOutputBuffered < Output
8
8
  Fluent::Plugin.register_output('logzio_buffered', self)
9
+ class RetryableResponse < StandardError; end
9
10
 
10
11
  helpers :compat_parameters
11
12
 
@@ -37,7 +38,21 @@ module Fluent::Plugin
37
38
  log.debug "Proxy #{@proxy_cert}"
38
39
  ENV['SSL_CERT_FILE'] = @proxy_cert
39
40
  end
41
+ @metric_labels = {
42
+ type: 'logzio_buffered',
43
+ plugin_id: 'out_logzio',
44
+ }
45
+ @metrics = {
46
+ status_codes: get_gauge(
47
+ :logzio_status_codes,
48
+ 'Status codes received from Logz.io', {"status_code":""}),
49
+ }
50
+
51
+ end
40
52
 
53
+ def initialize
54
+ super
55
+ @registry = ::Prometheus::Client.registry
41
56
  end
42
57
 
43
58
  def start
@@ -121,6 +136,27 @@ module Fluent::Plugin
121
136
  end
122
137
 
123
138
  def send_bulk(bulk_records, bulk_size)
139
+ response = do_post(bulk_records, bulk_size)
140
+
141
+ @metrics[:status_codes].increment(labels: merge_labels({'status_code': response.code.to_s}))
142
+ log.info "Status code from logzio: #{response.code}"
143
+
144
+ if not response.code.start_with?('2')
145
+ log.info "here here here"
146
+ if response.code == '400'
147
+ log.warn "Received #{response.code} from Logzio. Some logs may be malformed or too long. Valid logs were succesfully sent into the system. Will try to proccess and send oversized logs. Response body: #{response.body}"
148
+ process_code_400(bulk_records, Yajl.load(response.body))
149
+ elsif response.code == '401'
150
+ log.error "Received #{response.code} from Logzio. Unauthorized, please check your logs shipping token. Will not retry sending. Response body: #{response.body}"
151
+ else
152
+ log.debug "Failed request body: #{post.body}"
153
+ log.error "Error while sending POST to #{@uri}: #{response.body}"
154
+ raise RetryableResponse, "Logzio listener returned (#{response.code}) for #{@uri}: #{response.body}", []
155
+ end
156
+ end
157
+ end
158
+
159
+ def do_post(bulk_records, bulk_size)
124
160
  log.debug "Sending a bulk of #{bulk_records.size} records, size #{bulk_size}B to Logz.io"
125
161
 
126
162
  # Setting our request
@@ -131,44 +167,43 @@ module Fluent::Plugin
131
167
  if gzip
132
168
  post.body = compress(post.body)
133
169
  end
134
- sleep_interval = @retry_sleep
135
170
 
136
171
  begin
137
- @retry_count.times do |counter|
138
- should_retry = true
139
- begin
140
- response = @http.request @uri, post
141
- if response.code != '200'
142
- if response.code == '401'
143
- log.error "You are not authorized with Logz.io! Token OK? dropping logs..."
144
- should_retry = false
145
- elsif response.code == '400'
146
- log.info "Got 400 code from Logz.io. This means that some of your logs are too big, or badly formatted. Response: #{response.body}"
147
- should_retry = false
148
- else
149
- log.warn "Got HTTP #{response.code} from Logz.io, not giving up just yet (Try #{counter + 1}/#{@retry_count})"
150
- end
151
- else
152
- log.debug "Successfully sent bulk of #{bulk_records.size} records, size #{bulk_size}B to Logz.io"
153
- should_retry = false
154
- end
155
- rescue StandardError => e
156
- log.warn "Error connecting to Logz.io. Got exception: #{e} (Try #{counter + 1}/#{@retry_count})"
157
- end
172
+ response = @http.request @uri, post
173
+ rescue Net::HTTP::Persistent::Error => e
174
+ raise e.cause
175
+ return response
176
+ end
177
+ end
158
178
 
159
- if should_retry
160
- if counter == @retry_count - 1
161
- log.error "Could not send your bulk after #{retry_count} tries Sorry! Your bulk is: #{post.body}"
162
- break
163
- end
164
- sleep(sleep_interval)
165
- sleep_interval *= 2
166
- else
167
- return
168
- end
179
+ def process_code_400(bulk_records, response_body)
180
+ max_log_field_size_bytes = 32000
181
+ oversized_logs_counter = response_body['oversizedLines'].to_i
182
+ new_bulk = []
183
+ for log_record in bulk_records
184
+ log.info "Oversized lines: #{oversized_logs_counter}" # todo
185
+ if oversized_logs_counter == 0
186
+ log.debug "No malformed lines, breaking"
187
+ break
188
+ end
189
+ new_log = Yajl.load(log_record)
190
+ msg_size = new_log['message'].size
191
+ # Handle oversized log:
192
+ if msg_size >= max_log_field_size_bytes
193
+ new_log['message'] = new_log['message'][0, max_log_field_size_bytes - 1]
194
+ log.debug "new log: #{new_log}"
195
+ new_bulk.append(Yajl.dump(new_log))
196
+ oversized_logs_counter -= 1
197
+ end
198
+ end
199
+ if new_bulk.size > 0
200
+ log.debug "Number of fixed bad logs to send: #{new_bulk.size}"
201
+ response = do_post(new_bulk, new_bulk.size)
202
+ if response.code.start_with?('2')
203
+ log.info "Succesfully sent bad logs"
204
+ else
205
+ log.warn "While trying to send fixed bad logs, got #{response.code} from Logz.io, will not try to re-send"
169
206
  end
170
- rescue Exception => e
171
- log.error "Got unexpected exception! Here: #{e}"
172
207
  end
173
208
  end
174
209
 
@@ -179,5 +214,17 @@ module Fluent::Plugin
179
214
  w_gz.close
180
215
  wio.string
181
216
  end
217
+
218
+ def merge_labels(extra_labels= {})
219
+ @metric_labels.merge extra_labels
220
+ end
221
+
222
+ def get_gauge(name, docstring, extra_labels = {})
223
+ if @registry.exist?(name)
224
+ @registry.get(name)
225
+ else
226
+ @registry.gauge(name, docstring: docstring, labels: @metric_labels.keys + extra_labels.keys)
227
+ end
228
+ end
182
229
  end
183
230
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-logzio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.2.0.pre.test1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Kotov
8
8
  - Roi Rav-Hon
9
9
  - Arcadiy Ivanov
10
- - Miri Ignatiev
10
+ - Miri Bar
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2022-06-19 00:00:00.000000000 Z
14
+ date: 2023-07-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: net-http-persistent
@@ -47,6 +47,20 @@ dependencies:
47
47
  - - "<"
48
48
  - !ruby/object:Gem::Version
49
49
  version: '2'
50
+ - !ruby/object:Gem::Dependency
51
+ name: prometheus-client
52
+ requirement: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.1.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.1.0
50
64
  - !ruby/object:Gem::Dependency
51
65
  name: rake
52
66
  requirement: !ruby/object:Gem::Requirement
@@ -113,8 +127,8 @@ executables: []
113
127
  extensions: []
114
128
  extra_rdoc_files: []
115
129
  files:
116
- - ".github/workflows/git-secrets.yml"
117
130
  - ".gitignore"
131
+ - ".pre-commit-config.yaml"
118
132
  - ".rspec"
119
133
  - ".whitesource"
120
134
  - Gemfile
@@ -142,12 +156,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
156
  version: 2.1.0
143
157
  required_rubygems_version: !ruby/object:Gem::Requirement
144
158
  requirements:
145
- - - ">="
159
+ - - ">"
146
160
  - !ruby/object:Gem::Version
147
- version: '0'
161
+ version: 1.3.1
148
162
  requirements: []
149
- rubyforge_project: fluent-plugin-logzio
150
- rubygems_version: 2.5.2.3
163
+ rubygems_version: 3.0.3.1
151
164
  signing_key:
152
165
  specification_version: 4
153
166
  summary: Fluentd plugin for output to Logz.io
@@ -1,33 +0,0 @@
1
- name: git-secrets
2
-
3
- # Controls when the workflow will run
4
- # Triggers the workflow on push or pull request events but only for the main branch
5
- on: [push]
6
-
7
- # A workflow run is made up of one or more jobs that can run sequentially or in parallel
8
- jobs:
9
- # This workflow contains a single job called "main"
10
- git-secrets:
11
- # The type of runner that the job will run on
12
- runs-on: ubuntu-18.04
13
-
14
- # Steps represent a sequence of tasks that will be executed as part of the job
15
- steps:
16
- - name: Check Out Source Code
17
- uses: actions/checkout@v2
18
-
19
- - name: Set up Python 3.8
20
- uses: actions/setup-python@v2
21
- with:
22
- python-version: 3.8
23
- - name: Installing dependencies
24
- run:
25
- sudo apt-get install git less openssh-server
26
- - name: Installing scanning tool
27
- run: |
28
- brew install git-secrets
29
- git secrets --install
30
- git secrets --register-aws
31
- - name: Running scanning tool
32
- run:
33
- git secrets --scan