fluent-plugin-grafana-loki 1.2.18 → 1.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4a8acb3f25f565acd7f4071ea961ab1d7a76b7a2f80068fbcc77c3e380f3f5d
4
- data.tar.gz: 9b0c3124a9a12d2c5f2f5a1a96d885fe257040b0c58db62bd323d8799a7c62bc
3
+ metadata.gz: d1ebd917165346591d6426c54b36d736fedd78febe444ba9d8bc8e1ceb9d168d
4
+ data.tar.gz: 631078fe62f397592b9fdc0db07d895c9e74aefd3c2dc06c13949eb05b7229ab
5
5
  SHA512:
6
- metadata.gz: 65384975b8afc4d2fe377d7551caf461b14ea92dd9b21d254bf3cd001582807918671f724e902d012694fd7907601eb738c8d9f7adb14b2474163154a79eaa8b
7
- data.tar.gz: f2fb6366e91d22068797f43cf7b439b06d788a4dac33936bd62fa7895056f1f03e5b439ba2e31e0523152af8c0b2a6c380cc15eb1b35502cefcd5a8daeaeb601
6
+ metadata.gz: 4464b1422ca11a5f172b77bdb136e5c26c86a6dc7b1fe7072fcf72bbf613249fd0611864efafd6c87252491836a161670a7ecdb38bd4d83a7a0618027730c764
7
+ data.tar.gz: 1eff1349f98f245444b29bbaba14122f836d8689caa1b9788c2bfe634ae12f2096475518e0766ced2c3581cbdcbb70a94337789e174ccffd96a11466f4b638eb
data/README.md CHANGED
@@ -82,6 +82,15 @@ The expected output is:
82
82
  ]
