fluent-plugin-grafana-loki 1.2.16 → 1.2.20
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 +4 -4
- data/README.md +16 -4
- data/bin/setup +6 -4
- data/bin/test +5 -0
- data/lib/fluent/plugin/out_loki.rb +28 -23
- metadata +8 -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
|
@@ -6,14 +6,17 @@ See [docs/client/fluentd/README.md](../../docs/sources/clients/fluentd/_index.md
|
|
|
6
6
|
|
|
7
7
|
## Development
|
|
8
8
|
|
|
9
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
|
9
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
10
10
|
|
|
11
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `fluent-plugin-grafana-loki.gemspec`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
11
|
+
To install this gem onto your local machine, run `ruby -S bundle exec rake install`. To release a new version, update the version number in `fluent-plugin-grafana-loki.gemspec`, and then run `ruby -S bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
12
12
|
|
|
13
|
-
To create the gem: `gem build fluent-plugin-grafana-loki.gemspec`
|
|
13
|
+
To create the gem: `ruby -S gem build fluent-plugin-grafana-loki.gemspec`
|
|
14
14
|
|
|
15
15
|
Useful additions:
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
ruby -S gem install rubocop
|
|
19
|
+
```
|
|
17
20
|
|
|
18
21
|
## Testing
|
|
19
22
|
|
|
@@ -79,6 +82,15 @@ The expected output is:
|
|
|
79
82
|
]
|
|
80
83
|
```
|
|
81
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
|
+
|
|
82
94
|
## Copyright
|
|
83
95
|
|
|
84
96
|
* Copyright(c) 2018- Grafana Labs
|
data/bin/setup
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
+
|
|
2
3
|
set -euo pipefail
|
|
3
|
-
IFS=$'\n\t'
|
|
4
|
-
set -vx
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
ruby --version
|
|
6
|
+
echo ""
|
|
7
|
+
ruby -S gem install bundler --version 2.3.4
|
|
8
|
+
ruby -S bundle config set --local path $(pwd)/vendor/bundle
|
|
9
|
+
ruby -S bundle install
|
data/bin/test
ADDED
|
@@ -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
|
|
@@ -278,8 +281,10 @@ module Fluent
|
|
|
278
281
|
when :key_value
|
|
279
282
|
formatted_labels = []
|
|
280
283
|
record.each do |k, v|
|
|
284
|
+
# Remove non UTF-8 characters by force-encoding the string
|
|
285
|
+
v = v.encode('utf-8', invalid: :replace, undef: :replace, replace: '?') if v.is_a?(String)
|
|
281
286
|
# Escape double quotes and backslashes by prefixing them with a backslash
|
|
282
|
-
v = v.to_s.gsub(
|
|
287
|
+
v = v.to_s.gsub(/(["\\])/, '\\\\\1')
|
|
283
288
|
if v.include?(' ') || v.include?('=')
|
|
284
289
|
formatted_labels.push(%(#{k}="#{v}"))
|
|
285
290
|
else
|
|
@@ -291,23 +296,24 @@ module Fluent
|
|
|
291
296
|
end
|
|
292
297
|
line
|
|
293
298
|
end
|
|
299
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
294
300
|
|
|
295
|
-
#
|
|
296
301
|
# convert a line to loki line with labels
|
|
302
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
297
303
|
def line_to_loki(record)
|
|
298
304
|
chunk_labels = {}
|
|
299
305
|
line = ''
|
|
300
306
|
if record.is_a?(Hash)
|
|
301
307
|
@record_accessors&.each do |name, accessor|
|
|
302
|
-
new_key = name.gsub(%r{[
|
|
308
|
+
new_key = name.gsub(%r{[.\-/]}, '_')
|
|
303
309
|
chunk_labels[new_key] = accessor.call(record)
|
|
304
310
|
accessor.delete(record)
|
|
305
311
|
end
|
|
306
312
|
|
|
307
313
|
if @extract_kubernetes_labels && record.key?('kubernetes')
|
|
308
314
|
kubernetes_labels = record['kubernetes']['labels']
|
|
309
|
-
kubernetes_labels
|
|
310
|
-
new_key = l.gsub(%r{[
|
|
315
|
+
kubernetes_labels&.each_key do |l|
|
|
316
|
+
new_key = l.gsub(%r{[.\-/]}, '_')
|
|
311
317
|
chunk_labels[new_key] = kubernetes_labels[l]
|
|
312
318
|
end
|
|
313
319
|
end
|
|
@@ -327,7 +333,7 @@ module Fluent
|
|
|
327
333
|
# unique per flush thread
|
|
328
334
|
# note that flush thread != fluentd worker. if you use multiple workers you still need to
|
|
329
335
|
# add the worker id as a label
|
|
330
|
-
if @buffer_config.flush_thread_count > 1
|
|
336
|
+
if @include_thread_label && @buffer_config.flush_thread_count > 1
|
|
331
337
|
chunk_labels['fluentd_thread'] = Thread.current[:_fluentd_plugin_helper_thread_title].to_s
|
|
332
338
|
end
|
|
333
339
|
|
|
@@ -337,14 +343,13 @@ module Fluent
|
|
|
337
343
|
labels: chunk_labels
|
|
338
344
|
}
|
|
339
345
|
end
|
|
346
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
340
347
|
|
|
341
348
|
# iterate through each chunk and create a loki stream entry
|
|
342
349
|
def chunk_to_loki(chunk)
|
|
343
350
|
streams = {}
|
|
344
|
-
last_time = nil
|
|
345
351
|
chunk.each do |time, record|
|
|
346
352
|
# each chunk has a unique set of labels
|
|
347
|
-
last_time = time if last_time.nil?
|
|
348
353
|
result = line_to_loki(record)
|
|
349
354
|
chunk_labels = result[:labels]
|
|
350
355
|
# initialize a new stream with the chunk_labels if it does not exist
|
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
|
|
@@ -129,12 +129,13 @@ files:
|
|
|
129
129
|
- README.md
|
|
130
130
|
- bin/console
|
|
131
131
|
- bin/setup
|
|
132
|
+
- bin/test
|
|
132
133
|
- lib/fluent/plugin/out_loki.rb
|
|
133
134
|
homepage: https://github.com/grafana/loki/
|
|
134
135
|
licenses:
|
|
135
136
|
- Apache-2.0
|
|
136
137
|
metadata: {}
|
|
137
|
-
post_install_message:
|
|
138
|
+
post_install_message:
|
|
138
139
|
rdoc_options: []
|
|
139
140
|
require_paths:
|
|
140
141
|
- lib
|
|
@@ -142,15 +143,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
142
143
|
requirements:
|
|
143
144
|
- - ">="
|
|
144
145
|
- !ruby/object:Gem::Version
|
|
145
|
-
version: '
|
|
146
|
+
version: '2.7'
|
|
146
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
148
|
requirements:
|
|
148
149
|
- - ">="
|
|
149
150
|
- !ruby/object:Gem::Version
|
|
150
151
|
version: '0'
|
|
151
152
|
requirements: []
|
|
152
|
-
rubygems_version: 3.
|
|
153
|
-
signing_key:
|
|
153
|
+
rubygems_version: 3.3.7
|
|
154
|
+
signing_key:
|
|
154
155
|
specification_version: 4
|
|
155
156
|
summary: Output plugin to ship logs to a Grafana Loki server
|
|
156
157
|
test_files: []
|