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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed6c65bd36e9061203dd9ea2e55d230ce14bd5b8
|
4
|
+
data.tar.gz: 2b5facf174f25a137ab607526bbe5701d1d72706
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
159
|
-
|
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: '
|
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
|
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:
|
32
|
+
tags = tags.merge({ app_name: app_name, process_type: process_type, app_instance: app_instance})
|
30
33
|
|
31
|
-
if direction == :inbound
|
32
|
-
series
|
33
|
-
|
34
|
-
|
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
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
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
|
-
|
50
|
-
|
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
|
-
|
58
|
-
|
50
|
+
if defined? Prometheus
|
51
|
+
#Prometheus Stuff
|
52
|
+
if env['PATH_INFO'] == '/connect/internal/metrics'
|
59
53
|
|
60
|
-
|
61
|
-
|
54
|
+
#Do something before each scrape
|
55
|
+
if defined? Resque.redis
|
62
56
|
|
63
|
-
|
57
|
+
app_name = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
|
58
|
+
begin
|
64
59
|
|
65
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
77
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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 :
|
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 = ""
|
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.
|
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-
|
11
|
+
date: 2018-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apartment
|