zuora_connect 1.7.03 → 1.7.04

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
  SHA1:
3
- metadata.gz: 043bacd1f74b2e3a3e22d8cffe8f642081b5d265
4
- data.tar.gz: f5cae6cafedaa42f6ed37028d4794b17c858d1f0
3
+ metadata.gz: ed6c65bd36e9061203dd9ea2e55d230ce14bd5b8
4
+ data.tar.gz: 2b5facf174f25a137ab607526bbe5701d1d72706
5
5
  SHA512:
6
- metadata.gz: 2d641103cfb8016b386f8a47e5d75740ad044967ce988264b775d74fa19cb6bf7fd1c36097713c80ab680ee09dab3e429b50cfabcc6b00302eb2cd565a4a8529
7
- data.tar.gz: 0ada5cd7bff5dae2135e6d8871d34df83450e594125030e5cf3a44e3ac34662483a66f649807db57166df7bf01e9c20a29ada8e2500e85afd85863c49d674132
6
+ metadata.gz: e07a270696b0acd4df0bd925f948c3a166eb7aae36dc328f64847472a364030643d2e2674e36e30016f268ffd5496f56e0b1c9ca517db4fe362c2d16f0f8eb58
7
+ data.tar.gz: e3049b0cb2552c5768e9e114f0544d13b3bfd2d73e3bf5d938ae264f7556eb18118acb397f5a98e31995ae72461629185e38fb2c8e1a1379fa77385bd6e5e9a5
@@ -155,8 +155,10 @@ module ZuoraConnect
155
155
 
156
156
  #### START Metrics Mathods ####
157
157
  def self.write_to_telegraf(*args)
158
- @@telegraf_host = ZuoraConnect::Telegraf.new() if @@telegraf_host == nil
159
- return @@telegraf_host.write(*args)
158
+ if ZuoraConnect.configuration.enable_metrics
159
+ @@telegraf_host = ZuoraConnect::Telegraf.new() if @@telegraf_host == nil
160
+ return @@telegraf_host.write(*args)
161
+ end
160
162
  end
161
163
 
162
164
  def self.get_metrics(type)
@@ -2,6 +2,11 @@ module ZuoraConnect
2
2
  class Telegraf
3
3
  attr_accessor :host
4
4
 
5
+ OUTBOUND_METRICS = true
6
+ OUTBOUND_METRICS_NAME = "request-outbound"
7
+ INBOUND_METRICS = true
8
+ INBOUND_METRICS_NAME = "request-inbound"
9
+
5
10
  def initialize
6
11
  self.connect
7
12
  end
@@ -19,21 +24,17 @@ module ZuoraConnect
19
24
  Rails.logger.warn(self.format_metric_log('Telegraf', ex.message))
20
25
  end
21
26
 
22
- def write(direction: 'Default', tags: {}, values: {})
27
+ def write(direction: 'Unknown', tags: {}, values: {})
23
28
  time = Benchmark.measure do |bench|
24
29
  # To avoid writing metrics from rspec tests
25
- if ENV['DEIS_APP'] || true
26
- # Getting the process type
27
- p_type = self.get_process_type
30
+ if Rails.env.to_sym != :test
28
31
  app_instance = Thread.current[:appinstance].present? ? Thread.current[:appinstance].id : 0
29
- tags = tags.merge({ app_name: ZuoraConnect.configuration.app_name, process_type: p_type, app_instance: app_instance})
32
+ tags = tags.merge({ app_name: app_name, process_type: process_type, app_instance: app_instance})
30
33
 
31
- if direction == :inbound && ZuoraConnect.configuration.enable_inbound_metrics_flag
32
- series = ZuoraConnect.configuration.influxdb_series_name_inbound
33
- self.write_udp(series: series, tags: tags, values: values)
34
- elsif direction == :outbound && ZuoraConnect.configuration.enable_outbound_metrics_flag
35
- series = ZuoraConnect.configuration.influxdb_series_name_outbound
36
- self.write_udp(series: series, tags: tags, values: values)
34
+ if direction == :inbound
35
+ self.write_udp(series: INBOUND_METRICS_NAME, tags: tags, values: values) if INBOUND_METRICS
36
+ elsif direction == :outbound
37
+ self.write_udp(series: OUTBOUND_METRICS_NAME, tags: tags, values: values) if OUTBOUND_METRICS
37
38
  else
38
39
  self.write_udp(series: direction, tags: tags, values: values)
39
40
  end
@@ -58,8 +59,12 @@ module ZuoraConnect
58
59
  Rails.logger.warn(self.format_metric_log('Telegraf', ex.message))
59
60
  end
60
61
 
62
+ def app_name
63
+ return ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
64
+ end
65
+
61
66
  # Returns the process type if any
62
- def get_process_type
67
+ def process_type
63
68
  p_type = 'Unknown'
64
69
  if ENV['HOSTNAME'] && ENV['DEIS_APP']
