fluent-plugin-jfrog-send-metrics 0.1.8 → 0.1.9

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: e81703836698da47723aac87029c37beb200bf98a54302c1c9a9112f3256d393
4
- data.tar.gz: 410485c8e3f8ee9e8181ea31d92fedbd43c50b27d3ac58816c7a3aeef85a4d77
3
+ metadata.gz: 898feff8ab8f4a975854370c16b2d400e16918afe77dbc09e76b930ea62a2c05
4
+ data.tar.gz: 98102867a939e246ba8a688c1afd65853dacb62f0e4df23970ecd0bb5387628a
5
5
  SHA512:
6
- metadata.gz: 2457370d7894ec11e2191c6a1820f9da8c7933f7be8287682c30f117bf89b38c65c1312b38efea4872c1675d0f5599ebc0b619a6f3b0e2ba65b3b9b4aacade03
7
- data.tar.gz: 9d77b96e6443969640c545dbedc239f31ef32214f06e3748bfe2084dc1eb93de0cce6d8a2003593a4c3a44ae28988390d6031eff11905ba9bd024a83ee96ca1c
6
+ metadata.gz: efc92c68d8d5eac16199f54d129ad2786356c8b81a30236a7af5aaff559446e8239f9fb378506d4fa9f1d8b8997067f7b8fe2572ce70c6c4b564c7b0882b2265
7
+ data.tar.gz: 97dad1d675ccb149eaaf3a4d6232e51558221323245eb43acde64147451f056179490d178defd53d223557ce4e3521bc7de12f3a53b5be03c106ee38ed854c81
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-jfrog-send-metrics (0.1.8)
4
+ fluent-plugin-jfrog-send-metrics (0.1.9)
5
5
  fluentd (>= 0.14.10, < 2)
6
6
  rest-client (>= 2.1.0)
7
7
 
@@ -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.8"
6
+ spec.version = "0.1.9"
7
7
  spec.authors = ["MahithaB", "BenH"]
8
8
  spec.email = ["partner_support@jfrog.com"]
9
9
 
@@ -26,24 +26,24 @@ class DatadogMetrics
26
26
  return record
27
27
  end
28
28
 
29
- def send_metrics(ddtags, record, http_proxy, verify_ssl, request_timeout, gzip_compression)
29
+ def send_metrics(ddtags, record, http_proxy, verify_ssl, request_timeout, gzip_compression, logger)
30
30
  # Get the current local timestamp
31
- puts "#{Utility.get_time} Additional tags to be added to metrics are:", ddtags
31
+ logger.info("#{Utility.get_time} Additional tags to be added to metrics are:", ddtags)
32
32
  metrics_data = add_custom_data(ddtags, record)
33
- puts "#{Utility.get_time} Sending received metrics data"
33
+ logger.info("#{Utility.get_time} Sending received metrics data")
34
34
 
35
35
  if http_proxy
36
36
  RestClient.proxy = URI.parse(http_proxy)
37
- puts "#{Utility.get_time} Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}"
37
+ logger.info("#{Utility.get_time} Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}")
38
38
  elsif ENV['HTTP_PROXY']
39
39
  RestClient.proxy = ENV['HTTP_PROXY']
40
- puts "#{Utility.get_time} Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
40
+ logger.info("#{Utility.get_time} Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}")
41
41
  elsif ENV['http_proxy']
42
42
  RestClient.proxy = ENV['http_proxy']
43
- puts "#{Utility.get_time} Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
43
+ logger.info("#{Utility.get_time} Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}")
44
44
  elsif ENV['https_proxy']
45
45
  RestClient.proxy = ENV['https_proxy']
46
- puts "#{Utility.get_time} Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
46
+ logger.info("#{Utility.get_time} Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}")
47
47
  end
48
48
 
