fluent-plugin-jfrog-metrics 0.2.10 → 0.2.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9376678b3169e51397b9d705e3fe663dc869af24cfb6003622bdd4b7609f269
4
- data.tar.gz: 2119039f822220595e995d88b417fe9f43b0cdaa9b783959feb9ce349bc9615b
3
+ metadata.gz: 28f317687267209cdc5e43c874fa40503c6ab86d970ec1509ff1d3e1af7cf26f
4
+ data.tar.gz: 4ab7a27eeee244cb9b497c2d4d3b97553049ba859cdbda3b194c7cf4d81b3cdf
5
5
  SHA512:
6
- metadata.gz: 5543013d5ff07db5c6046d1aed46383f80f3eb709e4344703c9dcef736716b05be80feea657c5be7ed399c24e6c446011e8a14e44ebdccd6566fd0c220f2285c
7
- data.tar.gz: f44be96345b2c7dfee24b9f95a21ce0db4c49724180bd66d8af7ae8d2e5611a1244acc9c7e20820fcb7d3326595170062f28ebb3b8e3cb8d348a931beee4d998
6
+ metadata.gz: ebd57e01c5255ec2bd69201919c05069d90cb9847653cc8b620b89034e75bce2f06fe378897f0756f2c6aee257ae463ea32a1ccdc17b9ee7fd0f89a88eabdab2
7
+ data.tar.gz: 30a48056fda84ab46678855b9fa84270c6618518c5835e7ae3b853d3a27fd6dd8ee8b5dab907c00fd84c83a59e6bfaf551fec8ca3a8447fd0741f5a3a8656aa8
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-jfrog-metrics (0.2.10)
4
+ fluent-plugin-jfrog-metrics (0.2.12)
5
5
  fluentd (>= 0.14.10, < 2)
6
- rest-client (~> 2.1.0)
6
+ rest-client (>= 2.1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -88,8 +88,6 @@ Integration is done by setting up Xray. Obtain JPD url and access token for API.
88
88
  - **metric_prefix** (string) (required): This values pulls the specific metrics. Values can be - jfrog.artifactory, jfrog.xray
89
89
  - **execution_interval** (integer) (optional): Wait interval between pulling new events (scheduler)
90
90
  - Default value: `60`
91
- - **timeout_interval** (integer) (optional): Timeout interval for pulling new events (scheduler)
92
- - Default value: `60`
93
91
  - **request_timeout** (integer) (optional): Http request timeout when calling Artifactory/Xray to pull new events (http client)
94
92
  - Default value: `20`
95
93
  - **common_jpd** (true / false) (optional): This flag should be set as true only for non-kubernetes installations or installations where JPD base URL is same to access both Artifactory and Xray,
@@ -101,7 +99,6 @@ Integration is done by setting up Xray. Obtain JPD url and access token for API.
101
99
  - Default value: true
102
100
 
103
101
  Note:
104
-
105
102
  - For Artifactory v7.4 and below only API Key must be used,
106
103
  - For Artifactory v7.4 to 7.46 either Token or API Key can be used,
107
104
  - For Artifactory v7.47 and above token only must be used.
@@ -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-metrics'
6
- spec.version = '0.2.10'
6
+ spec.version = '0.2.12'
7
7
  spec.authors = ['MahithaB, BenHarosh']
8
8
  spec.email = ['cpe-support@jfrog.com']
9
9
 
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'bundler', '~> 1.14'
25
25
  spec.add_development_dependency 'rake', '~> 12.0'
26
26
  spec.add_development_dependency 'test-unit', '~> 3.0'
27
- spec.add_development_dependency "rest-client", "~> 2.1.0"
27
+ spec.add_development_dependency "rest-client", ">= 2.1.0"
28
28
  spec.add_runtime_dependency 'fluentd', ['>= 0.14.10', '< 2']
29
- spec.add_runtime_dependency "rest-client", "~> 2.1.0"
29
+ spec.add_runtime_dependency "rest-client", ">= 2.1.0"
30
30
  end
@@ -22,7 +22,6 @@ require_relative 'metrics_helper'
22
22
  require_relative 'newrelic_metrics_parser'
23
23
  require_relative 'splunk_metrics_parser'
24
24
  require_relative 'datadog_metrics_parser'
25
- require_relative 'utility'
26
25
 
27
26
  module Fluent
28
27
  module Plugin
@@ -38,13 +37,14 @@ module Fluent
38
37
  config_param :apikey, :string, default: '', :secret => true
39
38
  config_param :token, :string, default: '', :secret => true
40
39
  config_param :execution_interval, :time, default: 60
41
- config_param :timeout_interval, :time, default: 60
42
40
  config_param :request_timeout, :time, default: 20
43
41
  config_param :metric_prefix, :string, default: ''
44
42
  config_param :target_platform, :string, default: 'SPLUNK'
45
43
  config_param :common_jpd, :bool, default: false
46
44
  config_param :verify_ssl, :bool, default: true
47
45
 
46
+ $logger = nil
47
+
48
48
  # `configure` is called before `start`.
49
49
  # 'conf' is a `Hash` that includes the configuration parameters.
50
50
  # If the configuration is invalid, raise `Fluent::ConfigError`.
@@ -65,11 +65,18 @@ module Fluent
65
65
  raise Fluent::ConfigError, 'Must define the target_platform to be fone of the following (DATADOG, NEWRELIC, SPLUNK).' if !(['DATADOG', 'NEWRELIC', 'SPLUNK'].include?(@target_platform))
66
66
  end
67
67
 
68
+ def initialize
69
+ super
70
+ end
71
+
68
72
  # `start` is called when starting and after `configure` is successfully completed.
69
73
  def start
70
74
  super
71
75
  @running = true
72
- @thread = Thread.new(&method(:run))
76
+ $logger = log
77
+ @thread = Thread.new do
78
+ run
79
+ end
73
80
  end
74
81
 
75
82
  def shutdown
@@ -79,26 +86,33 @@ module Fluent
79
86
  end
80
87
 
81
88
  def run
82
- puts "#{Utility.get_time} Preparing metrics collection, creating timer task"
83
- timer_task = Concurrent::TimerTask.new(execution_interval: @execution_interval, timeout_interval: @timeout_interval, run_now: true) do
84
- puts "#{Utility.get_time} Timer task execution"
85
- do_execute
89
+ $logger.info("Preparing metrics collection, creating timer task")
90
+ timer_task = Concurrent::TimerTask.new(execution_interval: @execution_interval, run_now: true) do
91
+ begin
92
+ $logger.info("Timer task execution started")
93
+ do_execute
94
+ next "Timer task execution finished successfully"
95
+ rescue => e
96
+ $logger.error("Error occurred when running Timer task: #{e.message}")
97
+ raise e
98
+ end
86
99
  end
100
+ timer_task.add_observer(TaskObserver.new)
87
101
  timer_task.execute
88
102
  sleep 100
89
103
  end
90
104
 
91
105
  def do_execute
92
106
  begin
93
- puts "#{Utility.get_time} Metrics collection started"
94
- metrics_helper = MetricsHelper.new(@metric_prefix, @jpd_url, @username, @apikey, @token, @common_jpd, @verify_ssl, @request_timeout)
107
+ $logger.info("Metrics collection started")
108
+ metrics_helper = MetricsHelper.new($logger, @metric_prefix, @jpd_url, @username, @apikey, @token, @common_jpd, @verify_ssl, @request_timeout)
95
109
  platform_metrics = metrics_helper.get_metrics
96
110
 
97
111
  additional_metrics = metrics_helper.get_additional_metrics
98
112
  if !additional_metrics.nil? && additional_metrics != ''
99
113
  platform_metrics += additional_metrics.to_s
100
114
  end
101
- puts "#{Utility.get_time} Metrics collection finished"
115
+ $logger.info("Metrics collection finished")
102
116
 
103
117
  if @target_platform == 'SPLUNK'
104
118
  parser = SplunkMetricsParser.new(@metric_prefix, router, @tag)
@@ -109,19 +123,33 @@ module Fluent
109
123
  else
110
124
  raise 'Parser Type is not valid. target_platform Should be SPLUNK or NEWRELIC or DATADOG'
111
125
  end
126
+ $logger.debug("Emitting collected metrics started")
112
127
  parser.emit_parsed_metrics(platform_metrics)
128
+ $logger.debug("Emitting collected metrics finished")
113
129
 
114
130
  rescue RestClient::Exceptions::OpenTimeout
115
- puts "#{Utility.get_time} The request timed out while trying to open a connection. The configured request timeout is: #{@request_timeout}"
131
+ $logger.info("The request timed out while trying to open a connection. The configured request timeout is: #{@request_timeout}")
116
132
  rescue RestClient::Exceptions::ReadTimeout
117
- puts "#{Utility.get_time} The request timed out while waiting for a response. The configured request timeout is: #{@request_timeout}"
133
+ $logger.info("The request timed out while waiting for a response. The configured request timeout is: #{@request_timeout}")
118
134
  rescue RestClient::Exceptions::RequestTimeout
119
- puts "#{Utility.get_time} The request timed out. The configured request timeout is: #{@request_timeout}"
135
+ $logger.info("The request timed out. The configured request timeout is: #{@request_timeout}")
120
136
  rescue RestClient::ExceptionWithResponse => e
121
- puts "#{Utility.get_time} HTTP request failed: #{e.response}"
137
+ $logger.info("HTTP request failed: #{e.response}")
122
138
  rescue StandardError => e
123
- puts "#{Utility.get_time} An unexpected error occurred: #{e.message}"
124
- end
139
+ $logger.info("An unexpected error occurred during metrics collection: #{e.message}")
140
+ else
141
+ $logger.debug("Metrics collection and emission do_execute finished with no errors")
142
+ end
143
+ end
144
+
145
+ class TaskObserver
146
+ def update(time, result, e)
147
+ if result
148
+ $logger.info("Timer task Execution successfully returned: '#{result}' at: #{time}")
149
+ else
150
+ $logger.error("Timer task Execution failed with error: #{e} at: #{time}")
151
+ end
152
+ end
125
153
  end
126
154
  end
127
155
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rest-client'
4
- require_relative 'utility'
5
4
 
6
5
  class MetricsHelper
7
6
  @@obs_endpoint_exists = false
8
7
 
9
- def initialize(metric_prefix, jpd_url, username, apikey, token, common_jpd, verify_ssl, request_timeout)
8
+ def initialize(logger, metric_prefix, jpd_url, username, apikey, token, common_jpd, verify_ssl, request_timeout)
9
+ @logger = logger
10
10
  @metric_prefix = metric_prefix
11
11
  @jpd_url = jpd_url
12
12
  @username = username
@@ -18,6 +18,7 @@ class MetricsHelper
18
18
  end
19
19
 
20
20
  def get_metrics
21
+ @logger.debug("Get metrics started")
21
22
  url = nil
22
23
  url = case @metric_prefix
23
24
  when 'jfrog.artifactory'
@@ -27,72 +28,80 @@ class MetricsHelper
27
28
  else
28
29
  "#{@jpd_url}/artifactory/api/v1/metrics"
29
30
  end
30
-
31
- puts "#{Utility.get_time} Executing #{@metric_prefix} metrics collection from: #{url}"
31
+
32
+ @logger.info("Executing #{@metric_prefix} metrics collection from: #{url}")
32
33
  if !@token.nil? && @token != ''
33
34
  execute_rest_call(url, @username, nil, @token, true, @verify_ssl, @request_timeout)
34
35
  elsif !@apikey.nil? && @apikey != ''
35
36
  execute_rest_call(url, @username, @apikey, nil, false, @verify_ssl, @request_timeout)
36
37
  end
37
-
38
+ @logger.debug("Get metrics finished")
38
39
  end
39
40
 
40
41
  def get_additional_metrics
41
- puts "#{Utility.get_time} Aadditional metrics collection started"
42
+ @logger.info("Aadditional metrics collection started")
42
43
  if (@metric_prefix == 'jfrog.artifactory' || @common_jpd == false) && !@token.nil? && @token != ''
43
44
  url = "#{@jpd_url}/observability/api/v1/metrics"
44
- puts "#{Utility.get_time} Collecting additional metrics from: #{url}"
45
+ @logger.info("Collecting additional metrics from: #{url}")
45
46
  check_endpoint(url, @token, @verify_ssl, @request_timeout) if @@obs_endpoint_exists == nil? || !@@obs_endpoint_exists
46
47
  execute_rest_call(url, @username, nil, @token, true, @verify_ssl, @request_timeout) if @@obs_endpoint_exists
47
48
  end
49
+ @logger.info("Aadditional metrics collection finished")
48
50
  end
49
51
 
50
52
  def check_endpoint(url, token, verify_ssl, request_timeout)
51
- puts "#{Utility.get_time} Checking connectivity to endpoint: #{url}"
52
- response = RestClient::Request.new(
53
+ @logger.debug("Checking connectivity to endpoint: #{url} started")
54
+ request = RestClient::Request.new(
53
55
  method: :get,
54
56
  url: url,
55
57
  headers: { Authorization: "Bearer #{token}"},
56
58
  verify_ssl: verify_ssl,
57
59
  timeout: request_timeout
58
- ).execute do |response, request, result|
60
+ )
61
+
62
+ request.execute do |response, request, result|
59
63
  if response.code == 200
60
64
  @@obs_endpoint_exists = true
61
- puts "#{Utility.get_time} #{url} exists: #{@@obs_endpoint_exists}. Storing the result for next executions"
65
+ @logger.info("#{url} exists: #{@@obs_endpoint_exists}. Storing the result for next executions")
62
66
  else
63
67
  @@obs_endpoint_exists = false
64
- puts "#{Utility.get_time} Cannot verify endpoint. Skipping metrics collection from #{url}. Received response code: #{response.code}, Response body:\n#{response.body}"
68
+ @logger.info("Cannot verify endpoint. Skipping metrics collection from #{url}. Received response code: #{response.code}, Response body:\n#{response.body}")
65
69
  end
66
70
  end
71
+ @logger.debug("Checking connectivity to endpoint: #{url} finished")
67
72
  end
68
73
 
69
74
  def execute_rest_call(url, user, password, token, use_token, verify_ssl, request_timeout)
75
+ @logger.debug("Rest call to fetch metrics started")
70
76
  request = if use_token == true
77
+ @logger.debug("Using token for authentication")
71
78
  RestClient::Request.new(
72
79
  method: :get,
73
80
  url: url,
74
81
  headers: { Authorization: "Bearer #{token}" },
75
82
  verify_ssl: verify_ssl,
76
- timeout: request_timeout
83
+ timeout: request_timeout
77
84
  )
78
85
  else
86
+ @logger.debug("Using apiKey for authentication")
79
87
  RestClient::Request.new(
80
88
  method: :get,
81
89
  url: url,
82
90
  user: user,
83
91
  password: password,
84
92
  verify_ssl: verify_ssl,
85
- timeout: request_timeout,
93
+ timeout: request_timeout
86
94
  )
87
95
  end
88
-
96
+
89
97
  request.execute do |response, request, result|
98
+ @logger.debug("Recieved response body: #{response.body} when fetching metrics")
90
99
  case response.code
91
100
  when 200
92
- puts "#{Utility.get_time} #{@metric_prefix} metrics were successfully collected from url: #{url}"
101
+ @logger.info("#{@metric_prefix} metrics were successfully collected from url: #{url}")
93
102
  return response.body
94
103
  else
95
- puts "#{Utility.get_time} Cannot fetch #{@metric_prefix} metrics from url: #{url}. Received response code: #{response.code}, Response body:\n#{response.body}"
104
+ @logger.info("Cannot fetch #{@metric_prefix} metrics from url: #{url}. Received response code: #{response.code}, Response body:\n#{response.body}")
96
105
  raise "Unexpected response code: #{response.code} when calling #{url}"
97
106
  end
98
107
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-jfrog-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - MahithaB, BenHarosh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-01 00:00:00.000000000 Z
11
+ date: 2024-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,14 +56,14 @@ dependencies:
56
56
  name: rest-client
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.1.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.1.0
69
69
  - !ruby/object:Gem::Dependency
@@ -90,14 +90,14 @@ dependencies:
90
90
  name: rest-client
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - "~>"
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: 2.1.0
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - "~>"
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: 2.1.0
103
103
  description: Fluentd Plugin for converting JFrog Artifactory, Xray generated metrics
@@ -123,7 +123,6 @@ files:
123
123
  - lib/fluent/plugin/metrics_helper.rb
124
124
  - lib/fluent/plugin/newrelic_metrics_parser.rb
125
125
  - lib/fluent/plugin/splunk_metrics_parser.rb
126
- - lib/fluent/plugin/utility.rb
127
126
  - spec/fixtures/files/creds.rb
128
127
  - spec/fixtures/files/sample_artifactory_metrics.txt
129
128
  - spec/fixtures/files/sample_xray_metrics.txt
@@ -1,7 +0,0 @@
1
- class Utility
2
- # one place to control time format for logginggit
3
- def self.get_time()
4
- return Time.now.strftime("%Y-%m-%d %H:%M:%S")
5
- end
6
-
7
- end