logstash-output-edge_loki 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logstash/outputs/edge_loki.rb +39 -14
- data/logstash-output-edge_loki.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5ec89dff9f872d7371462dc0e39118ac9e0fa9d662fa5eecd4e99e9565f29d7
|
4
|
+
data.tar.gz: b598d411be65be2e16c9ce26d6d954cc63496085b714e66bc6274af6c42ef765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eef5ab0b6d08ab8968575e33cb60b88ecc6b45775df95c7abde04229bcc80577f394a976d4041bdd954772f598b67b94ce9da028c4f4ce32cd67a03bd5739da
|
7
|
+
data.tar.gz: b7f7529cc7d32de3e6c47a579f5db49595f2671d156660add48091ff4be26a83621ecb1196b3769854d7eae22ade1e0dbf4ad9bbd3008327a9c6fe83b0b6ee9f
|
@@ -15,9 +15,12 @@ class LogStash::Outputs::EDGE_Loki < LogStash::Outputs::Base
|
|
15
15
|
|
16
16
|
## 'A single instance of the Output will be shared among the pipeline worker threads'
|
17
17
|
concurrency :single
|
18
|
+
|
19
|
+
## 'Loki Domain'
|
20
|
+
config :domain, :validate => :string, :required => true
|
18
21
|
|
19
|
-
## 'Loki
|
20
|
-
config :
|
22
|
+
## 'Loki Endpoint'
|
23
|
+
config :endpoint, :validate => :string, :required => true
|
21
24
|
|
22
25
|
## 'BasicAuth credentials'
|
23
26
|
config :client_id, :validate => :string, :required => false
|
@@ -224,9 +227,10 @@ class LogStash::Outputs::EDGE_Loki < LogStash::Outputs::Base
|
|
224
227
|
|
225
228
|
def send(batch)
|
226
229
|
@logger.info("send: started method")
|
227
|
-
|
230
|
+
token = createClient()
|
228
231
|
payload = batch.to_json
|
229
|
-
res =
|
232
|
+
res = pensive_http_request(token, payload)
|
233
|
+
@logger.info("send result: ", res => res)
|
230
234
|
if res.is_a?(Net::HTTPSuccess)
|
231
235
|
@logger.debug("Successfully pushed data to loki")
|
232
236
|
else
|
@@ -234,25 +238,38 @@ class LogStash::Outputs::EDGE_Loki < LogStash::Outputs::Base
|
|
234
238
|
end
|
235
239
|
end
|
236
240
|
|
237
|
-
def
|
241
|
+
def send1(batch)
|
242
|
+
@logger.info("send: started method")
|
243
|
+
token = createClient()
|
244
|
+
payload = batch.to_json
|
245
|
+
res = loki_http_request(token, payload)
|
246
|
+
if res.is_a?(Net::HTTPSuccess)
|
247
|
+
@logger.debug("Successfully pushed data to loki")
|
248
|
+
else
|
249
|
+
@logger.debug("failed payload", :payload => payload)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def loki_http_request(token, payload)
|
238
254
|
@logger.info("loki_http_request: started method")
|
239
255
|
req = Net::HTTP::Post.new(
|
240
256
|
@uri.request_uri
|
241
257
|
)
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
258
|
+
|
259
|
+
req.add_field('Content-Type', 'application/json')
|
260
|
+
req.add_field('X-Scope-OrgID', @tenant_id) if @tenant_id
|
261
|
+
req['User-Agent']= 'loki-logstash'
|
262
|
+
req.basic_auth(@client_id, @client_secret) if @client_id
|
263
|
+
req.body = payload
|
247
264
|
|
248
265
|
opts = ssl_opts(@uri)
|
249
266
|
|
250
|
-
@logger.debug("sending #{
|
267
|
+
@logger.debug("sending #{req.body.length} bytes to loki")
|
251
268
|
retry_count = 0
|
252
269
|
delay = @min_delay
|
253
270
|
begin
|
254
271
|
res = Net::HTTP.start(@uri.host, @uri.port, **opts) { |http|
|
255
|
-
http.request(
|
272
|
+
http.request(req)
|
256
273
|
}
|
257
274
|
return res if !res.nil? && res.code.to_i != 429 && res.code.to_i.div(100) != 5
|
258
275
|
raise StandardError.new res
|
@@ -276,11 +293,19 @@ class LogStash::Outputs::EDGE_Loki < LogStash::Outputs::Base
|
|
276
293
|
|
277
294
|
def createClient
|
278
295
|
@logger.info("createClient: started method")
|
279
|
-
client = OAuth2::Client.new(@client_id, @client_secret, site: @
|
296
|
+
client = OAuth2::Client.new(@client_id, @client_secret, site: @domain + @endpoint)
|
280
297
|
client.auth_code.authorize_url(redirect_uri: @token_url)
|
298
|
+
token = client.auth_code.get_token(code, :redirect_uri => @token_url)
|
281
299
|
@logger.info("createClient: started method", :client => client)
|
282
|
-
return
|
300
|
+
return token
|
283
301
|
end
|
284
302
|
|
303
|
+
def pensive_http_request(token, payload)
|
304
|
+
@logger.info("pensive_http_request: started method")
|
305
|
+
response = token.get(@endpoint, :headers => { 'Accept' => 'application/json', 'X-Scope-OrgID', @tenant_id }, :params => { page: 1 })
|
306
|
+
hash = JSON.parse(response.body)
|
307
|
+
@logger.info("pensive_http_request: ", :token_output => hash)
|
308
|
+
return hash
|
309
|
+
end
|
285
310
|
end
|
286
311
|
|