fluent-plugin-jfrog-send-metrics 0.1.3 → 0.1.5

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: 10a4ee75d92bb898f8398e2e8c83e30682c350bb94772d2e8a73606a48b28deb
4
- data.tar.gz: 2a4261471690052c20d9c95acdb0c9f5bc61747b4850eba3d6e69487cb667844
3
+ metadata.gz: 01dd0aba88ecd2c738d0a44cd8692c61544ab76472b7e92ca7d2bded0a8cf683
4
+ data.tar.gz: 246352647868467d91d88dbe8cda0ce65ed411757f3d86e2fe1bcc9053391662
5
5
  SHA512:
6
- metadata.gz: a3d2b6f84468d2047bbe9b51c3dfafba49a32d88b6b5906713a84892f849ee565295a3d4eb718c991757d24256f4f5a4e430abe3c8a068553d4ec76b287c48d6
7
- data.tar.gz: b68ea4050bc6613f3ee28406802359f4da2294a00b06981af21a39e67ddc409a9832be1f8184cf4bd0b3130c83ad6742708bdccd22159eb114de9b56d06b5b4e
6
+ metadata.gz: 8eab565fd17b0a554e12633860b0d8c87a0efdc61b423c19f8b1df80dd2d343169594f73d790efd247b3d4427ef66af293e57e4bc97b212822b77b9cd50c62b7
7
+ data.tar.gz: 23a1a59d51b8bf2752770a25df3b2d4f7cf24000cfdc89a59dac1684398d49405614dc80c448ad97fcf6870c2b51991527f5b6a5779d283b8760de9117ea2243
data/Gemfile.lock CHANGED
@@ -1,26 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-jfrog-send-metrics (0.1.3)
4
+ fluent-plugin-jfrog-send-metrics (0.1.5)
5
5
  fluentd (>= 0.14.10, < 2)
