logstash-output-edge_loki 1.0.7 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7815895543bbcb18b5a4b9383f083223f229713c537f336f48cc2cffd76fed7
4
- data.tar.gz: d8d68d9291a738b47d4de30ec1d3c2a62894aae498dfb6869e14684d4cbebb37
3
+ metadata.gz: 459c97179f8e5871f7992ce20df5ba1ef2dc95ec0959eecbb1dbfda58c2dd81c
4
+ data.tar.gz: 672e5fc63bb488cd69fe6522cd210235fd6824d7677a713b45e16d8adc7864ce
5
5
  SHA512:
6
- metadata.gz: 4baf39cedf6a80af43190b002452d7565e1e1277de335aa708fd0533f76a527250ec90c420b1a643f7adf4c61d9dfe3216d9df4c10217aa926b126e703b504b1
7
- data.tar.gz: 7fc3f6ad11def007015b2180ed15c663919babce9f36d5e69d1533751f2ebbf78325f8fb949c7f92c8cf90aadc072e428f478cbc8f8dc8c6e37592072f93aebe
6
+ metadata.gz: 0727eb5e0abbf2cf0aeba08606b13a4081aa662f5b31afe1caebf7670d6ff62ed6059b1701d6662867feca4f1ab4a2b052eff678d02a7f2ee7849c3c7437b562
7
+ data.tar.gz: 2417817e5581a05067965c93a5e7e61a0f1403f4db0301c8f80d58eb03eca6e48eeacb9b583a046edb188e716793a15d2b3695ce15ad06eda6dfc4703bd1d2ac
@@ -15,29 +15,35 @@ 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
-
18
+
19
19
  ## 'Loki URL'
20
20
  config :url, :validate => :string, :required => true
21
21
 
22
22
  ## 'BasicAuth credentials'
23
- config :client_id, :validate => :string, :required => false
24
- config :client_secret, :validate => :string, secret: true, :required => false
23
+ config :client_id, :validate => :string, :required => true
24
+ config :client_secret, :validate => :string, secret: true, :required => true
25
25
 
26
- ## 'Client certificate'
27
- config :cert, :validate => :path, :required => false
28
- config :key, :validate => :path, :required => false
26
+ ## 'Loki Token URL Domain'
27
+ config :tokenurl_domain, :validate => :string, :required => true
29
28
 
30
- ## 'TLS'
31
- config :ca_cert, :validate => :path, :required => false
29
+ ## 'Loki Token URL Endpoint'
30
+ config :tokenurl_endpoint, :validate => :string, :default => "oauth2/v2.0/token", :required => false
31
+
32
+ ## 'Scopes'
33
+ config :scopes, :validate => :string, :required => true
34
+
35
+ ## 'Proxy URL'
36
+ config :proxy_url, :validate => :string, :required => false
32
37
 
33
38
  ## 'Disable server certificate verification'
34
39
  config :insecure_skip_verify, :validate => :boolean, :default => false, :required => false
35
40
 
36
- ## 'Loki Tenant ID'
37
- config :tenant_id, :validate => :string, :required => false
41
+ ## 'Client certificate'
42
+ config :cert, :validate => :path, :required => false
43
+ config :key, :validate => :path, :required => false
38
44
 
39
- ## 'Loki Token URL'
40
- config :token_url, :validate => :string, :required => false
45
+ ## 'TLS'
46
+ config :ca_cert, :validate => :path, :required => false
41
47
 
42
48
  ## 'Maximum batch size to accrue before pushing to loki. Defaults to 102400 bytes'
43
49
  config :batch_size, :validate => :number, :default => 102400, :required => false
@@ -94,7 +100,7 @@ class LogStash::Outputs::EDGE_Loki < LogStash::Outputs::Base
94
100
  end
95
101
 
96
102
  def max_batch_size
97
- @logger.info("max_batch_size: started method")
103
+ #@logger.info("max_batch_size: started method")
98
104
  loop do
99
105
  @mutex.synchronize do
100
106
  return if @stop
@@ -105,7 +111,7 @@ class LogStash::Outputs::EDGE_Loki < LogStash::Outputs::Base
105
111
 
106
112
  @mutex.synchronize do
107
113
  if !add_entry_to_batch(e)
108
- @logger.debug("Max batch_size is reached. Sending batch to loki")
114
+ @logger.debug("Max batch_size is reached. Sending batch to edge-loki")
109
115
  send(@batch)
110
116
  @batch = Batch.new(e)
111
117
  end
@@ -180,8 +186,7 @@ class LogStash::Outputs::EDGE_Loki < LogStash::Outputs::Base
180
186
  opts
181
187
  end