65
70
  temp = ENV['HOSTNAME'].split(ENV['DEIS_APP'])[1]
@@ -6,30 +6,28 @@ module Middleware
6
6
 
7
7
  # This method is triggered when a non error page is loaded (not 404)
8
8
  def call(name, started, finished, unique_id, payload)
9
- if ZuoraConnect.configuration.enable_inbound_metrics_flag == true
10
- # If the url contains any css or JavaScript files then do not collect metrics for them
11
- return nil if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| payload[:path].include?(word) }
12
-
13
- # Getting the endpoint and the content_type
14
- content_hash = {:html => "text/html", :js => "application/javascript", :json => "application/json"}
15
- content_type = content_hash.key?(payload[:format]) ? content_hash[payload[:format]] : payload[:format]
16
-
17
- # payloads with 500 requests do not have status as it is not set by the controller
18
- # https://github.com/rails/rails/issues/33335
19
- #status_code = payload[:status] ? payload[:status] : payload[:exception_object].present? ? 500 : ""
20
- if payload[:exception].present?
21
- status_code, exception = [500, payload[:exception].first]
22
- else
23
- status_code, exception = [payload[:status], nil]
24
- end
9
+ # If the url contains any css or JavaScript files then do not collect metrics for them
10
+ return nil if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| payload[:path].include?(word) }
11
+
12
+ # Getting the endpoint and the content_type
13
+ content_hash = {:html => "text/html", :js => "application/javascript", :json => "application/json"}
14
+ content_type = content_hash.key?(payload[:format]) ? content_hash[payload[:format]] : payload[:format]
15
+
16
+ # payloads with 500 requests do not have status as it is not set by the controller
17
+ # https://github.com/rails/rails/issues/33335
18
+ #status_code = payload[:status] ? payload[:status] : payload[:exception_object].present? ? 500 : ""
19
+ if payload[:exception].present?
20
+ status_code, exception = [500, payload[:exception].first]
21
+ else
22
+ status_code, exception = [payload[:status], nil]
23
+ end
25
24
 
26
- tags = {method: payload[:method], status: status_code, error_type: exception, content_type: content_type, controller: payload[:controller], action: payload[:action]}.compact
25
+ tags = {method: payload[:method], status: status_code, error_type: exception, content_type: content_type, controller: payload[:controller], action: payload[:action]}.compact
27
26
 
28
- values = {view_time: payload[:view_runtime], db_time: payload[:db_runtime], response_time: ((finished-started)*1000)}.compact
29
- values = values.map{ |k,v| [k,v.round(2)]}.to_h
27
+ values = {view_time: payload[:view_runtime], db_time: payload[:db_runtime], response_time: ((finished-started)*1000)}.compact
28
+ values = values.map{ |k,v| [k,v.round(2)]}.to_h
30
29
 
31
- ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
32
- end
30
+ ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
33
31
  end
34
32
  end
35
33
 
@@ -46,61 +44,59 @@ module Middleware
46
44
  start_time = Time.now
47
45
  @status, @headers, @response = @app.call(env)
48
46
 
49
- if ZuoraConnect.configuration.enable_inbound_metrics_flag == true
50
- # If the url contains any CSS or JavaScript files then do not collect metrics for them
51
- return [@status, @headers, @response] if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| env['PATH_INFO'].include?(word) }
52
-
53
- if defined? Prometheus
54
- #Prometheus Stuff
55
- if env['PATH_INFO'] == '/connect/internal/metrics'
47
+ # If the url contains any CSS or JavaScript files then do not collect metrics for them
48
+ return [@status, @headers, @response] if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| env['PATH_INFO'].include?(word) }
56
49
 
57
- #Do something before each scrape
58
- if defined? Resque.redis
50
+ if defined? Prometheus
51
+ #Prometheus Stuff
52
+ if env['PATH_INFO'] == '/connect/internal/metrics'
59
53
 
60
- app_name = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
61
- begin
54
+ #Do something before each scrape
55
+ if defined? Resque.redis
62
56
 
63
- Resque.redis.ping
57
+ app_name = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
58
+ begin
64
59
 
65
- Prometheus::REDIS_CONNECTION.set({connection:'redis',name:app_name},1)
66
- Prometheus::FINISHED_JOBS.set({type:'resque',name:app_name},Resque.info[:processed])
67
- Prometheus::PENDING_JOBS.set({type:'resque',name:app_name},Resque.info[:pending])
68
- Prometheus::ACTIVE_WORKERS.set({type:'resque',name:app_name},Resque.info[:working])
69
- Prometheus::WORKERS.set({type:'resque',name:app_name},Resque.info[:workers])
70
- Prometheus::FAILED_JOBS.set({type:'resque',name:app_name},Resque.info[:failed])
60
+ Resque.redis.ping
71
61
 