6
- rest-client (~> 2.0)
6
+ rest-client (~> 2.1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  ansi (1.5.0)
12
+ base64 (0.2.0)
12
13
  builder (3.2.4)
13
- concurrent-ruby (1.2.2)
14
- cool.io (1.7.1)
14
+ concurrent-ruby (1.3.4)
15
+ cool.io (1.8.1)
16
+ csv (3.3.0)
15
17
  domain_name (0.5.20190701)
16
18
  unf (>= 0.0.5, < 1.0.0)
17
- fluentd (1.16.1)
19
+ drb (2.2.1)
20
+ fluentd (1.17.0)
21
+ base64 (~> 0.2)
18
22
  bundler
19
23
  cool.io (>= 1.4.5, < 2.0.0)
24
+ csv (~> 3.2)
25
+ drb (~> 2.2)
20
26
  http_parser.rb (>= 0.5.1, < 0.9.0)
21
27
  msgpack (>= 1.3.1, < 2.0.0)
22
28
  serverengine (>= 2.3.2, < 3.0.0)
23
- sigdump (~> 0.2.2)
29
+ sigdump (~> 0.2.5)
24
30
  strptime (>= 0.2.4, < 1.0.0)
25
31
  tzinfo (>= 1.0, < 3.0)
26
32
  tzinfo-data (~> 1.0)
@@ -39,7 +45,7 @@ GEM
39
45
  builder
40
46
  minitest (>= 5.0)
41
47
  ruby-progressbar
42
- msgpack (1.7.1)
48
+ msgpack (1.7.2)
43
49
  netrc (0.11.0)
44
50
  power_assert (2.0.1)
45
51
  rake (12.3.3)
@@ -51,13 +57,13 @@ GEM
51
57
  ruby-progressbar (1.11.0)
52
58
  serverengine (2.3.2)
53
59
  sigdump (~> 0.2.2)
54
- sigdump (0.2.4)
60
+ sigdump (0.2.5)
55
61
  strptime (0.2.5)
56
62
  test-unit (3.5.3)
57
63
  power_assert
58
64
  tzinfo (2.0.6)
59
65
  concurrent-ruby (~> 1.0)
60
- tzinfo-data (1.2023.3)
66
+ tzinfo-data (1.2024.1)
61
67
  tzinfo (>= 1.0.0)
62
68
  unf (0.1.4)
63
69
  unf_ext
data/README.md CHANGED
@@ -64,20 +64,24 @@ Configure the match directive parameters as specified below
64
64
  ```
65
65
  <match jfrog.metrics.**>
66
66
  @type jfrog_send_metrics
67
- target_platform "NEWRELIC"
67
+ target_platform "NEWRELIC" # or "DATADOG"
68
68
  apikey <api_key>
69
+ url https://metric-api.newrelic.com/metric/v1 # or DataDog's metrics URL
70
+ http_proxy <proxy_url>
69
71
  </match>
70
-
71
72
  ```
73
+
72
74
  #### Configuration parameters
73
75
 
74
76
  Obtain respective authentication credentials for log-vendors
75
77
 
76
78
  * **target_platform**(string)(required): The target log-vendor ("NEWRELIC" or "DATADOG")
77
79
  * **apikey**(string)(required): APIKEY is the apikey of log-vendor for authentication(LicenseKey for NewRelic)
80
+ * **url**(string)(required): Metrics url of the mertics-vendor (Metrics URL for NewRelic or DataDog)
81
+ * **http_proxy**(string)(optional): Proxy server URL - which will proxy http/s calls to your observability vendor (DataDog/NewRelic)
78
82
 
79
83
  ## Copyright
80
84
 
81
- * Copyright(c) 2022- MahithaB
85
+ * Copyright(c) 2024- MahithaB, BenH
82
86
  * License
83
87
  * Apache License, Version 2.0
@@ -3,9 +3,9 @@ $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.3"
7
- spec.authors = ["MahithaB"]
8
- spec.email = ["60710901+MahithaB@users.noreply.github.com"]
6
+ spec.version = "0.1.5"
7
+ spec.authors = ["MahithaB", "BenH"]
8
+ spec.email = ["partner_support@jfrog.com"]
9
9
 
10
10
  spec.summary = %q{Fluentd Plugin for sending metrics to the respective log-vendor}
11
11
  spec.description = %q{Fluentd Plugin for sending metrics to the respective log-vendor}
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "test-unit", "~> 3.0"
26
26
  spec.add_development_dependency "rest-client", "~> 2.0"
27
27
  spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
28
- spec.add_runtime_dependency "rest-client", "~> 2.0"
28
+ spec.add_runtime_dependency "rest-client", "~> 2.1.0"
29
29
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'json'
3
3
  require 'rest-client'
4
+ require 'uri'
4
5
 
5
6
  class DatadogMetrics
6
7
  def initialize(apikey, url)
@@ -8,20 +9,61 @@ class DatadogMetrics
8
9
  @url = url
9
10
  end
10
11
 
11
- def send_metrics(metrics_data)
12
+ def add_custom_data(ddtags, record)
13
+ if ddtags.length() > 0
14
+ record_series = record['series']
15
+ data_array = []
16
+ record_series.each do |interim_data|
17
+ interim_data['tags'] ||= []
18
+ interim_data['tags'].push(*ddtags)
19
+ data_array << interim_data
20
+ end
21
+ record['series'] = data_array
22
+ return record
23
+ end
24
+ return record
25
+ end
26
+
27
+ def send_metrics(ddtags, http_proxy, record)
28
+ puts "Additional tags to be added to metrics are", ddtags
29
+ metrics_data = add_custom_data(ddtags, record)
12
30
  puts "Sending received metrics data"
13
- response = RestClient::Request.new(
14
- method: :post,
15
- url: @url,
16
- payload: metrics_data.to_json,
17
- headers: {'DD-API-KEY': @apikey, content_type: :json }
18
- ).execute do |response, request, result|
19
- case response.code
20
- when 202
21
- return response.body
22
- else
23
- puts 'Cannot send metrics to Datadog', response.body
31
+
32
+ if http_proxy
33
+ RestClient.proxy = URI.parse(http_proxy)
34
+ puts "Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}"
35
+ elsif ENV['HTTP_PROXY']
36
+ RestClient.proxy = ENV['HTTP_PROXY']
37
+ puts "Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
38
+ elsif ENV['http_proxy']
39
+ RestClient.proxy = ENV['http_proxy']
40
+ puts "Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
41
+ elsif ENV['https_proxy']
42
+ RestClient.proxy = ENV['https_proxy']
43
+ puts "Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
44
+ end
45
+
46
+ begin
47
+ response = RestClient::Request.new(
48
+ method: :post,
49
+ url: @url,
50
+ payload: metrics_payload.to_json,
51
+ headers: {params: {'Api-Key' => @apikey}}
52
+ ).execute do |response, request, result|
53
+ case response.code
54
+ when 202
55
+ puts 'Metrics were successfully sent to DataDog'
56
+ return response.body
57
+ else
58
+ puts "Cannot send metrics to DataDog. Received response code: %d" % [response&.code]
59
+ end
24
60
  end
61
+ rescue Net::HTTPClientException => e
62
+ # Handle the HTTP client exception
63
+ puts "An HTTP client error occurred when calling DataDog metrics: #{e.message}"
64
+ rescue StandardError => e
65
+ # Handle any other exceptions
66
+ puts "An error occurred when sending metrics to DataDog: #{e.message}"
25
67
  end
26
68
  end
27
69
  end
@@ -8,22 +8,46 @@ class NewRelicMetrics
8
8
  @url = url
9
9
  end
10
10
 
11
- def send_metrics(metrics_data)
11
+ def send_metrics(metrics_data, http_proxy)
12
12
  puts "Sending received metrics data"
13
13
  metrics_payload = []
14
14
  metrics_payload.push(JSON.parse(metrics_data.to_json))
15
- response = RestClient::Request.new(
16
- method: :post,
17
- url: @url,
18
- payload: metrics_payload.to_json,
19
- headers: {params: {'Api-Key' => @apikey}}
20
- ).execute do |response, request, result|
21
- case response.code
22
- when 202
23
- return response.body
24
- else
25
- puts 'Cannot send metrics to NewRelic'
15
+
16
+ if http_proxy
17
+ RestClient.proxy = URI.parse(http_proxy)
18
+ puts "Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}"
19
+ elsif ENV['HTTP_PROXY']
20
+ RestClient.proxy = ENV['HTTP_PROXY']
21
+ puts "Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
22
+ elsif ENV['http_proxy']
23
+ RestClient.proxy = ENV['http_proxy']
24
+ puts "Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
25
+ elsif ENV['https_proxy']
26
+ RestClient.proxy = ENV['https_proxy']
27
+ puts "Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
28
+ end
29
+
30
+ begin
31
+ response = RestClient::Request.new(
32
+ method: :post,
33
+ url: @url,
34
+ payload: metrics_payload.to_json,
35
+ headers: {params: {'Api-Key' => @apikey}}
36
+ ).execute do |response, request, result|
37
+ case response.code
38
+ when 202
39
+ puts 'Metrics were successfully sent to NewRelic'
40
+ return response.body
41
+ else
42
+ puts "Cannot send metrics to NewRelic. Received response code: %d" % [response&.code]
43
+ end
26
44
  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}"