49
49
  headers = {
@@ -57,23 +57,24 @@ class DatadogMetrics
57
57
  headers[:'Content-Encoding'] = 'gzip'
58
58
  end
59
59
 
60
- response = RestClient::Request.new(
60
+ request = RestClient::Request.new(
61
61
  method: :post,
62
62
  url: @url,
63
63
  payload: payload,
64
64
  headers: headers,
65
65
  verify_ssl: verify_ssl,
66
66
  timeout: request_timeout
67
- ).execute do |response, request, result|
67
+ )
68
+
69
+ request.execute do |response, request, result|
68
70
  case response.code
69
71
  when 202
70
- puts "#{Utility.get_time} Metrics were successfully sent to DataDog"
72
+ logger.info("#{Utility.get_time} Metrics were successfully sent to DataDog")
71
73
  return response.body
72
74
  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]
75
+ logger.info("#{Utility.get_time} Cannot send metrics to DataDog url: %s. Received response code: %d, Response body: %s" % [@url, response.code, response.body])
74
76
  end
75
77
  end
76
78
  end
77
-
78
79
  end
79
80
 
@@ -10,23 +10,23 @@ class NewRelicMetrics
10
10
  @url = url
11
11
  end
12
12
 
13
- def send_metrics(metrics_data, http_proxy, verify_ssl, request_timeout, gzip_compression)
14
- puts "#{Utility.get_time} Sending received metrics data"
13
+ def send_metrics(metrics_data, http_proxy, verify_ssl, request_timeout, gzip_compression, logger)
14
+ logger.info("#{Utility.get_time} Sending received metrics data")
15
15
  metrics_payload = []
16
16
  metrics_payload.push(JSON.parse(metrics_data.to_json))
17
17
 
18
18
  if http_proxy
19
19
  RestClient.proxy = URI.parse(http_proxy)
20
- puts "#{Utility.get_time} Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}"
20
+ logger.info("#{Utility.get_time} Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}")
21
21
  elsif ENV['HTTP_PROXY']
22
22
  RestClient.proxy = ENV['HTTP_PROXY']
23
- puts "#{Utility.get_time} Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
23
+ logger.info("#{Utility.get_time} Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}")
24
24
  elsif ENV['http_proxy']
25
25
  RestClient.proxy = ENV['http_proxy']
26
- puts "#{Utility.get_time} Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
26
+ logger.info("#{Utility.get_time} Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}")
27
27
  elsif ENV['https_proxy']
28
28
  RestClient.proxy = ENV['https_proxy']
29
- puts "#{Utility.get_time} Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
29
+ logger.info("#{Utility.get_time} Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}")
30
30
  end
31
31
 
32
32
  headers = {
@@ -37,21 +37,23 @@ class NewRelicMetrics
37
37
  payload = Utility.compress_payload(metrics_payload)
38
38
  headers[:'Content-Encoding'] = 'gzip'
39
39
  end
40
-
41
- response = RestClient::Request.new(
40
+
41
+ request = RestClient::Request.new(
42
42
  method: :post,
43
43
  url: @url,
44
44
  payload: payload,
45
45
  headers: headers,
46
46
  verify_ssl: verify_ssl,
47
47
  timeout: request_timeout
48
- ).execute do |response, request, result|
48
+ )
49
+
50
+ request.execute do |response, request, result|
49
51
  case response.code
50
52
  when 202
51
- puts "#{Utility.get_time} Metrics were successfully sent to NewRelic"
53
+ logger.info("#{Utility.get_time} Metrics were successfully sent to NewRelic")
52
54
  return response.body
53
55
  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]
56
+ logger.info("#{Utility.get_time} Cannot send metrics to NewRelic url: %s. Received response code: %d, Response body: %s" % [@url, response.code, response.body])
55
57
  end
56
58
  end
57
59
  end
@@ -40,33 +40,36 @@ module Fluent
40
40
  def configure(conf)
41
41
  super
