fluent-plugin-grafana-loki 1.2.10 → 1.2.11
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/lib/fluent/plugin/out_loki.rb +26 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f55e32f690e614bb33d3f905d01881bc0ad1bdc6a55badb1088930725d310c1b
|
4
|
+
data.tar.gz: dd4e2c4477d6edd9ea4f917cf62a821a99cfc0799639fe4445f5ac2635988305
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d86cf23b27f243822ee9628e472d26f2bb6869462b471ddc26f9b0f347f36d48dec7f0aa3bce2bf2cac5893352a8509d71d4363f782d4b7dc8db2dcd7e1b1175
|
7
|
+
data.tar.gz: 010ce549ecdc4c6945a9a09fe790f82364eafa6389c3829e5d0483e7f595c5db4f449b584769c1d1214df8c0d1794a29c3a4a1fe8c9e214327be226e38f99cb1
|
@@ -15,6 +15,7 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
|
+
require 'fluent/env'
|
18
19
|
require 'fluent/plugin/output'
|
19
20
|
require 'net/http'
|
20
21
|
require 'yajl'
|
@@ -26,6 +27,8 @@ module Fluent
|
|
26
27
|
class LokiOutput < Fluent::Plugin::Output # rubocop:disable Metrics/ClassLength
|
27
28
|
Fluent::Plugin.register_output('loki', self)
|
28
29
|
|
30
|
+
class LogPostError < StandardError; end
|
31
|
+
|
29
32
|
helpers :compat_parameters, :record_accessor
|
30
33
|
|
31
34
|
attr_accessor :record_accessors
|
@@ -131,29 +134,16 @@ module Fluent
|
|
131
134
|
body = { 'streams' => payload }
|
132
135
|
|
133
136
|
# add ingest path to loki url
|
137
|
+
res = loki_http_request(body)
|
134
138
|
|
135
|
-
|
136
|
-
@uri.request_uri
|
137
|
-
)
|
138
|
-
req.add_field('Content-Type', 'application/json')
|
139
|
-
req.add_field('X-Scope-OrgID', @tenant) if @tenant
|
140
|
-
req.body = Yajl.dump(body)
|
141
|
-
req.basic_auth(@username, @password) if @username
|
142
|
-
|
143
|
-
opts = ssl_opts(@uri)
|
139
|
+
return if res.is_a?(Net::HTTPSuccess)
|
144
140
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
res_summary = if res
|
149
|
-
"#{res.code} #{res.message} #{res.body}"
|
150
|
-
else
|
151
|
-
'res=nil'
|
152
|
-
end
|
153
|
-
log.warn "failed to #{req.method} #{@uri} (#{res_summary})"
|
154
|
-
log.debug Yajl.dump(body)
|
141
|
+
res_summary = "#{res.code} #{res.message} #{res.body}"
|
142
|
+
log.warn "failed to write post to #{@uri} (#{res_summary})"
|
143
|
+
log.debug Yajl.dump(body)
|
155
144
|
|
156
|
-
|
145
|
+
# Only retry 429 and 500s
|
146
|
+
raise(LogPostError, res_summary) if res.is_a?(Net::HTTPTooManyRequests) || res.is_a?(Net::HTTPServerError)
|
157
147
|
end
|
158
148
|
|
159
149
|
def ssl_opts(uri)
|
@@ -186,6 +176,22 @@ module Fluent
|
|
186
176
|
|
187
177
|
private
|
188
178
|
|
179
|
+
def loki_http_request(body)
|
180
|
+
req = Net::HTTP::Post.new(
|
181
|
+
@uri.request_uri
|
182
|
+
)
|
183
|
+
req.add_field('Content-Type', 'application/json')
|
184
|
+
req.add_field('X-Scope-OrgID', @tenant) if @tenant
|
185
|
+
req.body = Yajl.dump(body)
|
186
|
+
req.basic_auth(@username, @password) if @username
|
187
|
+
|
188
|
+
opts = ssl_opts(@uri)
|
189
|
+
|
190
|
+
log.debug "sending #{req.body.length} bytes to loki"
|
191
|
+
|
192
|
+
Net::HTTP.start(@uri.host, @uri.port, **opts) { |http| http.request(req) }
|
193
|
+
end
|
194
|
+
|
189
195
|
def numeric?(val)
|
190
196
|
!Float(val).nil?
|
191
197
|
rescue StandardError
|
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.
|
4
|
+
version: 1.2.11
|
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: 2020-03-
|
13
|
+
date: 2020-03-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|