fluent-plugin-jfrog-send-metrics 0.1.6 → 0.1.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 +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +8 -1
- data/fluent-plugin-jfrog-send-metrics.gemspec +2 -2
- data/lib/fluent/plugin/datadog_metrics_sender.rb +32 -23
- data/lib/fluent/plugin/newrelic_metrics_sender.rb +32 -26
- data/lib/fluent/plugin/out_jfrog_send_metrics.rb +25 -7
- data/lib/fluent/plugin/utility.rb +26 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e81703836698da47723aac87029c37beb200bf98a54302c1c9a9112f3256d393
|
4
|
+
data.tar.gz: 410485c8e3f8ee9e8181ea31d92fedbd43c50b27d3ac58816c7a3aeef85a4d77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2457370d7894ec11e2191c6a1820f9da8c7933f7be8287682c30f117bf89b38c65c1312b38efea4872c1675d0f5599ebc0b619a6f3b0e2ba65b3b9b4aacade03
|
7
|
+
data.tar.gz: 9d77b96e6443969640c545dbedc239f31ef32214f06e3748bfe2084dc1eb93de0cce6d8a2003593a4c3a44ae28988390d6031eff11905ba9bd024a83ee96ca1c
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fluent-plugin-jfrog-send-metrics (0.1.
|
4
|
+
fluent-plugin-jfrog-send-metrics (0.1.8)
|
5
5
|
fluentd (>= 0.14.10, < 2)
|
6
|
-
rest-client (
|
6
|
+
rest-client (>= 2.1.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -49,7 +49,7 @@ GEM
|
|
49
49
|
netrc (0.11.0)
|
50
50
|
power_assert (2.0.1)
|
51
51
|
rake (12.3.3)
|
52
|
-
rest-client (2.1.0)
|
52
|
+
rest-client (>= 2.1.0)
|
53
53
|
http-accept (>= 1.7.0, < 2.0)
|
54
54
|
http-cookie (>= 1.0.2, < 2.0)
|
55
55
|
mime-types (>= 1.16, < 4.0)
|
data/README.md
CHANGED
@@ -79,9 +79,16 @@ Obtain respective authentication credentials for log-vendors
|
|
79
79
|
* **apikey**(string)(required): APIKEY is the apikey of log-vendor for authentication(LicenseKey for NewRelic)
|
80
80
|
* **url**(string)(required): Metrics url of the mertics-vendor (Metrics URL for NewRelic or DataDog)
|
81
81
|
* **http_proxy**(string)(optional): Proxy server URL - which will proxy http/s calls to your observability vendor (DataDog/NewRelic)
|
82
|
+
* **verify_ssl** (true / false) (optional): This flag should be set as false in order to bypass client's ssl certificate verification. When false, sets ssl_opts['verify_ssl'] to OpenSSL::SSL::VERIFY_NONE. Otherwise, sets ssl_opts['verify_ssl'] to OpenSSL::SSL::VERIFY_PEER
|
83
|
+
* Default value: true
|
84
|
+
* **gzip_compression** (true / false) (optional): This flag should be set as true for compressing (gzip) the metrics payload on outbound posts. This parameter is set to false by default for backwards compatibility.
|
85
|
+
* Default value: false
|
86
|
+
* **request_timeout** (integer) (optional): Http request timeout when calling Artifactory/Xray to pull new events (http client)
|
87
|
+
* Default value: `20`
|
82
88
|
|
83
89
|
## Copyright
|
84
90
|
|
85
|
-
* Copyright(c) 2024-
|
91
|
+
* Copyright(c) 2024 - JFrog
|
92
|
+
* Maintainers - MahithaB, BenHarosh
|
86
93
|
* License
|
87
94
|
* Apache License, Version 2.0
|
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "fluent-plugin-jfrog-send-metrics"
|
6
|
-
spec.version = "0.1.
|
6
|
+
spec.version = "0.1.8"
|
7
7
|
spec.authors = ["MahithaB", "BenH"]
|
8
8
|
spec.email = ["partner_support@jfrog.com"]
|
9
9
|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "> 1.14"
|
24
24
|
spec.add_development_dependency "rake", "~> 12.0"
|
25
25
|
spec.add_development_dependency "test-unit", "~> 3.0"
|
26
|
-
spec.add_development_dependency "rest-client", "~> 2.0"
|
26
|
+
spec.add_development_dependency "rest-client", "~> 2.1.0"
|
27
27
|
spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
|
28
28
|
spec.add_runtime_dependency "rest-client", "~> 2.1.0"
|
29
29
|
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
require 'json'
|
3
3
|
require 'rest-client'
|
4
4
|
require 'uri'
|
5
|
+
require 'stringio'
|
6
|
+
require_relative 'utility'
|
5
7
|
|
6
8
|
class DatadogMetrics
|
7
9
|
def initialize(apikey, url)
|
@@ -24,47 +26,54 @@ class DatadogMetrics
|
|
24
26
|
return record
|
25
27
|
end
|
26
28
|
|
27
|
-
def send_metrics(ddtags, record, http_proxy)
|
28
|
-
|
29
|
+
def send_metrics(ddtags, record, http_proxy, verify_ssl, request_timeout, gzip_compression)
|
30
|
+
# Get the current local timestamp
|
31
|
+
puts "#{Utility.get_time} Additional tags to be added to metrics are:", ddtags
|
29
32
|
metrics_data = add_custom_data(ddtags, record)
|
30
|
-
puts "Sending received metrics data"
|
33
|
+
puts "#{Utility.get_time} Sending received metrics data"
|
31
34
|
|
32
35
|
if http_proxy
|
33
36
|
RestClient.proxy = URI.parse(http_proxy)
|
34
|
-
puts "Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}"
|
37
|
+
puts "#{Utility.get_time} Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}"
|
35
38
|
elsif ENV['HTTP_PROXY']
|
36
39
|
RestClient.proxy = ENV['HTTP_PROXY']
|
37
|
-
puts "Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
40
|
+
puts "#{Utility.get_time} Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
38
41
|
elsif ENV['http_proxy']
|
39
42
|
RestClient.proxy = ENV['http_proxy']
|
40
|
-
puts "Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
43
|
+
puts "#{Utility.get_time} Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
41
44
|
elsif ENV['https_proxy']
|
42
45
|
RestClient.proxy = ENV['https_proxy']
|
43
|
-
puts "Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
46
|
+
puts "#{Utility.get_time} Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
44
47
|
end
|
45
48
|
|
46
|
-
|
49
|
+
headers = {
|
50
|
+
'DD-API-KEY': @apikey,
|
51
|
+
content_type: :json
|
52
|
+
}
|
53
|
+
|
54
|
+
payload = metrics_data.to_json
|
55
|
+
if gzip_compression
|
56
|
+
payload = Utility.compress_payload(metrics_data)
|
57
|
+
headers[:'Content-Encoding'] = 'gzip'
|
58
|
+
end
|
59
|
+
|
47
60
|
response = RestClient::Request.new(
|
48
61
|
method: :post,
|
49
62
|
url: @url,
|
50
|
-
payload:
|
51
|
-
headers:
|
63
|
+
payload: payload,
|
64
|
+
headers: headers,
|
65
|
+
verify_ssl: verify_ssl,
|
66
|
+
timeout: request_timeout
|
52
67
|
).execute do |response, request, result|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
68
|
+
case response.code
|
69
|
+
when 202
|
70
|
+
puts "#{Utility.get_time} Metrics were successfully sent to DataDog"
|
71
|
+
return response.body
|
72
|
+
else
|
73
|
+
puts "#{Utility.get_time} Cannot send metrics to DataDog url: %s. Received response code: %d, Response body: %s" % [@url, response.code, response.body]
|
60
74
|
end
|
61
|
-
rescue Net::HTTPClientException => e
|
62
|
-
# Handle the HTTP client exception
|
63
|
-
puts "An HTTP client error occurred when sending metrics to DataDog: #{e.message}"
|
64
|
-
rescue StandardError => e
|
65
|
-
# Handle any other exceptions
|
66
|
-
puts "An error occurred when sending metrics to DataDog: #{e.message}"
|
67
75
|
end
|
68
76
|
end
|
77
|
+
|
69
78
|
end
|
70
79
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'json'
|
3
3
|
require 'rest-client'
|
4
|
+
require 'stringio'
|
5
|
+
require_relative 'utility'
|
4
6
|
|
5
7
|
class NewRelicMetrics
|
6
8
|
def initialize(apikey, url)
|
@@ -8,46 +10,50 @@ class NewRelicMetrics
|
|
8
10
|
@url = url
|
9
11
|
end
|
10
12
|
|
11
|
-
def send_metrics(metrics_data, http_proxy)
|
12
|
-
puts "Sending received metrics data"
|
13
|
+
def send_metrics(metrics_data, http_proxy, verify_ssl, request_timeout, gzip_compression)
|
14
|
+
puts "#{Utility.get_time} Sending received metrics data"
|
13
15
|
metrics_payload = []
|
14
16
|
metrics_payload.push(JSON.parse(metrics_data.to_json))
|
15
17
|
|
16
18
|
if http_proxy
|
17
19
|
RestClient.proxy = URI.parse(http_proxy)
|
18
|
-
puts "Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}"
|
20
|
+
puts "#{Utility.get_time} Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}"
|
19
21
|
elsif ENV['HTTP_PROXY']
|
20
22
|
RestClient.proxy = ENV['HTTP_PROXY']
|
21
|
-
puts "Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
23
|
+
puts "#{Utility.get_time} Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
22
24
|
elsif ENV['http_proxy']
|
23
25
|
RestClient.proxy = ENV['http_proxy']
|
24
|
-
puts "Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
26
|
+
puts "#{Utility.get_time} Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
25
27
|
elsif ENV['https_proxy']
|
26
28
|
RestClient.proxy = ENV['https_proxy']
|
27
|
-
puts "Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
29
|
+
puts "#{Utility.get_time} Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
headers = {
|
33
|
+
params: {'Api-Key' => @apikey}
|
34
|
+
}
|
35
|
+
payload = metrics_payload.to_json
|
36
|
+
if gzip_compression
|
37
|
+
payload = Utility.compress_payload(metrics_payload)
|
38
|
+
headers[:'Content-Encoding'] = 'gzip'
|
39
|
+
end
|
40
|
+
|
41
|
+
response = RestClient::Request.new(
|
42
|
+
method: :post,
|
43
|
+
url: @url,
|
44
|
+
payload: payload,
|
45
|
+
headers: headers,
|
46
|
+
verify_ssl: verify_ssl,
|
47
|
+
timeout: request_timeout
|
48
|
+
).execute do |response, request, result|
|
49
|
+
case response.code
|
50
|
+
when 202
|
51
|
+
puts "#{Utility.get_time} Metrics were successfully sent to NewRelic"
|
52
|
+
return response.body
|
53
|
+
else
|
54
|
+
puts "#{Utility.get_time} Cannot send metrics to NewRelic url: %s. Received response code: %d, Response body: %s" % [@url, response.code, response.body]
|
44
55
|
end
|
45
|
-
rescue Net::HTTPClientException => e
|
46
|
-
# Handle the HTTP client exception
|
47
|
-
puts "An HTTP client error occurred when sending metrics to NewRelic: #{e.message}"
|
48
|
-
rescue StandardError => e
|
49
|
-
# Handle any other exceptions
|
50
|
-
puts "An error occurred when sending metrics to NewRelic: #{e.message}"
|
51
56
|
end
|
52
57
|
end
|
53
58
|
end
|
59
|
+
|
@@ -30,25 +30,43 @@ module Fluent
|
|
30
30
|
config_param :url, :string, default: 'https://metric-api.newrelic.com/metric/v1'
|
31
31
|
config_param :ddtags, :array, default: []
|
32
32
|
config_param :http_proxy, :string, :default => nil
|
33
|
+
config_param :verify_ssl, :bool, default: true
|
34
|
+
config_param :request_timeout, :time, default: 20
|
35
|
+
config_param :gzip_compression, :bool, default: false
|
33
36
|
|
34
37
|
# `configure` is called before `start`.
|
35
38
|
# 'conf' is a `Hash` that includes the configuration parameters.
|
36
39
|
# If the configuration is invalid, raise `Fluent::ConfigError`.
|
37
40
|
def configure(conf)
|
38
41
|
super
|
39
|
-
|
42
|
+
|
43
|
+
raise Fluent::ConfigError, 'Must define the target_platform to be one of the following (DATADOG, NEWRELIC, SPLUNK).' if @target_platform == '' || !(['DATADOG', 'NEWRELIC'].include?(@target_platform))
|
40
44
|
|
41
45
|
raise Fluent::ConfigError, 'Must define the apikey to use for authentication.' if @apikey == ''
|
42
46
|
end
|
43
47
|
|
44
48
|
def process(tag, es)
|
45
49
|
es.each do |time, record|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
begin
|
51
|
+
if @target_platform == 'NEWRELIC'
|
52
|
+
vendor = NewRelicMetrics.new(@apikey, @url)
|
53
|
+
vendor.send_metrics(record, @http_proxy, @verify_ssl, @request_timeout, @gzip_compression)
|
54
|
+
elsif @target_platform == 'DATADOG'
|
55
|
+
vendor = DatadogMetrics.new(@apikey, @url)
|
56
|
+
vendor.send_metrics(@ddtags, record, @http_proxy, @verify_ssl, @request_timeout, @gzip_compression)
|
57
|
+
end
|
58
|
+
rescue RestClient::Exceptions::OpenTimeout
|
59
|
+
puts "#{Utility.get_time} The request timed out while trying to open a connection. The configured request timeout is: #{@request_timeout}"
|
60
|
+
rescue RestClient::Exceptions::ReadTimeout
|
61
|
+
puts "#{Utility.get_time} The request timed out while waiting for a response. The configured request timeout is: #{@request_timeout}"
|
62
|
+
rescue RestClient::Exceptions::RequestTimeout
|
63
|
+
puts "#{Utility.get_time} The request timed out. The configured request timeout is: #{@request_timeout}"
|
64
|
+
rescue RestClient::ExceptionWithResponse => e
|
65
|
+
puts "#{Utility.get_time} HTTP request failed: #{e.response}"
|
66
|
+
rescue Net::HTTPClientException => e
|
67
|
+
puts "#{Utility.get_time} An HTTP client error occurred when sending metrics to #{@target_platform}: #{e.message}"
|
68
|
+
rescue StandardError => e
|
69
|
+
puts "#{Utility.get_time} An error occurred when sending metrics to #{@target_platform}: #{e.message}"
|
52
70
|
end
|
53
71
|
end
|
54
72
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
|
3
|
+
class Utility
|
4
|
+
def self.compress_payload(payload)
|
5
|
+
puts "#{self.get_time} Compressing metrics payload"
|
6
|
+
json_payload = payload.to_json
|
7
|
+
|
8
|
+
# Compress the JSON string using zlib's GzipWriter
|
9
|
+
compressed_payload = StringIO.new
|
10
|
+
Zlib::GzipWriter.wrap(compressed_payload) do |gz|
|
11
|
+
gz.write(json_payload)
|
12
|
+
end
|
13
|
+
|
14
|
+
# convert the compressed data to a string
|
15
|
+
compressed_data = compressed_payload.string
|
16
|
+
|
17
|
+
puts "#{self.get_time} Original metrics payload size: #{json_payload.bytesize} bytes"
|
18
|
+
puts "#{self.get_time} Compressed metrics payload size: #{compressed_data.bytesize} bytes"
|
19
|
+
|
20
|
+
return compressed_data
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get_time()
|
24
|
+
return Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-jfrog-send-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MahithaB
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -59,14 +59,14 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: 2.1.0
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 2.1.0
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: fluentd
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/fluent/plugin/datadog_metrics_sender.rb
|
119
119
|
- lib/fluent/plugin/newrelic_metrics_sender.rb
|
120
120
|
- lib/fluent/plugin/out_jfrog_send_metrics.rb
|
121
|
+
- lib/fluent/plugin/utility.rb
|
121
122
|
- spec/fixtures/files/creds.rb
|
122
123
|
- spec/fixtures/files/sample_artifactory_newrelic_metrics.txt
|
123
124
|
- spec/fixtures/files/sample_xray_newrelic_metrics.txt
|