fluent-plugin-grafana-loki 1.2.17 → 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: 7314140e15cf44c0150b92442687304a8ce1f90470ddf9527a10d75603840e19
4
- data.tar.gz: 911185ef9e06820f156a763bc7ce562ff476982190b4a63658b505c278490892
3
+ metadata.gz: d1ebd917165346591d6426c54b36d736fedd78febe444ba9d8bc8e1ceb9d168d
4
+ data.tar.gz: 631078fe62f397592b9fdc0db07d895c9e74aefd3c2dc06c13949eb05b7229ab
5
5
  SHA512:
6
- metadata.gz: db08e94fc3b4b3bf5ca23df7488adad1d2ed2ca9ebd6bda6da2e7119594270efe02d8c3ee6a4dbc40b478eae120fb37565ac60ea0cd9b04ebf3c73f3b507a7a2
7
- data.tar.gz: 0ceee039f2801221495c67ea1e052e92d5da5795791af218d9d5ceb3c73e8aca661cac4dba75de5c635f6ff012ac58094aecb809f77e6d6649db250d2eb91b41
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,9 +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
- v = v.encode('utf-8', invalid: :replace)
285
+ v = v.encode('utf-8', invalid: :replace, undef: :replace, replace: '?') if v.is_a?(String)
283
286
  # Escape double quotes and backslashes by prefixing them with a backslash
284
- v = v.to_s.gsub(%r{(["\\])}, '\\\\\1')
287
+ v = v.to_s.gsub(/(["\\])/, '\\\\\1')
285
288
  if v.include?(' ') || v.include?('=')
286
289
  formatted_labels.push(%(#{k}="#{v}"))
287
290
  else
@@ -293,25 +296,25 @@ module Fluent
293
296
  end
294
297
  line
295
298
  end
299
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
296
300
 
297
301
  # convert a line to loki line with labels
302
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
298
303
  def line_to_loki(record)
299
304
  chunk_labels = {}
300
305
  line = ''
301
306
  if record.is_a?(Hash)
302
307
  @record_accessors&.each do |name, accessor|
303
- new_key = name.gsub(%r{[.\-\/]}, '_')
308
+ new_key = name.gsub(%r{[.\-/]}, '_')
304
309
  chunk_labels[new_key] = accessor.call(record)
305
310
  accessor.delete(record)
306
311
  end
307
312
 
308
313
  if @extract_kubernetes_labels && record.key?('kubernetes')
309
314
  kubernetes_labels = record['kubernetes']['labels']
310
- if !kubernetes_labels.nil?
311
- kubernetes_labels.each_key do |l|
312
- new_key = l.gsub(%r{[.\-\/]}, '_')
313
- chunk_labels[new_key] = kubernetes_labels[l]
314
- end
315
+ kubernetes_labels&.each_key do |l|
316
+ new_key = l.gsub(%r{[.\-/]}, '_')
317
+ chunk_labels[new_key] = kubernetes_labels[l]
315
318
  end
316
319
  end
317
320
 
@@ -330,7 +333,7 @@ module Fluent
330
333
  # unique per flush thread
331
334
  # note that flush thread != fluentd worker. if you use multiple workers you still need to
332
335
  # add the worker id as a label
333
- if @buffer_config.flush_thread_count > 1
336
+ if @include_thread_label && @buffer_config.flush_thread_count > 1
334
337
  chunk_labels['fluentd_thread'] = Thread.current[:_fluentd_plugin_helper_thread_title].to_s
335
338
  end
336
339
 
@@ -340,6 +343,7 @@ module Fluent
340
343
  labels: chunk_labels
341
344
  }
342
345
  end
346
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
343
347
 
344
348
  # iterate through each chunk and create a loki stream entry
345
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.17
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-12 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