182
188
 
183
- # Add an entry to the current batch returns false if the batch is full
184
- # and the entry can't be added.
189
+ # Add an entry to the current batch returns false if the batch is full and the entry can't be added.
185
190
  def add_entry_to_batch(e)
186
191
  line = e.entry['line']
187
192
  # we don't want to send empty lines.
@@ -223,38 +228,58 @@ class LogStash::Outputs::EDGE_Loki < LogStash::Outputs::Base
223
228
  end
224
229
 
225
230
  def send(batch)
226
- @logger.info("send: started method")
227
- client = createClient()
231
+ #@logger.info("send: started method")
228
232
  payload = batch.to_json
229
- res = loki_http_request(client, payload)
230
- if res.is_a?(Net::HTTPSuccess)
231
- @logger.debug("Successfully pushed data to loki")
233
+ if @proxy_url == ""
234
+ client = createClient()
235
+ else
236
+ client = createClientwithProxy()
237
+ end
238
+ access = getToken(client)
239
+ res = edge_http_request(access, payload)
240
+ if res == "200"
241
+ cntLines = JSON.parse(payload)["streams"][0]["values"].size
242
+ @logger.info("Successfully pushed data to edge_loki")
243
+ @logger.info("Sent #{cntLines} lines to edge-loki")
232
244
  else
233
- @logger.debug("failed payload", :payload => payload)
245
+ @logger.debug("failed payload", :payload => JSON.parse(payload)["streams"][0]["values"])
234
246
  end
235
247
  end
236
248
 
237
- def loki_http_request(client, payload)
238
- @logger.info("loki_http_request: started method")
239
- req = Net::HTTP::Post.new(
240
- @uri.request_uri
241
- )
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
249
+ def createClient()
250
+ #@logger.info("createClient: started method")
251
+ client = OAuth2::Client.new(@client_id, @client_secret, auth_scheme: "basic_auth", site: @tokenurl_domain,:token_url => @tokenurl_endpoint)
252
+ return client
253
+ end
247
254
 
248
- opts = ssl_opts(@uri)
255
+ def createClientwithProxy()
256
+ #@logger.info("createClient: started method")
257
+ conn_opts = {}
258
+ conn_opts = conn_opts.merge('ssl' => {verify: false})
259
+ conn_opts = conn_opts.merge('proxy' => @proxy_url)
260
+ client = OAuth2::Client.new(@client_id, @client_secret, auth_scheme: "basic_auth", site: @tokenurl_domain,:token_url => @tokenurl_endpoint, :connection_opts => conn_opts)
261
+ return client
262
+ end
249
263
 
250
- @logger.debug("sending #{client.body.length} bytes to loki")
264
+ def getToken(client)
265
+ params = {}
266
+ opts = {}
267
+ params = params.merge('scope' => @scopes)
268
+ access = client.client_credentials.get_token(params, opts)
269
+ return access
270
+ end
271
+
272
+ def edge_http_request(token, payload)
273
+ #@logger.info("edge_http_request: started method")
274
+ cntLines = JSON.parse(payload)["streams"][0]["values"].size
275
+ @logger.info("processing #{cntLines} lines to edge-loki")
251
276
  retry_count = 0
252
277
  delay = @min_delay
253
278
  begin
254
- res = Net::HTTP.start(@uri.host, @uri.port, **opts) { |http|
255
- http.request(client)
256
- }
257
- return res if !res.nil? && res.code.to_i != 429 && res.code.to_i.div(100) != 5
279
+ res = token.post(@uri, {:body => payload, :headers => {'Content-Type' => 'application/json'}})
280
+ status_code = "#{res.status}"
281
+ return status_code if !status_code.nil? && status_code.to_i != 429 && status_code.to_i.div(100) != 5
282
+ return res
258
283
  raise StandardError.new res
259
284
  rescue StandardError => e
260
285
  retry_count += 1
@@ -274,13 +299,4 @@ class LogStash::Outputs::EDGE_Loki < LogStash::Outputs::Base
274
299
  end
275
300
  end
276
301
 
277
- def createClient
278
- @logger.info("createClient: started method")
279
- client = OAuth2::Client.new(@client_id, @client_secret, site: @url)
280
- client.auth_code.authorize_url(redirect_uri: @token_url)
281
- @logger.info("createClient: started method", :client => client)
282
- return client
283
- end
284
-
285
302
  end
286
-
@@ -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.10'
4
4
  s.authors = ['Britto Prabhu']
5
5
  s.email = ['britto.prabhu@apmterminals.com']
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
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.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Britto Prabhu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-04 00:00:00.000000000 Z
11
+ date: 2023-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement