fluent-plugin-jfrog-metrics 0.2.10 → 0.2.11

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: cb8dfdd51ee10875ad7d6ec7c539a92ebc703061e4bc87aa407229ebb1b97898
4
+ data.tar.gz: b5f7c2a0121c9100a579f6ce61d5845ae6058656f06031d06dbc4800a7b8bfe3
5
5
  SHA512:
6
- metadata.gz: 5543013d5ff07db5c6046d1aed46383f80f3eb709e4344703c9dcef736716b05be80feea657c5be7ed399c24e6c446011e8a14e44ebdccd6566fd0c220f2285c
7
- data.tar.gz: f44be96345b2c7dfee24b9f95a21ce0db4c49724180bd66d8af7ae8d2e5611a1244acc9c7e20820fcb7d3326595170062f28ebb3b8e3cb8d348a931beee4d998
6
+ metadata.gz: a7fca5a309cb9c334116019c7914456870f31aa1ca8adcadb8803932327bea1a0d8ecfd6cd4f36346b6c3904dc83c795618877a2ceca8a78bcd4ae3a6d3ab667
7
+ data.tar.gz: 8ed3af580a9cea432a5a66983c5c87e2c28b46134f3772e4fdc9b712bdd55ca75ea4ca8247cd2bdbbf426a13e6982d4dee69151ab96b39d7f8f55dd040749c1e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-jfrog-metrics (0.2.10)
4
+ fluent-plugin-jfrog-metrics (0.2.11)
5
5
  fluentd (>= 0.14.10, < 2)
6
6
  rest-client (~> 2.1.0)
7
7
 
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.11'
7
7
  spec.authors = ['MahithaB, BenHarosh']
8
8
  spec.email = ['cpe-support@jfrog.com']
9
9
 
@@ -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,7 +37,6 @@ 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'
@@ -65,11 +63,17 @@ module Fluent
65
63
  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
64
  end
67
65
 
66
+ def initialize
67
+ super
68
+ end
69
+
68
70
  # `start` is called when starting and after `configure` is successfully completed.
69
71
  def start
70
72
  super
71
73
  @running = true
72
- @thread = Thread.new(&method(:run))
74
+ @thread = Thread.new do
75
+ run(log)
76
+ end
73
77
  end
74
78
 
75
79
  def shutdown
@@ -78,27 +82,28 @@ module Fluent
78
82
  super
79
83
  end
80
84
 
81
- 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
85
+ def run(logger)
86
+ logger.info("Preparing metrics collection, creating timer task")
87
+ timer_task = Concurrent::TimerTask.new(execution_interval: @execution_interval, run_now: true) do
88
+ logger.info("Timer task execution started")
89
+ do_execute(logger)
90
+ logger.info("Timer task execution finished")
86
91
  end
87
92
  timer_task.execute
88
93
  sleep 100
89
94
  end
90
95
 
91
- def do_execute
96
+ def do_execute(logger)
92
97
  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)
98
+ logger.info("Metrics collection started")
99
+ metrics_helper = MetricsHelper.new(logger, @metric_prefix, @jpd_url, @username, @apikey, @token, @common_jpd, @verify_ssl, @request_timeout)
95
100
  platform_metrics = metrics_helper.get_metrics
96
101
 
97
102
  additional_metrics = metrics_helper.get_additional_metrics
98
103
  if !additional_metrics.nil? && additional_metrics != ''
99
104
  platform_metrics += additional_metrics.to_s
100
105
  end
101
- puts "#{Utility.get_time} Metrics collection finished"
106
+ logger.info("Metrics collection finished")
102
107
 
103
108
  if @target_platform == 'SPLUNK'
104
109
  parser = SplunkMetricsParser.new(@metric_prefix, router, @tag)
@@ -109,19 +114,23 @@ module Fluent
109
114
  else
110
115
  raise 'Parser Type is not valid. target_platform Should be SPLUNK or NEWRELIC or DATADOG'
111
116
  end
117
+ logger.debug("Emitting collected metrics started")
112
118
  parser.emit_parsed_metrics(platform_metrics)
119
+ logger.debug("Emitting collected metrics finished")
113
120
 
114
121
  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}"
122
+ logger.info("The request timed out while trying to open a connection. The configured request timeout is: #{@request_timeout}")
116
123
  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}"
124
+ logger.info("The request timed out while waiting for a response. The configured request timeout is: #{@request_timeout}")
118
125
  rescue RestClient::Exceptions::RequestTimeout
119
- puts "#{Utility.get_time} The request timed out. The configured request timeout is: #{@request_timeout}"
126
+ logger.info("The request timed out. The configured request timeout is: #{@request_timeout}")
120
127
  rescue RestClient::ExceptionWithResponse => e
121
- puts "#{Utility.get_time} HTTP request failed: #{e.response}"
128
+ logger.info("HTTP request failed: #{e.response}")
122
129
  rescue StandardError => e
123
- puts "#{Utility.get_time} An unexpected error occurred: #{e.message}"
124
- end
130
+ logger.info("An unexpected error occurred during metrics collection: #{e.message}")
131
+ else
132
+ logger.debug("Metrics collection and emission do_execute finished with no errors")
133
+ end
125
134
  end
126
135
  end
127
136
  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.11
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
@@ -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