83
83
  ```
84
84
 
85
+ ## Build and publish gem
86
+
87
+ To build and publish a gem to
88
+ [rubygems](https://rubygems.org/gems/fluent-plugin-grafana-loki) you first need
89
+ to update the version in the `fluent-plugin-grafana-loki.gemspec` file.
90
+ Then update the `VERSION` variable in the `Makefile` to match the new version number.
91
+ Create a PR with the changes against the `main` branch und run `make
92
+ fluentd-plugin-push` from the root of the project once the PR has been merged.
93
+
85
94
  ## Copyright
86
95
 
87
96
  * Copyright(c) 2018- Grafana Labs
@@ -73,15 +73,19 @@ module Fluent
73
73
  desc 'if a record only has 1 key, then just set the log line to the value and discard the key.'
74
74
  config_param :drop_single_key, :bool, default: false
75
75
 
76
+ desc 'whether or not to include the fluentd_thread label when multiple threads are used for flushing'
77
+ config_param :include_thread_label, :bool, default: true
78
+
76
79
  config_section :buffer do
77
80
  config_set_default :@type, DEFAULT_BUFFER_TYPE
78
81
  config_set_default :chunk_keys, []
79
82
  end
80
83
 
81
- def configure(conf) # rubocop:disable Metrics/CyclomaticComplexity
84
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
85
+ def configure(conf)
82
86
  compat_parameters_convert(conf, :buffer)
83
87
  super
84
- @uri = URI.parse(@url + '/loki/api/v1/push')
88
+ @uri = URI.parse("#{@url}/loki/api/v1/push")
85
89
  unless @uri.is_a?(URI::HTTP) || @uri.is_a?(URI::HTTPS)
86
90
  raise Fluent::ConfigError, 'URL parameter must have HTTP/HTTPS scheme'
87
91
  end
@@ -105,25 +109,24 @@ module Fluent
105
109
  validate_client_cert_key
106
110
  end
107
111
 
108
- raise "bearer_token_file #{@bearer_token_file} not found" if !@bearer_token_file.nil? && !File.exist?(@bearer_token_file)
112
+ if !@bearer_token_file.nil? && !File.exist?(@bearer_token_file)
113
+ raise "bearer_token_file #{@bearer_token_file} not found"
114
+ end
109
115
 
110
116
  @auth_token_bearer = nil
111
- if !@bearer_token_file.nil?
112
- if !File.exist?(@bearer_token_file)
113
- raise "bearer_token_file #{@bearer_token_file} not found"
114
- end
117
+ unless @bearer_token_file.nil?
118
+ raise "bearer_token_file #{@bearer_token_file} not found" unless File.exist?(@bearer_token_file)
115
119
 
116
120
  # Read the file once, assume long-lived authentication token.
117
121
  @auth_token_bearer = File.read(@bearer_token_file)
118
- if @auth_token_bearer.empty?
119
- raise "bearer_token_file #{@bearer_token_file} is empty"
120
- end
122
+ raise "bearer_token_file #{@bearer_token_file} is empty" if @auth_token_bearer.empty?
123
+
121
124
  log.info "will use Bearer token from bearer_token_file #{@bearer_token_file} in Authorization header"
122
125
  end
123
126
 
124
-
125
127
  raise "CA certificate file #{@ca_cert} not found" if !@ca_cert.nil? && !File.exist?(@ca_cert)
126
128
  end
129
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
127
130
 
128
131
  def client_cert_configured?
129
132
  !@key.nil? && !@cert.nil?
@@ -201,8 +204,7 @@ module Fluent
201
204
  def generic_to_loki(chunk)
202
205
  # log.debug("GenericToLoki: converting #{chunk}")
203
206
  streams = chunk_to_loki(chunk)
204
- payload = payload_builder(streams)
205
- payload
207
+ payload_builder(streams)
206
208
  end
207
209
 
208
210
  private
@@ -212,7 +214,7 @@ module Fluent
212
214
  @uri.request_uri
213
215
  )
214
216
  req.add_field('Content-Type', 'application/json')
215
- req.add_field('Authorization', "Bearer #{@auth_token_bearer}") if !@auth_token_bearer.nil?
217
+ req.add_field('Authorization', "Bearer #{@auth_token_bearer}") unless @auth_token_bearer.nil?
216
218
  req.add_field('X-Scope-OrgID', tenant) if tenant
217
219
  req.body = Yajl.dump(body)
218
220
  req.basic_auth(@username, @password) if @username
@@ -238,7 +240,7 @@ module Fluent
238
240
  data_labels = {} if data_labels.nil?
239
241
  data_labels = data_labels.merge(@extra_labels)
240
242
  # sanitize label values
241
- data_labels.each { |k, v| formatted_labels[k] = v.gsub('"', '\\"') if v && v&.is_a?(String) }
243
+ data_labels.each { |k, v| formatted_labels[k] = v.gsub('"', '\\"') if v.is_a?(String) }
242
244
  formatted_labels
243
245
  end
244
246
 
@@ -267,6 +269,7 @@ module Fluent
267
269
  end
268
270
  end
269
271
 
272
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
270
273
  def record_to_line(record)
271
274
  line = ''
272
275
  if @drop_single_key && record.keys.length == 1
@@ -279,11 +282,9 @@ module Fluent
279
282
  formatted_labels = []
280
283
  record.each do |k, v|
281
284
  # Remove non UTF-8 characters by force-encoding the string
282
- if v.is_a?(String)
283
- v = v.encode('utf-8', invalid: :replace)
284
- end
285
+ v = v.encode('utf-8', invalid: :replace, undef: :replace, replace: '?') if v.is_a?(String)
285
286
  # Escape double quotes and backslashes by prefixing them with a backslash
286
- v = v.to_s.gsub(%r{(["\\])}, '\\\\\1')
287
+ v = v.to_s.gsub(/(["\\])/, '\\\\\1')
287
288
  if v.include?(' ') || v.include?('=')
288
289
  formatted_labels.push(%(#{k}="#{v}"))
289
290
  else
@@ -295,25 +296,25 @@ module Fluent
295
296
  end
296
297
  line
297
298
  end
299
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
298
300
 
299
301
  # convert a line to loki line with labels
302
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
300
303
  def line_to_loki(record)
301
304
  chunk_labels = {}
302
305
  line = ''
303
306
  if record.is_a?(Hash)
304
307
  @record_accessors&.each do |name, accessor|
305
- new_key = name.gsub(%r{[.\-\/]}, '_')
308
+ new_key = name.gsub(%r{[.\-/]}, '_')
306
309
  chunk_labels[new_key] = accessor.call(record)
307
310
  accessor.delete(record)
308
311
  end
309
312
 
310
313
  if @extract_kubernetes_labels && record.key?('kubernetes')
311
314
  kubernetes_labels = record['kubernetes']['labels']
312
- if !kubernetes_labels.nil?
313
- kubernetes_labels.each_key do |l|
314
- new_key = l.gsub(%r{[.\-\/]}, '_')
315
- chunk_labels[new_key] = kubernetes_labels[l]
316
- end
315
+ kubernetes_labels&.each_key do |l|
316
+ new_key = l.gsub(%r{[.\-/]}, '_')
317
+ chunk_labels[new_key] = kubernetes_labels[l]
317
318
  end
318
319
  end
319
320
 
@@ -332,7 +333,7 @@ module Fluent
332
333
  # unique per flush thread
333
334
  # note that flush thread != fluentd worker. if you use multiple workers you still need to
334
335
  # add the worker id as a label
335
- if @buffer_config.flush_thread_count > 1
336
+ if @include_thread_label && @buffer_config.flush_thread_count > 1
336
337
  chunk_labels['fluentd_thread'] = Thread.current[:_fluentd_plugin_helper_thread_title].to_s
337
338
  end
338
339
 
@@ -342,6 +343,7 @@ module Fluent
342
343
  labels: chunk_labels
343
344
  }
344
345
  end
346
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
345
347
 
346
348
  # iterate through each chunk and create a loki stream entry
347
349
  def chunk_to_loki(chunk)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-grafana-loki
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.18
4
+ version: 1.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - woodsaj
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-01-17 00:00:00.000000000 Z
13
+ date: 2022-11-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fluentd
@@ -141,16 +141,16 @@ require_paths:
141
141
  - lib
142
142
  required_ruby_version: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - ">="
144
+ - - "~>"
145
145
  - !ruby/object:Gem::Version
146
- version: '0'
146
+ version: '2.7'
147
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - ">="
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.0.3.1
153
+ rubygems_version: 3.1.6
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Output plugin to ship logs to a Grafana Loki server