fluent-plugin-grafana-loki 1.2.18 → 1.2.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/fluent/plugin/out_loki.rb +28 -26
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c085d1fab891521b78a29e74cb171049013870eacf0bd902a82b73c5e2c1be6
|
4
|
+
data.tar.gz: f82af7a67da96eb1b51f9de96c1b9ca156b7b3304072f0a38cdfd0f5e324f49f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afc6b16682378857824334d80767ee7ff6ea1ca44a9b0cec3d4e131eab3049da6342a9d5adf5d16b65d2ceacc404cf280930675a296caf1b119dc5e0f3c90752
|
7
|
+
data.tar.gz: 276a4724d61a1290f4bed889a620dda8e87c42acdf46bc26907455c0f453fc1ef9829d06830a791c8a95a62a1ec841feb18d851cbb543baec99d818ff362d39f
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
112
|
-
|
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
|
-
|
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
|
-
|
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}")
|
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
|
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(
|
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
|
-
|
313
|
-
|
314
|
-
|
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,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-grafana-loki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- woodsaj
|
8
8
|
- briangann
|
9
9
|
- cyriltovena
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-02-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fluentd
|
@@ -135,7 +135,7 @@ homepage: https://github.com/grafana/loki/
|
|
135
135
|
licenses:
|
136
136
|
- Apache-2.0
|
137
137
|
metadata: {}
|
138
|
-
post_install_message:
|
138
|
+
post_install_message:
|
139
139
|
rdoc_options: []
|
140
140
|
require_paths:
|
141
141
|
- lib
|
@@ -143,15 +143,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
143
|
requirements:
|
144
144
|
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: '
|
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.
|
154
|
-
signing_key:
|
153
|
+
rubygems_version: 3.3.7
|
154
|
+
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Output plugin to ship logs to a Grafana Loki server
|
157
157
|
test_files: []
|