27
51
  end
28
52
  end
29
53
  end
@@ -28,6 +28,8 @@ module Fluent
28
28
  config_param :target_platform, :string, default: ''
29
29
  config_param :apikey, :string, default: ''
30
30
  config_param :url, :string, default: 'https://metric-api.newrelic.com/metric/v1'
31
+ config_param :ddtags, :array, default: []
32
+ config_param :http_proxy, :string, :default => nil
31
33
 
32
34
  # `configure` is called before `start`.
33
35
  # 'conf' is a `Hash` that includes the configuration parameters.
@@ -37,17 +39,16 @@ module Fluent
37
39
  raise Fluent::ConfigError, 'Must define the vendor to use for getting the metrics.' if @target_platform == ''
38
40
 
39
41
  raise Fluent::ConfigError, 'Must define the apikey to use for authentication.' if @apikey == ''
40
-
41
42
  end
42
43
 
43
44
  def process(tag, es)
44
45
  es.each do |time, record|
45
46
  if @target_platform == 'NEWRELIC'
46
47
  vendor = NewRelicMetrics.new(@apikey, @url)
47
- vendor.send_metrics(record)
48
+ vendor.send_metrics(record, @http_proxy)
48
49
  elsif @target_platform == 'DATADOG'
49
50
  vendor = DatadogMetrics.new(@apikey, @url)
50
- vendor.send_metrics(record)
51
+ vendor.send_metrics(@ddtags, @http_proxy, record)
51
52
  end
52
53
  end
53
54
  end
@@ -15,7 +15,7 @@ class JfrogSendMetricsOutputTest < Test::Unit::TestCase
15
15
  # Default configuration for tests
16
16
  CONFIG = %(
17
17
  target_platform "NEWRELIC"
18
- apikey ""
18
+ apikey "apiKey"
19
19
  url "https://metric-api.newrelic.com/metric/v1"
20
20
  )
21
21
 
metadata CHANGED
@@ -1,14 +1,15 @@
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.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - MahithaB
8
+ - BenH
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2023-06-14 00:00:00.000000000 Z
12
+ date: 2024-08-16 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -92,17 +93,17 @@ dependencies:
92
93
  requirements:
93
94
  - - "~>"
94
95
  - !ruby/object:Gem::Version
95
- version: '2.0'
96
+ version: 2.1.0
96
97
  type: :runtime
97
98
  prerelease: false
98
99
  version_requirements: !ruby/object:Gem::Requirement
99
100
  requirements:
100
101
  - - "~>"
101
102
  - !ruby/object:Gem::Version
102
- version: '2.0'
103
+ version: 2.1.0
103
104
  description: Fluentd Plugin for sending metrics to the respective log-vendor
104
105
  email:
105
- - 60710901+MahithaB@users.noreply.github.com
106
+ - partner_support@jfrog.com
106
107
  executables: []
107
108
  extensions: []
108
109
  extra_rdoc_files: []
@@ -143,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
144
  - !ruby/object:Gem::Version
144
145
  version: '0'
145
146
  requirements: []
146
- rubygems_version: 3.1.6
147
+ rubygems_version: 3.5.3
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: Fluentd Plugin for sending metrics to the respective log-vendor