72
- rescue Redis::CannotConnectError
73
- Prometheus::REDIS_CONNECTION.set({connection:'redis',name:app_name},0)
74
- end
62
+ Prometheus::REDIS_CONNECTION.set({connection:'redis',name:app_name},1)
63
+ Prometheus::FINISHED_JOBS.set({type:'resque',name:app_name},Resque.info[:processed])
64
+ Prometheus::PENDING_JOBS.set({type:'resque',name:app_name},Resque.info[:pending])
65
+ Prometheus::ACTIVE_WORKERS.set({type:'resque',name:app_name},Resque.info[:working])
66
+ Prometheus::WORKERS.set({type:'resque',name:app_name},Resque.info[:workers])
67
+ Prometheus::FAILED_JOBS.set({type:'resque',name:app_name},Resque.info[:failed])
75
68
 
76
- if ZuoraConnect.configuration.custom_prometheus_update_block != nil
77
- ZuoraConnect.configuration.custom_prometheus_update_block.call()
78
- end
69
+ rescue Redis::CannotConnectError
70
+ Prometheus::REDIS_CONNECTION.set({connection:'redis',name:app_name},0)
79
71
  end
80
72
 
73
+ if ZuoraConnect.configuration.custom_prometheus_update_block != nil
74
+ ZuoraConnect.configuration.custom_prometheus_update_block.call()
75
+ end
81
76
  end
77
+
82
78
  end
79
+ end
83
80
 
84
- # Uncomment following block of code for handling engine requests/requests without controller
85
- # else
86
- # # Handling requests which do not have controllers (engines)
87
- if env["SCRIPT_NAME"].present?
88
- controller_path = "#{env['SCRIPT_NAME'][1..-1]}"
89
- controller_path = controller_path.sub("/", "::")
90
- request_path = "#{controller_path}#UnknownAction"
91
- else
92
- # Writing to telegraf: Handle 404
93
- if [404].include?(@status)
94
- content_type = @headers['Content-Type'].split(';')[0] if @headers['Content-Type']
95
-
96
- tags = {status: @status, content_type: content_type}
97
-
98
- tags = tags.merge({controller: 'ActionController', action: 'RoutingError' })
99
-
100
- values = {response_time: ((Time.now - start_time)*1000).round(2) }
101
-
102
- ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
103
- end
81
+ # Uncomment following block of code for handling engine requests/requests without controller
82
+ # else
83
+ # # Handling requests which do not have controllers (engines)
84
+ if env["SCRIPT_NAME"].present?
85
+ controller_path = "#{env['SCRIPT_NAME'][1..-1]}"
86
+ controller_path = controller_path.sub("/", "::")
87
+ request_path = "#{controller_path}#UnknownAction"
88
+ else
89
+ # Writing to telegraf: Handle 404
90
+ if [404].include?(@status)
91
+ content_type = @headers['Content-Type'].split(';')[0] if @headers['Content-Type']
92
+
93
+ tags = {status: @status, content_type: content_type}
94
+
95
+ tags = tags.merge({controller: 'ActionController', action: 'RoutingError' })
96
+
97
+ values = {response_time: ((Time.now - start_time)*1000).round(2) }
98
+
99
+ ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
104
100
  end
105
101
  end
106
102
  [@status, @headers, @response]
@@ -3,7 +3,7 @@ module ZuoraConnect
3
3
 
4
4
  attr_accessor :default_locale, :default_time_zone, :url, :mode, :delayed_job,:private_key, :additional_apartment_models
5
5
 
6
- attr_accessor :telegraf_endpoint, :telegraf_debug, :enable_inbound_metrics_flag, :enable_outbound_metrics_flag, :custom_prometheus_update_block, :app_name, :influxdb_series_name_inbound, :influxdb_series_name_outbound
6
+ attr_accessor :enable_metrics, :telegraf_endpoint, :telegraf_debug, :custom_prometheus_update_block
7
7
 
8
8
  attr_accessor :oauth_client_id, :oauth_client_secret, :oauth_client_redirect_uri
9
9
 
@@ -20,14 +20,9 @@ module ZuoraConnect
20
20
 
21
21
 
22
22
  # Setting the app name for telegraf write
23
+ @enable_metrics = false
23
24
  @telegraf_endpoint = 'udp://telegraf-app-metrics.monitoring.svc.cluster.local:8094'
24
25
  @telegraf_debug = false
25
- @enable_inbound_metrics_flag = false
26
- @enable_outbound_metrics_flag = false
27
- @influxdb_series_name_inbound = "request-inbound"
28
- @influxdb_series_name_outbound = "request-outbound"
29
-
30
- @app_name = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
31
26
 
32
27
  # OAuth Settings
33
28
  @oauth_client_id = ""
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "1.7.03"
2
+ VERSION = "1.7.04"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.03
4
+ version: 1.7.04
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-31 00:00:00.000000000 Z
11
+ date: 2018-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment