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 +4 -4
- data/lib/logstash/outputs/edge_loki.rb +63 -47
- data/logstash-output-edge_loki.gemspec +1 -1
- 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: 459c97179f8e5871f7992ce20df5ba1ef2dc95ec0959eecbb1dbfda58c2dd81c
|
4
|
+
data.tar.gz: 672e5fc63bb488cd69fe6522cd210235fd6824d7677a713b45e16d8adc7864ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =>
|
24
|
-
config :client_secret, :validate => :string, secret: true, :required =>
|
23
|
+
config :client_id, :validate => :string, :required => true
|
24
|
+
config :client_secret, :validate => :string, secret: true, :required => true
|
25
25
|
|
26
|
-
## '
|
27
|
-
config :
|
28
|
-
config :key, :validate => :path, :required => false
|
26
|
+
## 'Loki Token URL Domain'
|
27
|
+
config :tokenurl_domain, :validate => :string, :required => true
|
29
28
|
|
30
|
-
## '
|
31
|
-
config :
|
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
|
-
## '
|
37
|
-
config :
|
41
|
+
## 'Client certificate'
|
42
|
+
config :cert, :validate => :path, :required => false
|
43
|
+
config :key, :validate => :path, :required => false
|
38
44
|
|
39
|
-
## '
|
40
|
-
config :
|
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
|
-
|
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
|
-
|
227
|
-
client = createClient()
|
231
|
+
#@logger.info("send: started method")
|
228
232
|
payload = batch.to_json
|
229
|
-
|
230
|
-
|
231
|
-
|
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
|
238
|
-
|
239
|
-
|
240
|
-
|
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
|
-
|
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
|
-
|
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 =
|
255
|
-
|
256
|
-
|
257
|
-
return res
|
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
|
-
|
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.
|
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-
|
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
|