logstash-output-edge_loki 1.0.7 → 1.0.8

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: b7815895543bbcb18b5a4b9383f083223f229713c537f336f48cc2cffd76fed7
4
- data.tar.gz: d8d68d9291a738b47d4de30ec1d3c2a62894aae498dfb6869e14684d4cbebb37
3
+ metadata.gz: a5ec89dff9f872d7371462dc0e39118ac9e0fa9d662fa5eecd4e99e9565f29d7
4
+ data.tar.gz: b598d411be65be2e16c9ce26d6d954cc63496085b714e66bc6274af6c42ef765
5
5
  SHA512:
6
- metadata.gz: 4baf39cedf6a80af43190b002452d7565e1e1277de335aa708fd0533f76a527250ec90c420b1a643f7adf4c61d9dfe3216d9df4c10217aa926b126e703b504b1
7
- data.tar.gz: 7fc3f6ad11def007015b2180ed15c663919babce9f36d5e69d1533751f2ebbf78325f8fb949c7f92c8cf90aadc072e428f478cbc8f8dc8c6e37592072f93aebe
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 URL'
20
- config :url, :validate => :string, :required => true
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
- client = createClient()
230
+ token = createClient()
228
231
  payload = batch.to_json
229
- res = loki_http_request(client, payload)
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 loki_http_request(client, payload)
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
- client.add_field('Content-Type', 'application/json')
243
- client.add_field('X-Scope-OrgID', @tenant_id) if @tenant_id
244
- client['User-Agent']= 'loki-logstash'
245
- client.basic_auth(@client_id, @client_secret) if @client_id
246
- client.body = payload
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 #{client.body.length} bytes to loki")
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(client)
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: @url)
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 client
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-edge_loki'
3
- s.version = '1.0.7'
3
+ s.version = '1.0.8'
4
4
  s.authors = ['Britto Prabhu']
5
5
  s.email = ['britto.prabhu@apmterminals.com']
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-edge_loki
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Britto Prabhu