zuora_connect 1.5.40t → 1.5.40
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/zuora_connect/static_controller.rb +2 -9
- data/app/models/zuora_connect/app_instance_base.rb +4 -148
- data/config/routes.rb +0 -1
- data/lib/zuora_connect.rb +1 -9
- data/lib/zuora_connect/configuration.rb +1 -13
- data/lib/zuora_connect/controllers/helpers.rb +3 -5
- data/lib/zuora_connect/railtie.rb +0 -22
- data/lib/zuora_connect/version.rb +1 -1
- metadata +6 -36
- data/config/initializers/prometheus.rb +0 -39
- data/lib/middleware/metrics_middleware.rb +0 -110
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c7121413b5f1a0613786c3de3c859c9a174c340
|
4
|
+
data.tar.gz: 53249355807a2420ede58402a161828c912da299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3395cacd984c09bb2dc5f14f28ff1423d79d4e0cf80a05ac70f5934013d205d5efc216754b5b9d2d1c03a0b61c849e9dc4252e9ecfd12371dcb97721db676a12
|
7
|
+
data.tar.gz: 5b030d3b12c511cd5ec14fad87545e2e4fe43019c42c4d353a483aef2a2aa2f1509298f9e5db399b54d385f77b42667725634206d7eec381c969e1bc46b6f721
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module ZuoraConnect
|
2
2
|
class StaticController < ApplicationController
|
3
|
-
before_filter :authenticate_connect_app_request, :except => [:
|
4
|
-
after_filter :persist_connect_app_session, :except => [:
|
5
|
-
|
3
|
+
before_filter :authenticate_connect_app_request, :except => [:health, :session_error, :invalid_app_instance_error]
|
4
|
+
after_filter :persist_connect_app_session, :except => [:health, :session_error, :invalid_app_instance_error]
|
6
5
|
def session_error
|
7
6
|
respond_to do |format|
|
8
7
|
format.html
|
@@ -17,17 +16,11 @@ module ZuoraConnect
|
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
def metrics
|
21
|
-
type = params[:type].present? ? params[:type] : "versions"
|
22
|
-
render json: ZuoraConnect::AppInstanceBase.get_metrics(type), status: 200
|
23
|
-
end
|
24
|
-
|
25
19
|
def health
|
26
20
|
render json: {
|
27
21
|
message: "Alive",
|
28
22
|
status: 200
|
29
23
|
}, status: 200
|
30
24
|
end
|
31
|
-
|
32
25
|
end
|
33
26
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module ZuoraConnect
|
2
|
-
require "uri"
|
3
2
|
class AppInstanceBase < ActiveRecord::Base
|
4
3
|
default_scope {select(ZuoraConnect::AppInstance.column_names.delete_if {|x| ["catalog_mapping", "catalog"].include?(x) }) }
|
5
4
|
after_initialize :init
|
@@ -25,109 +24,6 @@ module ZuoraConnect
|
|
25
24
|
self.apartment_switch(nil, true)
|
26
25
|
end
|
27
26
|
|
28
|
-
|
29
|
-
# Methods for writing Telegraf metrics
|
30
|
-
|
31
|
-
# Returns the process type if any
|
32
|
-
def self.get_process_type
|
33
|
-
p_type = nil
|
34
|
-
if ENV['HOSTNAME'] && ENV['DEIS_APP']
|
35
|
-
temp = ENV['HOSTNAME'].split(ENV['DEIS_APP'])[1]
|
36
|
-
temp = temp.split(/(-[0-9a-zA-Z]{5})$/)[0] # remove the 5 char hash
|
37
|
-
p_type = temp[1, temp.rindex("-")-1]
|
38
|
-
end
|
39
|
-
return p_type
|
40
|
-
end
|
41
|
-
|
42
|
-
# Write to telegraf
|
43
|
-
def self.write_to_telegraf(endpoint_name: nil, method_name: nil, status_code: nil, response_time: nil, db_runtime: nil, view_runtime: nil, content_type: nil, direction: nil, error_type: nil, app_instance: nil, function_name: nil)
|
44
|
-
|
45
|
-
# To avoid writing metrics from rspec tests
|
46
|
-
if ENV['DEIS_APP']
|
47
|
-
# Getting the process type
|
48
|
-
p_type = ZuoraConnect::AppInstanceBase.get_process_type
|
49
|
-
|
50
|
-
if direction == "inbound"
|
51
|
-
Thread.current[:appinstance].present? ? app_instance = Thread.current[:appinstance].id : app_instance = 0
|
52
|
-
|
53
|
-
# Separately handling 200 and non 200 as influx does not accept nil as a value
|
54
|
-
if db_runtime && view_runtime
|
55
|
-
# 200 requests
|
56
|
-
begin
|
57
|
-
ZuoraConnect.configuration.telegraf_client.write(ZuoraConnect.configuration.influxdb_series_name_inbound,
|
58
|
-
tags: {"app_name": "#{ZuoraConnect.configuration.app_name}", "controller_action": endpoint_name, "content-type": content_type, method: method_name, status: status_code, process_type: p_type, "app_instance": app_instance},
|
59
|
-
values: {response_time: response_time, db_time: db_runtime, view_time: view_runtime})
|
60
|
-
rescue => e
|
61
|
-
raise e
|
62
|
-
end
|
63
|
-
else
|
64
|
-
# non 200 requests
|
65
|
-
begin
|
66
|
-
ZuoraConnect.configuration.telegraf_client.write(ZuoraConnect.configuration.influxdb_series_name_inbound,
|
67
|
-
tags: {"app_name": "#{ZuoraConnect.configuration.app_name}", "controller_action": endpoint_name, "content-type": content_type, method: method_name, status: status_code, process_type: p_type, "app_instance": app_instance},
|
68
|
-
values: {response_time: response_time})
|
69
|
-
rescue=> e
|
70
|
-
raise e
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
elsif direction == "outbound"
|
75
|
-
# if there is an error
|
76
|
-
if error_type
|
77
|
-
begin
|
78
|
-
ZuoraConnect.configuration.telegraf_client.write(ZuoraConnect.configuration.influxdb_series_name_outbound,
|
79
|
-
tags: {"app_name": "#{ZuoraConnect.configuration.app_name}", endpoint: endpoint_name, status: status_code, process_type: p_type, "app_instance": app_instance, "function_name": function_name, method: method_name, "error_type": error_type},
|
80
|
-
values: {response_time: response_time})
|
81
|
-
rescue => e
|
82
|
-
raise e
|
83
|
-
end
|
84
|
-
else
|
85
|
-
begin
|
86
|
-
ZuoraConnect.configuration.telegraf_client.write(ZuoraConnect.configuration.influxdb_series_name_outbound,
|
87
|
-
tags: {"app_name": "#{ZuoraConnect.configuration.app_name}", endpoint: endpoint_name, status: status_code, process_type: p_type, "app_instance": app_instance, "function_name": function_name, method: method_name},
|
88
|
-
values: {response_time: response_time})
|
89
|
-
rescue => e
|
90
|
-
raise e
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.get_metrics(type)
|
98
|
-
namespace = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
|
99
|
-
|
100
|
-
data = {}
|
101
|
-
|
102
|
-
if type == "versions"
|
103
|
-
data = {
|
104
|
-
app_name: namespace,
|
105
|
-
Version_Gem: ZuoraConnect::VERSION,
|
106
|
-
Version_Zuora: ZuoraAPI::VERSION ,
|
107
|
-
Version_Ruby: RUBY_VERSION,
|
108
|
-
Version_Rails: Rails.version,
|
109
|
-
hold: 1
|
110
|
-
}
|
111
|
-
elsif type == "stats"
|
112
|
-
begin
|
113
|
-
Resque.redis.ping
|
114
|
-
data = {
|
115
|
-
app_name: namespace,
|
116
|
-
Resque:{
|
117
|
-
Jobs_Finished: Resque.info[:processed] ,
|
118
|
-
Jobs_Failed: Resque.info[:failed],
|
119
|
-
Jobs_Pending: Resque.info[:pending],
|
120
|
-
Workers_Active: Resque.info[:working],
|
121
|
-
Workers_Total: Resque.info[:workers]
|
122
|
-
}
|
123
|
-
}
|
124
|
-
rescue
|
125
|
-
end
|
126
|
-
end
|
127
|
-
return data.to_json
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
27
|
def apartment_switch(method = nil, migrate = false)
|
132
28
|
begin
|
133
29
|
Apartment::Tenant.switch!(self.id) if self.persisted?
|
@@ -221,7 +117,7 @@ module ZuoraConnect
|
|
221
117
|
|
222
118
|
def refresh(session = nil)
|
223
119
|
refresh_count ||= 0
|
224
|
-
|
120
|
+
|
225
121
|
start = Time.now
|
226
122
|
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
227
123
|
response_time = Time.now - start
|
@@ -241,7 +137,6 @@ module ZuoraConnect
|
|
241
137
|
Rails.logger.info("[#{self.id}] REFRESH TASK - #{ex.class} Retrying(#{refresh_count})")
|
242
138
|
retry
|
243
139
|
else
|
244
|
-
error_type = "#{ex.class}"
|
245
140
|
Rails.logger.fatal("[#{self.id}] REFRESH TASK - #{ex.class} Failed #{refresh_count}x")
|
246
141
|
raise
|
247
142
|
end
|
@@ -253,16 +148,9 @@ module ZuoraConnect
|
|
253
148
|
end
|
254
149
|
retry
|
255
150
|
else
|
256
|
-
error_type = "#{ex.class}"
|
257
151
|
Rails.logger.fatal("[#{self.id}] REFRESH TASK - Failed #{refresh_count}x")
|
258
152
|
raise
|
259
153
|
end
|
260
|
-
ensure
|
261
|
-
# Writing to telegraf
|
262
|
-
status_code = response.code if response
|
263
|
-
endpoint_name = URI(ZuoraConnect.configuration.url).host
|
264
|
-
Thread.current[:appinstance].present? ? app_instance = Thread.current[:appinstance].id : app_instance = 0
|
265
|
-
ZuoraConnect::AppInstanceBase.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "GET", "app_instance": app_instance)
|
266
154
|
end
|
267
155
|
|
268
156
|
#### START Task Mathods ####
|
@@ -302,28 +190,13 @@ module ZuoraConnect
|
|
302
190
|
end
|
303
191
|
|
304
192
|
def updateOption(optionId, value)
|
305
|
-
|
306
|
-
start_time = Time.now
|
307
|
-
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/application_options/#{optionId}/edit?value=#{value}",:body => {:access_token => self.username})
|
308
|
-
rescue => e
|
309
|
-
error_type = "#{e.class}"
|
310
|
-
ensure
|
311
|
-
end_time = Time.now
|
312
|
-
response_time = end_time - start_time
|
313
|
-
status_code = response.code if response
|
314
|
-
endpoint_name = URI(ZuoraConnect.configuration.url).host
|
315
|
-
Thread.current[:appinstance].present? ? app_instance = Thread.current[:appinstance].id : app_instance = 0
|
316
|
-
ZuoraConnect::AppInstanceBase.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "GET", "app_instance": app_instance)
|
317
|
-
return response
|
318
|
-
end
|
193
|
+
return HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/application_options/#{optionId}/edit?value=#{value}",:body => {:access_token => self.username})
|
319
194
|
end
|
320
195
|
|
321
196
|
#This can update an existing login, add a new login, change to another existing login
|
322
197
|
#EXAMPLE: {"name": "ftp_login_14","username": "ftplogin7","tenant_type": "Custom","password": "test2","url": "www.ftp.com","custom_data": { "path": "/var/usr/test"}}
|
323
198
|
def update_logins(options)
|
324
199
|
update_login_count ||= 0
|
325
|
-
start_time = Time.now
|
326
|
-
error_type = ""
|
327
200
|
response = HTTParty.post(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}/logins",:body => {:access_token => self.username}.merge(options))
|
328
201
|
parsed_json = JSON.parse(response.body)
|
329
202
|
if response.code == 200
|
@@ -338,11 +211,10 @@ module ZuoraConnect
|
|
338
211
|
else
|
339
212
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
340
213
|
end
|
341
|
-
rescue Net::ReadTimeout, Net::OpenTimeout, Errno::EPIPE, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError
|
214
|
+
rescue Net::ReadTimeout, Net::OpenTimeout, Errno::EPIPE, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError
|
342
215
|
if (update_login_count += 1) < 3
|
343
216
|
retry
|
344
217
|
else
|
345
|
-
error_type = "#{ex.class}"
|
346
218
|
raise
|
347
219
|
end
|
348
220
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
@@ -352,16 +224,8 @@ module ZuoraConnect
|
|
352
224
|
end
|
353
225
|
retry
|
354
226
|
else
|
355
|
-
error_type = "#{ex.class}"
|
356
227
|
raise
|
357
228
|
end
|
358
|
-
ensure
|
359
|
-
end_time = Time.now
|
360
|
-
response_time = end_time - start_time
|
361
|
-
status_code = response.code if response
|
362
|
-
endpoint_name = URI(ZuoraConnect.configuration.url).host
|
363
|
-
Thread.current[:appinstance].present? ? app_instance = Thread.current[:appinstance].id : app_instance = 0
|
364
|
-
ZuoraConnect::AppInstanceBase.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "POST", "app_instance": app_instance)
|
365
229
|
end
|
366
230
|
#### END Task Mathods ####
|
367
231
|
|
@@ -380,7 +244,7 @@ module ZuoraConnect
|
|
380
244
|
|
381
245
|
def refresh_oauth
|
382
246
|
refresh_oauth_count ||= 0
|
383
|
-
|
247
|
+
|
384
248
|
start = Time.now
|
385
249
|
params = {
|
386
250
|
:grant_type => "refresh_token",
|
@@ -407,7 +271,6 @@ module ZuoraConnect
|
|
407
271
|
Rails.logger.info("[#{self.id}] REFRESH OAUTH - #{ex.class} Retrying(#{refresh_oauth_count})")
|
408
272
|
retry
|
409
273
|
else
|
410
|
-
error_type = "#{ex.class}"
|
411
274
|
Rails.logger.fatal("[#{self.id}] REFRESH OAUTH - #{ex.class} Failed #{refresh_oauth_count}x")
|
412
275
|
raise
|
413
276
|
end
|
@@ -422,15 +285,9 @@ module ZuoraConnect
|
|
422
285
|
Rails.logger.info("[#{self.id}] REFRESH OAUTH - Failed Retrying(#{refresh_oauth_count})")
|
423
286
|
retry
|
424
287
|
else
|
425
|
-
error_type = "#{ex.class}"
|
426
288
|
Rails.logger.fatal("[#{self.id}] REFRESH OAUTH - Failed #{refresh_oauth_count}x")
|
427
289
|
raise
|
428
290
|
end
|
429
|
-
ensure
|
430
|
-
status_code = response.code if response
|
431
|
-
endpoint_name = URI(ZuoraConnect.configuration.url).host
|
432
|
-
Thread.current[:appinstance].present? ? app_instance = Thread.current[:appinstance].id : app_instance = 0
|
433
|
-
ZuoraConnect::AppInstanceBase.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "POST", "app_instance": app_instance)
|
434
291
|
end
|
435
292
|
#### END Connect OAUTH methods ####
|
436
293
|
|
@@ -887,7 +744,6 @@ module ZuoraConnect
|
|
887
744
|
super
|
888
745
|
end
|
889
746
|
|
890
|
-
|
891
747
|
method_hook :refresh, :updateOption, :update_logins, :before => :check_oauth_state
|
892
748
|
method_hook :new_session, :refresh, :build_task, :after => :apartment_switch
|
893
749
|
end
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
ZuoraConnect::Engine.routes.draw do
|
2
2
|
get '/health' => 'static#health'
|
3
|
-
get '/internal/data' => 'static#metrics'
|
4
3
|
get '/invalid_session' => 'static#session_error', :as => :invalid_session
|
5
4
|
get '/invalid_instance' => "static#invalid_app_instance_error", :as => :invalid_instance
|
6
5
|
namespace :api do
|
data/lib/zuora_connect.rb
CHANGED
@@ -4,11 +4,9 @@ require 'zuora_connect/exceptions'
|
|
4
4
|
require 'zuora_connect/controllers/helpers'
|
5
5
|
require 'zuora_connect/views/helpers'
|
6
6
|
require 'zuora_connect/railtie'
|
7
|
-
require 'resque/additions'
|
7
|
+
require 'resque/additions'
|
8
8
|
require 'resque/dynamic_queues'
|
9
9
|
require 'resque/self_lookup'
|
10
|
-
require 'prometheus/client'
|
11
|
-
|
12
10
|
|
13
11
|
module ZuoraConnect
|
14
12
|
class << self
|
@@ -37,10 +35,4 @@ module ZuoraConnect
|
|
37
35
|
|
38
36
|
return configuration
|
39
37
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
38
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ZuoraConnect
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :oauth_client_id, :oauth_client_secret, :oauth_client_redirect_uri,:use_s3, :default_locale,:dev_mode_appinstance ,:dev_mode_admin, :dev_mode_user, :dev_mode_pass, :default_time_zone,:delayed_job,:url, :private_key, :dev_mode_logins,:dev_mode_mode, :dev_mode_options, :mode, :timeout,:dev_mode_secret_access_key,:dev_mode_access_key_id,:aws_region, :s3_bucket_name, :s3_folder_name, :additional_apartment_models
|
3
|
+
attr_accessor :oauth_client_id, :oauth_client_secret, :oauth_client_redirect_uri,:use_s3, :default_locale,:dev_mode_appinstance ,:dev_mode_admin, :dev_mode_user, :dev_mode_pass, :default_time_zone,:delayed_job,:url, :private_key, :dev_mode_logins,:dev_mode_mode, :dev_mode_options, :mode, :timeout,:dev_mode_secret_access_key,:dev_mode_access_key_id,:aws_region, :s3_bucket_name, :s3_folder_name, :additional_apartment_models
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@default_locale = :en
|
@@ -11,14 +11,6 @@ module ZuoraConnect
|
|
11
11
|
@use_s3 = false
|
12
12
|
@private_key = ENV["CONNECT_KEY"]
|
13
13
|
@additional_apartment_models = []
|
14
|
-
@telegraf_endpoint = 'udp://telegraf-app-metrics.monitoring.svc.cluster.local:8094'
|
15
|
-
@enable_metrics_flag = true
|
16
|
-
@telegraf_client = Telegraf::Agent.new @telegraf_endpoint
|
17
|
-
|
18
|
-
# Setting the app name for telegraf write
|
19
|
-
@app_name = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
|
20
|
-
@influxdb_series_name_inbound = "request-inbound"
|
21
|
-
@influxdb_series_name_outbound = "request-outbound"
|
22
14
|
|
23
15
|
# OAuth Settings
|
24
16
|
@oauth_client_id = ""
|
@@ -38,10 +30,6 @@ module ZuoraConnect
|
|
38
30
|
@aws_region = "us-west-2"
|
39
31
|
@s3_bucket_name = "rbm-apps"
|
40
32
|
@s3_folder_name = Rails.application.class.parent_name
|
41
|
-
|
42
|
-
#Prometheus
|
43
|
-
@custom_prometheus_update_block = nil
|
44
|
-
|
45
33
|
end
|
46
34
|
|
47
35
|
def private_key
|
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'apartment/migrator'
|
2
|
-
require 'benchmark'
|
3
|
-
|
4
2
|
module ZuoraConnect
|
5
3
|
module Controllers
|
6
4
|
module Helpers
|
@@ -38,14 +36,14 @@ module ZuoraConnect
|
|
38
36
|
else
|
39
37
|
setup_instance_via_dev_mode
|
40
38
|
end
|
41
|
-
#Call .data_lookup with the current session to retrieve session. In some cases session may be stored/cache in redis
|
39
|
+
#Call .data_lookup with the current session to retrieve session. In some cases session may be stored/cache in redis
|
42
40
|
#so data lookup provides a model method that can be overriden per app.
|
43
41
|
if params[:controller] != 'zuora_connect/api/v1/app_instance' && params[:action] != 'drop'
|
44
42
|
if @appinstance.new_session_for_ui_requests(:params => params)
|
45
43
|
@appinstance.new_session(:session => @appinstance.data_lookup(:session => session))
|
46
44
|
end
|
47
45
|
end
|
48
|
-
PaperTrail.whodunnit = session["#{@appinstance.id}::user::email"] if defined?(PaperTrail) && session["#{@appinstance.id}::user::email"].present?
|
46
|
+
PaperTrail.whodunnit = session["#{@appinstance.id}::user::email"] if defined?(PaperTrail) && session["#{@appinstance.id}::user::email"].present?
|
49
47
|
begin
|
50
48
|
I18n.locale = session["#{@appinstance.id}::user::locale"] ? session["#{@appinstance.id}::user::locale"] : @appinstance.locale
|
51
49
|
rescue I18n::InvalidLocale => ex
|
@@ -114,7 +112,7 @@ module ZuoraConnect
|
|
114
112
|
else
|
115
113
|
raise ZuoraConnect::Exceptions::AccessDenied.new("Authorization mistmatch. Possible tampering")
|
116
114
|
end
|
117
|
-
end
|
115
|
+
end
|
118
116
|
end
|
119
117
|
|
120
118
|
def setup_instance_via_session
|
@@ -1,10 +1,5 @@
|
|
1
|
-
require 'middleware/metrics_middleware'
|
2
|
-
|
3
1
|
module ZuoraConnect
|
4
2
|
class Railtie < Rails::Railtie
|
5
|
-
require 'prometheus/middleware/exporter'
|
6
|
-
|
7
|
-
|
8
3
|
config.before_initialize do
|
9
4
|
version = Rails.version
|
10
5
|
if version >= "5.0.0"
|
@@ -17,23 +12,6 @@ module ZuoraConnect
|
|
17
12
|
::Rails.configuration.action_dispatch.x_sendfile_header = nil
|
18
13
|
end
|
19
14
|
|
20
|
-
# Base object not being loaded at this point for some reason
|
21
|
-
if ZuoraConnect::Configuration.new.enable_metrics_flag == true
|
22
|
-
|
23
|
-
initializer "prometheus.configure_rails_initialization" do |app|
|
24
|
-
app.middleware.use Prometheus::Middleware::Exporter,(options ={:path => '/connect/internal/metrics'})
|
25
|
-
end
|
26
|
-
|
27
|
-
initializer "zuora_connect.configure_rails_initialization" do |app|
|
28
|
-
app.middleware.insert_after Rack::Sendfile, Middleware::MetricsMiddleware
|
29
|
-
end
|
30
|
-
|
31
|
-
# hook to process_action
|
32
|
-
ActiveSupport::Notifications.subscribe('process_action.action_controller', Middleware::PageRequest.new)
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
15
|
initializer(:rails_stdout_logging, before: :initialize_logger) do
|
38
16
|
if Rails.env != 'development' && !ENV['DEIS_APP'].blank?
|
39
17
|
require 'lograge'
|
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.5.
|
4
|
+
version: 1.5.40
|
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-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apartment
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 1.4
|
39
|
+
version: '1.4'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 1.4.0
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.4
|
49
|
+
version: '1.4'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 1.4.0
|
@@ -106,34 +106,6 @@ dependencies:
|
|
106
106
|
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
|
-
- !ruby/object:Gem::Dependency
|
110
|
-
name: telegraf
|
111
|
-
requirement: !ruby/object:Gem::Requirement
|
112
|
-
requirements:
|
113
|
-
- - "~>"
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
version: 0.4.0
|
116
|
-
type: :runtime
|
117
|
-
prerelease: false
|
118
|
-
version_requirements: !ruby/object:Gem::Requirement
|
119
|
-
requirements:
|
120
|
-
- - "~>"
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version: 0.4.0
|
123
|
-
- !ruby/object:Gem::Dependency
|
124
|
-
name: prometheus-client
|
125
|
-
requirement: !ruby/object:Gem::Requirement
|
126
|
-
requirements:
|
127
|
-
- - "~>"
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
version: 0.8.0
|
130
|
-
type: :runtime
|
131
|
-
prerelease: false
|
132
|
-
version_requirements: !ruby/object:Gem::Requirement
|
133
|
-
requirements:
|
134
|
-
- - "~>"
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
version: 0.8.0
|
137
109
|
- !ruby/object:Gem::Dependency
|
138
110
|
name: railties
|
139
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -266,7 +238,6 @@ files:
|
|
266
238
|
- app/views/zuora_connect/static/session_error.html.erb
|
267
239
|
- config/initializers/apartment.rb
|
268
240
|
- config/initializers/object_method_hooks.rb
|
269
|
-
- config/initializers/prometheus.rb
|
270
241
|
- config/initializers/redis.rb
|
271
242
|
- config/initializers/resque.rb
|
272
243
|
- config/initializers/to_bool.rb
|
@@ -281,7 +252,6 @@ files:
|
|
281
252
|
- db/migrate/20110503003603_add_catalog_mappings_to_app_instance.rb
|
282
253
|
- db/migrate/20110503003604_catalog_default.rb
|
283
254
|
- db/migrate/20180301052853_add_catalog_attempted_at.rb
|
284
|
-
- lib/middleware/metrics_middleware.rb
|
285
255
|
- lib/resque/additions.rb
|
286
256
|
- lib/resque/dynamic_queues.rb
|
287
257
|
- lib/resque/self_lookup.rb
|
@@ -349,9 +319,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
349
319
|
version: '0'
|
350
320
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
351
321
|
requirements:
|
352
|
-
- - "
|
322
|
+
- - ">="
|
353
323
|
- !ruby/object:Gem::Version
|
354
|
-
version:
|
324
|
+
version: '0'
|
355
325
|
requirements: []
|
356
326
|
rubyforge_project:
|
357
327
|
rubygems_version: 2.6.8
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Prometheus
|
2
|
-
require "zuora_connect/version"
|
3
|
-
require "zuora_api/version"
|
4
|
-
|
5
|
-
app_name = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
|
6
|
-
# Create a default Prometheus registry for our metrics.
|
7
|
-
prometheus = Prometheus::Client.registry
|
8
|
-
|
9
|
-
# Create your metrics.
|
10
|
-
ZUORA_VERSION = Prometheus::Client::Gauge.new(:zuora_version, 'The current Zuora Gem version.')
|
11
|
-
CONNECT_VERSION = Prometheus::Client::Gauge.new(:gem_version, 'The current Connect Gem version.')
|
12
|
-
RAILS_VERSION = Prometheus::Client::Gauge.new(:rails_version, 'The current Rails version.')
|
13
|
-
RUBY_V = Prometheus::Client::Gauge.new(:ruby_version, 'The current Ruby version.')
|
14
|
-
|
15
|
-
# Register your metrics with the registry we previously created.
|
16
|
-
prometheus.register(ZUORA_VERSION);ZUORA_VERSION.set({version:ZuoraAPI::VERSION,name:app_name},0)
|
17
|
-
prometheus.register(CONNECT_VERSION);CONNECT_VERSION.set({version:ZuoraConnect::VERSION,name:app_name},0)
|
18
|
-
prometheus.register(RAILS_VERSION);RAILS_VERSION.set({version:Rails.version,name:app_name},0)
|
19
|
-
prometheus.register(RUBY_V);RUBY_V.set({version:RUBY_VERSION,name:app_name},0)
|
20
|
-
|
21
|
-
# Do they have resque jobs?
|
22
|
-
if defined? Resque.redis
|
23
|
-
REDIS_CONNECTION = Prometheus::Client::Gauge.new(:redis_connection, 'The status of the redis connection, 0 or 1')
|
24
|
-
FINISHED_JOBS = Prometheus::Client::Gauge.new(:finished_jobs, 'Done resque jobs')
|
25
|
-
WORKERS = Prometheus::Client::Gauge.new(:workers, 'Total resque workers')
|
26
|
-
ACTIVE_WORKERS = Prometheus::Client::Gauge.new(:active_workers, 'Active resque workers')
|
27
|
-
FAILED_JOBS = Prometheus::Client::Gauge.new(:failed_jobs, 'Failed resque jobs')
|
28
|
-
PENDING_JOBS = Prometheus::Client::Gauge.new(:pending_jobs, 'Pending resque jobs')
|
29
|
-
|
30
|
-
prometheus.register(REDIS_CONNECTION)
|
31
|
-
prometheus.register(FINISHED_JOBS)
|
32
|
-
prometheus.register(ACTIVE_WORKERS)
|
33
|
-
prometheus.register(WORKERS)
|
34
|
-
prometheus.register(FAILED_JOBS)
|
35
|
-
prometheus.register(PENDING_JOBS)
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
module Middleware
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
# Object of this class is passed to the ActiveSupport::Notification hook
|
5
|
-
class PageRequest
|
6
|
-
|
7
|
-
# This method is triggered when a non error page is loaded (not 404)
|
8
|
-
def call(name, started, finished, unique_id, payload)
|
9
|
-
|
10
|
-
# If the url contains any css or JavaScript files then do not collect metrics for them
|
11
|
-
block_words = ["css", "assets", "jpg", "png", "jpeg", "ico"]
|
12
|
-
if block_words.any? { |word| payload[:path].include?(word) }
|
13
|
-
return nil
|
14
|
-
end
|
15
|
-
|
16
|
-
# Getting the endpoint and the content_type
|
17
|
-
content_hash = {:html => "text/html", :js => "application/javascript", :json => "application/json"}
|
18
|
-
content_hash.key?(payload[:format]) ? content_type = content_hash[payload[:format]] : content_type = payload[:format]
|
19
|
-
request_path = "#{payload[:controller]}##{payload[:action]}"
|
20
|
-
response_time = finished-started
|
21
|
-
|
22
|
-
# payloads with 500 requests do not have status as it is not set by the controller
|
23
|
-
# https://github.com/rails/rails/issues/33335
|
24
|
-
status_code = payload[:status] ? payload[:status] : payload[:exception_object].present? ? 500 : ""
|
25
|
-
|
26
|
-
# Write to telegraf
|
27
|
-
ZuoraConnect::AppInstanceBase.write_to_telegraf("endpoint_name": request_path, "method_name": payload[:method], "status_code": status_code, "response_time": response_time, "db_runtime": payload[:db_runtime].to_f, "view_runtime": payload[:view_runtime], "content_type": content_type, "direction": "inbound")
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
class MetricsMiddleware
|
34
|
-
|
35
|
-
require "zuora_connect/version"
|
36
|
-
require "zuora_api/version"
|
37
|
-
require "telegraf"
|
38
|
-
|
39
|
-
def initialize(app)
|
40
|
-
@app = app
|
41
|
-
end
|
42
|
-
|
43
|
-
def call(env)
|
44
|
-
start_time = Time.now
|
45
|
-
@status, @headers, @response = @app.call(env)
|
46
|
-
end_time = Time.now
|
47
|
-
|
48
|
-
# If the url contains any CSS or JavaScript files then do not collect metrics for them
|
49
|
-
block_words = ["css", "assets", "jpg", "png", "jpeg", "ico"]
|
50
|
-
if block_words.any? { |word| env['PATH_INFO'].include?(word) }
|
51
|
-
return [@status, @headers, @response]
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
response_time = end_time - start_time
|
56
|
-
|
57
|
-
#Prometheus Stuff
|
58
|
-
if env['PATH_INFO'] == '/connect/internal/metrics'
|
59
|
-
|
60
|
-
#Do something before each scrape
|
61
|
-
if defined? Resque.redis
|
62
|
-
|
63
|
-
app_name = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
|
64
|
-
begin
|
65
|
-
|
66
|
-
Resque.redis.ping
|
67
|
-
|
68
|
-
Prometheus::REDIS_CONNECTION.set({connection:'redis',name:app_name},1)
|
69
|
-
Prometheus::FINISHED_JOBS.set({type:'resque',name:app_name},Resque.info[:processed])
|
70
|
-
Prometheus::PENDING_JOBS.set({type:'resque',name:app_name},Resque.info[:pending])
|
71
|
-
Prometheus::ACTIVE_WORKERS.set({type:'resque',name:app_name},Resque.info[:working])
|
72
|
-
Prometheus::WORKERS.set({type:'resque',name:app_name},Resque.info[:workers])
|
73
|
-
Prometheus::FAILED_JOBS.set({type:'resque',name:app_name},Resque.info[:failed])
|
74
|
-
|
75
|
-
rescue Redis::CannotConnectError
|
76
|
-
Prometheus::REDIS_CONNECTION.set({connection:'redis',name:app_name},0)
|
77
|
-
end
|
78
|
-
|
79
|
-
if ZuoraConnect.configuration.custom_prometheus_update_block != nil
|
80
|
-
ZuoraConnect.configuration.custom_prometheus_update_block.call()
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
# Writing to telegraf: Handle 404 and 500 requests
|
87
|
-
if @status == 404 || @status == 304
|
88
|
-
# Getting the endpoint and content_type
|
89
|
-
request_path = @status == 404 ? "ActionController#RoutingError" : env["action_controller.instance"].present? ? "#{env["action_controller.instance"].class}##{env["action_controller.instance"].action_name}" : ""
|
90
|
-
|
91
|
-
# Uncomment following block of code for handling engine requests/requests without controller
|
92
|
-
# else
|
93
|
-
# # Handling requests which do not have controllers (engines)
|
94
|
-
# if env["SCRIPT_NAME"].present?
|
95
|
-
# controller_path = "#{env['SCRIPT_NAME'][1..-1]}"
|
96
|
-
# controller_path = controller_path.sub("/", "::")
|
97
|
-
# request_path = "#{controller_path}#UnknownAction"
|
98
|
-
# end
|
99
|
-
|
100
|
-
content_type = @headers['Content-Type'].split(';')[0] if @headers['Content-Type']
|
101
|
-
ZuoraConnect::AppInstanceBase.write_to_telegraf("endpoint_name": request_path, "method_name": env['REQUEST_METHOD'], "status_code": @status, "response_time": response_time, "content_type": content_type, "direction": "inbound") if request_path.present?
|
102
|
-
end
|
103
|
-
|
104
|
-
[@status, @headers, @response]
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|