42
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))
43
+ raise Fluent::ConfigError, 'Must define the target_platform to be one of the following (DATADOG, NEWRELIC).' if @target_platform == '' || !(['DATADOG', 'NEWRELIC'].include?(@target_platform))
44
44
 
45
45
  raise Fluent::ConfigError, 'Must define the apikey to use for authentication.' if @apikey == ''
46
46
  end
47
47
 
48
48
  def process(tag, es)
49
+ logger = log
49
50
  es.each do |time, record|
50
51
  begin
52
+ logger.info("Sending metrics to target platform: #{@target_platform} started")
51
53
  if @target_platform == 'NEWRELIC'
52
54
  vendor = NewRelicMetrics.new(@apikey, @url)
53
- vendor.send_metrics(record, @http_proxy, @verify_ssl, @request_timeout, @gzip_compression)
55
+ vendor.send_metrics(record, @http_proxy, @verify_ssl, @request_timeout, @gzip_compression, logger)
54
56
  elsif @target_platform == 'DATADOG'
55
57
  vendor = DatadogMetrics.new(@apikey, @url)
56
- vendor.send_metrics(@ddtags, record, @http_proxy, @verify_ssl, @request_timeout, @gzip_compression)
58
+ vendor.send_metrics(@ddtags, record, @http_proxy, @verify_ssl, @request_timeout, @gzip_compression, logger)
57
59
  end
60
+ logger.info("Sending metrics to target platform: #{@target_platform} finished")
58
61
  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}"
62
+ logger.info("#{Utility.get_time} The request timed out while trying to open a connection. The configured request timeout is: #{@request_timeout}")
60
63
  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}"
64
+ logger.info("#{Utility.get_time} The request timed out while waiting for a response. The configured request timeout is: #{@request_timeout}")
62
65
  rescue RestClient::Exceptions::RequestTimeout
63
- puts "#{Utility.get_time} The request timed out. The configured request timeout is: #{@request_timeout}"
66
+ logger.info("#{Utility.get_time} The request timed out. The configured request timeout is: #{@request_timeout}")
64
67
  rescue RestClient::ExceptionWithResponse => e
65
- puts "#{Utility.get_time} HTTP request failed: #{e.response}"
68
+ logger.info("#{Utility.get_time} HTTP request failed: #{e.response}")
66
69
  rescue Net::HTTPClientException => e
67
- puts "#{Utility.get_time} An HTTP client error occurred when sending metrics to #{@target_platform}: #{e.message}"
70
+ logger.info("#{Utility.get_time} An HTTP client error occurred when sending metrics to #{@target_platform}: #{e.message}")
68
71
  rescue StandardError => e
69
- puts "#{Utility.get_time} An error occurred when sending metrics to #{@target_platform}: #{e.message}"
72
+ logger.info("#{Utility.get_time} An error occurred when sending metrics to #{@target_platform}: #{e.message}")
70
73
  end
71
74
  end
72
75
  end
@@ -8,7 +8,11 @@ class Utility
8
8
  # Compress the JSON string using zlib's GzipWriter
9
9
  compressed_payload = StringIO.new
10
10
  Zlib::GzipWriter.wrap(compressed_payload) do |gz|
11
- gz.write(json_payload)
11
+ begin
12
+ gz.write(json_payload)
13
+ ensure
14
+ gz.close
15
+ end
12
16
  end
13
17
 
14
18
  # convert the compressed data to a string
@@ -23,4 +27,13 @@ class Utility
23
27
  def self.get_time()
24
28
  return Time.now.strftime("%Y-%m-%d %H:%M:%S")
25
29
  end
30
+
31
+ def self.enable_http_client_logs(http_client_logs)
32
+ if http_client_logs
33
+ RestClient.log = STDOUT
34
+ else
35
+ RestClient.log = nil
36
+ end
37
+ end
38
+
26
39
  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.8
4
+ version: 0.1.9
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-10-24 00:00:00.000000000 Z
12
+ date: 2024-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler