zuora_connect 2.0.60t → 3.0.0k
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 +4 -4
- data/Rakefile +1 -1
- data/app/controllers/zuora_connect/static_controller.rb +3 -7
- data/app/models/zuora_connect/app_instance_base.rb +90 -143
- data/config/initializers/postgresql_adapter.rb +1 -1
- data/config/initializers/prometheus.rb +13 -13
- data/config/initializers/redis.rb +4 -4
- data/config/initializers/resque.rb +0 -12
- data/config/initializers/unicorn.rb +2 -2
- data/config/routes.rb +0 -1
- data/lib/metrics/net.rb +7 -7
- data/lib/middleware/metrics_middleware.rb +9 -44
- data/lib/resque/plugins/app_instance_job.rb +10 -6
- data/lib/resque/plugins/custom_logger.rb +1 -1
- data/lib/zuora_connect.rb +3 -63
- data/lib/zuora_connect/controllers/helpers.rb +20 -20
- data/lib/zuora_connect/engine.rb +2 -1
- data/lib/zuora_connect/railtie.rb +0 -77
- data/lib/zuora_connect/version.rb +1 -1
- metadata +67 -14
- data/app/models/zuora_connect/telegraf.rb +0 -97
- data/lib/logging/connect_formatter.rb +0 -44
- data/lib/metrics/influx/point_value.rb +0 -79
@@ -12,21 +12,21 @@ class RedisFlash
|
|
12
12
|
end
|
13
13
|
|
14
14
|
if defined?(Redis.current)
|
15
|
-
Redis.current = Redis.new(:id => "#{
|
15
|
+
Redis.current = Redis.new(:id => "#{ZuoraObservability::Env.full_process_name(process_name: 'Redis')}", :url => redis_url, :timeout => 6, :reconnect_attempts => 2)
|
16
16
|
browser_urls['Redis'] = { "url" => redis_url }
|
17
17
|
if defined?(Resque.redis)
|
18
18
|
if resque_url != redis_url
|
19
|
-
Resque.redis = Redis.new(:id => "#{
|
19
|
+
Resque.redis = Redis.new(:id => "#{ZuoraObservability::Env.full_process_name(process_name: 'Resque')}", :url => resque_url, :timeout => 6, :reconnect_attempts => 2)
|
20
20
|
browser_urls['Resque'] = { "url" => resque_url }
|
21
21
|
else
|
22
22
|
Resque.redis = Redis.current
|
23
23
|
end
|
24
24
|
end
|
25
25
|
if defined?(flash_url.present?)
|
26
|
-
RedisFlash.current = Redis.new(:id => "#{
|
26
|
+
RedisFlash.current = Redis.new(:id => "#{ZuoraObservability::Env.full_process_name(process_name: 'Flash')}", :url => flash_url, :timeout => 6, :reconnect_attempts => 2)
|
27
27
|
browser_urls['Flash'] = { "url" => flash_url }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
if defined?(RedisBrowser)
|
31
31
|
RedisBrowser.configure("connections" => browser_urls)
|
32
|
-
end
|
32
|
+
end
|
@@ -34,15 +34,3 @@ Resque.module_eval do
|
|
34
34
|
Hash[queue_names.zip(sizes)]
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
if defined?(Resque.logger)
|
39
|
-
Resque.logger = ZuoraConnect.custom_logger(name: "Resque", type: 'Monologger', level: MonoLogger::INFO)
|
40
|
-
Resque::Scheduler.logger = ZuoraConnect.custom_logger(name: "ResqueScheduler") if defined?(Resque::Scheduler)
|
41
|
-
end
|
42
|
-
if defined?(Delayed::Worker.logger)
|
43
|
-
Delayed::Worker.logger = ZuoraConnect.custom_logger(name: "DelayedJob", type: 'Monologger', level: MonoLogger::INFO)
|
44
|
-
end
|
45
|
-
|
46
|
-
Makara::Logging::Logger.logger = ZuoraConnect.custom_logger(name: "Makara") if defined?(Makara)
|
47
|
-
ElasticAPM.agent.config.logger = ZuoraConnect.custom_logger(name: "ElasticAPM", level: MonoLogger::WARN) if defined?(ElasticAPM) && ElasticAPM.running?
|
48
|
-
ActionMailer::Base.logger = ZuoraConnect.custom_logger(name: "ActionMailer", type: 'Monologger') if defined?(ActionMailer)
|
@@ -6,7 +6,7 @@ if defined?(Unicorn::WorkerKiller)
|
|
6
6
|
if defined?(Prometheus)
|
7
7
|
Prometheus::UNICORN_KILLS.set(1)
|
8
8
|
else
|
9
|
-
|
9
|
+
ZuoraObservability::Metrics.write_to_telegraf(direction: 'Unicorn-Killer', tags: {app_instance: 0}, values: {kill: 1})
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -34,4 +34,4 @@ if defined?(Unicorn::HttpServer) && defined?(Prometheus)
|
|
34
34
|
class Unicorn::Worker
|
35
35
|
prepend WorkerExtensions
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
data/config/routes.rb
CHANGED
data/lib/metrics/net.rb
CHANGED
@@ -68,12 +68,12 @@ class HttpLogger
|
|
68
68
|
log_request_body(request)
|
69
69
|
log_request_headers(request)
|
70
70
|
if defined?(response) && response
|
71
|
-
tags = tags.merge({status: response.code.to_i})
|
71
|
+
tags = tags.merge({status: response.code.to_i})
|
72
72
|
log_response_code(response)
|
73
73
|
log_response_headers(response)
|
74
74
|
log_response_body(response.body)
|
75
75
|
end
|
76
|
-
|
76
|
+
ZuoraObservability::Metrics.write_to_telegraf(direction: :outbound, tags: tags, values: values)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -95,7 +95,7 @@ class HttpLogger
|
|
95
95
|
end
|
96
96
|
|
97
97
|
HTTP_METHODS_WITH_BODY = Set.new(%w(POST PUT GET PATCH))
|
98
|
-
|
98
|
+
|
99
99
|
def log_request_body(request)
|
100
100
|
if self.class.log_request_body
|
101
101
|
if HTTP_METHODS_WITH_BODY.include?(request.method)
|
@@ -149,8 +149,8 @@ class HttpLogger
|
|
149
149
|
def truncate_body(body)
|
150
150
|
if collapse_body_limit && collapse_body_limit > 0 && body && body.size >= collapse_body_limit
|
151
151
|
body_piece_size = collapse_body_limit / 2
|
152
|
-
body[0..body_piece_size] +
|
153
|
-
"\n\n<some data truncated>\n\n" +
|
152
|
+
body[0..body_piece_size] +
|
153
|
+
"\n\n<some data truncated>\n\n" +
|
154
154
|
body[(body.size - body_piece_size)..body.size]
|
155
155
|
else
|
156
156
|
body
|
@@ -203,7 +203,7 @@ class Net::HTTP
|
|
203
203
|
|
204
204
|
def request(request, body = nil, &block)
|
205
205
|
HttpLogger.perform(self, request, body) do
|
206
|
-
request_without_logging(request, body, &block)
|
206
|
+
request_without_logging(request, body, &block)
|
207
207
|
end
|
208
208
|
end
|
209
209
|
end
|
@@ -215,4 +215,4 @@ if defined?(Rails)
|
|
215
215
|
HttpLogger.logger = ZuoraConnect.logger unless HttpLogger.logger
|
216
216
|
end
|
217
217
|
end
|
218
|
-
end
|
218
|
+
end
|
@@ -1,37 +1,6 @@
|
|
1
1
|
module ZuoraConnect
|
2
2
|
require 'uri'
|
3
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
|
-
# 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", :csv => "text/csv"}
|
14
|
-
content_type = content_hash.key?(payload[:format]) ? content_hash[payload[:format]] : payload[:format]
|
15
|
-
content_type = content_type.to_s.gsub('text/javascript', 'application/javascript')
|
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
|
25
|
-
|
26
|
-
tags = {method: payload[:method], status: status_code, error_type: exception, content_type: content_type, controller: payload[:controller], action: payload[:action]}.compact
|
27
|
-
|
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
|
30
|
-
|
31
|
-
ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
4
|
class MetricsMiddleware
|
36
5
|
|
37
6
|
require "zuora_connect/version"
|
@@ -42,7 +11,7 @@ module ZuoraConnect
|
|
42
11
|
end
|
43
12
|
|
44
13
|
def call(env)
|
45
|
-
@bad_headers = ["HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED_HOST", "HTTP_X_FORWARDED_PORT", "HTTP_X_FORWARDED_PROTO", "HTTP_X_FORWARDED_SCHEME", "HTTP_X_FORWARDED_SSL"]
|
14
|
+
@bad_headers = ["HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED_HOST", "HTTP_X_FORWARDED_PORT", "HTTP_X_FORWARDED_PROTO", "HTTP_X_FORWARDED_SCHEME", "HTTP_X_FORWARDED_SSL"]
|
46
15
|
if !ActionDispatch::Request::HTTP_METHODS.include?(env["REQUEST_METHOD"].upcase)
|
47
16
|
[405, {"Content-Type" => "text/plain"}, ["Method Not Allowed"]]
|
48
17
|
else
|
@@ -65,15 +34,18 @@ module ZuoraConnect
|
|
65
34
|
@bad_headers.each { |header| env.delete(header) }
|
66
35
|
|
67
36
|
if defined?(Prometheus) && env['PATH_INFO'] == '/connect/internal/metrics'
|
37
|
+
|
68
38
|
# Prometheus Stuff
|
69
|
-
metrics =
|
39
|
+
metrics = ZuoraObservability::Metrics.resque
|
40
|
+
metrics = defined?(ZuoraConnect::AppInstance.get_metrics) ? ZuoraConnect::AppInstance.get_metrics(metrics) : metrics
|
41
|
+
|
70
42
|
redis_up = metrics.present? && metrics.dig(:Resque, :Workers_Total).present? ? 1 : 0
|
71
43
|
Prometheus::REDIS_CONNECTION.set(redis_up)
|
72
44
|
|
73
45
|
process_prometheus_metric(metrics: metrics)
|
74
46
|
|
75
47
|
if defined?(Unicorn) && Unicorn.respond_to?(:listener_names)
|
76
|
-
|
48
|
+
ZuoraObservability::Metrics.unicorn_listener.each do |key, value|
|
77
49
|
gauge = Prometheus.const_get("unicorn_#{key}".gsub(/[^a-zA-Z0-9_]/, '_').upcase)
|
78
50
|
gauge.set(value) if gauge.present?
|
79
51
|
end
|
@@ -84,14 +56,7 @@ module ZuoraConnect
|
|
84
56
|
start_time = Time.now
|
85
57
|
begin
|
86
58
|
@status, @headers, @response = @app.call(env)
|
87
|
-
ensure
|
88
|
-
|
89
|
-
# If the url contains any CSS or JavaScript files then do not collect metrics for them
|
90
|
-
if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| env['PATH_INFO'].include?(word) } || /.*\.js$/.match(env['PATH_INFO'])
|
91
|
-
tags = {status: @status, controller: 'ActionController', action: 'Assets', app_instance: 0}
|
92
|
-
values = {response_time: ((Time.now - start_time)*1000).round(2) }
|
93
|
-
ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: 'request-inbound-assets', tags: tags, values: values)
|
94
|
-
end
|
59
|
+
ensure
|
95
60
|
|
96
61
|
# Uncomment following block of code for handling engine requests/requests without controller
|
97
62
|
# else
|
@@ -112,7 +77,7 @@ module ZuoraConnect
|
|
112
77
|
|
113
78
|
values = {response_time: ((Time.now - start_time)*1000).round(2) }
|
114
79
|
|
115
|
-
|
80
|
+
ZuoraObservability::Metrics.write_to_telegraf(direction: :inbound, tags: tags, values: values)
|
116
81
|
end
|
117
82
|
end
|
118
83
|
Thread.current[:inbound_metric] = nil
|
@@ -140,7 +105,7 @@ module ZuoraConnect
|
|
140
105
|
gauge_name.to_sym,
|
141
106
|
docstring: "#{key} metric",
|
142
107
|
labels: %i(type name),
|
143
|
-
preset_labels: { type: type, name:
|
108
|
+
preset_labels: { type: type, name: ZuoraObservability::Env.app_name },
|
144
109
|
store_settings: most_recent_aggregation
|
145
110
|
)
|
146
111
|
gauge.set(value)
|
@@ -12,14 +12,14 @@ module Resque
|
|
12
12
|
when "Hash"
|
13
13
|
data = args.merge({:worker_class => self.to_s})
|
14
14
|
end
|
15
|
-
if Rails.logger.is_a?(Ougai::Logger)
|
15
|
+
if Rails.logger.is_a?(Ougai::Logger) && !Rails.env.development?
|
16
16
|
Rails.logger.with_fields = {job: data, trace_id: SecureRandom.uuid, name: "RailsWorker"}
|
17
17
|
end
|
18
18
|
|
19
19
|
begin
|
20
|
-
connection_count ||= 0
|
20
|
+
connection_count ||= 0
|
21
21
|
@appinstance = ZuoraConnect::AppInstance.find(args['app_instance_id'].to_i)
|
22
|
-
|
22
|
+
job_start_log(args)
|
23
23
|
|
24
24
|
@appinstance.new_session(holding_pattern: true)
|
25
25
|
rescue ActiveRecord::RecordNotFound => exception
|
@@ -52,12 +52,12 @@ module Resque
|
|
52
52
|
return
|
53
53
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => exception
|
54
54
|
Rails.logger.warn("Enqueue Job Again ~ 2 mins", exception)
|
55
|
-
@appinstance.queue_pause(time: 2.minutes.to_i)
|
55
|
+
@appinstance.queue_pause(time: 2.minutes.to_i)
|
56
56
|
Resque.enqueue_to(self.job.queue, self.job.payload['class'], args)
|
57
57
|
return
|
58
58
|
rescue Net::ReadTimeout, Net::OpenTimeout, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError => exception
|
59
59
|
Rails.logger.warn("Enqueue Job Again ~ 2 mins", exception)
|
60
|
-
@appinstance.queue_pause(time: 2.minutes.to_i)
|
60
|
+
@appinstance.queue_pause(time: 2.minutes.to_i)
|
61
61
|
Resque.enqueue_to(self.job.queue, self.job.payload['class'], args)
|
62
62
|
return
|
63
63
|
end
|
@@ -68,6 +68,10 @@ module Resque
|
|
68
68
|
@appinstance.cache_app_instance if defined?(@appinstance)
|
69
69
|
Rails.logger.flush if Rails.logger.methods.include?(:flush)
|
70
70
|
end
|
71
|
+
|
72
|
+
def job_start_log(args)
|
73
|
+
Rails.logger.info("Starting job")
|
74
|
+
end
|
71
75
|
end
|
72
76
|
end
|
73
|
-
end
|
77
|
+
end
|
@@ -17,7 +17,7 @@ module Resque
|
|
17
17
|
when "Hash"
|
18
18
|
data = args.merge({:worker_class => self.to_s})
|
19
19
|
end
|
20
|
-
if Rails.logger.is_a?(Ougai::Logger)
|
20
|
+
if Rails.logger.is_a?(Ougai::Logger) && !Rails.env.development?
|
21
21
|
Rails.logger.with_fields = {job: data, trace_id: SecureRandom.uuid, name: "RailsWorker"}
|
22
22
|
end
|
23
23
|
data = {:msg => 'Starting job', :job => data}
|
data/lib/zuora_connect.rb
CHANGED
@@ -9,12 +9,11 @@ require 'resque/silence_done'
|
|
9
9
|
require 'resque/self_lookup'
|
10
10
|
require 'resque/plugins/custom_logger'
|
11
11
|
require 'resque/plugins/app_instance_job'
|
12
|
-
require 'logging/connect_formatter'
|
13
|
-
require 'metrics/influx/point_value'
|
14
12
|
require 'metrics/net'
|
15
13
|
require 'mono_logger'
|
16
14
|
require 'zuora_connect/zuora_audit'
|
17
15
|
require 'active_record'
|
16
|
+
require 'zuora_observability'
|
18
17
|
::ActiveRecord::Base.send :include, ZuoraConnect::ZuoraAudit
|
19
18
|
|
20
19
|
module ZuoraConnect
|
@@ -29,68 +28,9 @@ module ZuoraConnect
|
|
29
28
|
when 'test'
|
30
29
|
Rails.logger
|
31
30
|
else
|
32
|
-
@logger ||= custom_logger(name: "Connect", level: Rails.logger.level)
|
31
|
+
@logger ||= ZuoraObservability::Logger.custom_logger(name: "Connect", level: Rails.logger.level)
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
36
|
-
def custom_logger(name: "", level: Rails.logger.present? ? Rails.logger.level : MonoLogger::INFO, type: :ougai)
|
37
|
-
#puts name + ' - ' + {Logger::WARN => 'Logger::WARN', Logger::ERROR => 'Logger::ERROR', Logger::DEBUG => 'Logger::DEBUG', Logger::INFO => 'Logger::INFO' }[level] + ' - '
|
38
|
-
if type == :ougai
|
39
|
-
require 'ougai'
|
40
|
-
require "ougai/formatters/customizable"
|
41
|
-
#logger = Ougai::Logger.new(MonoLogger.new(STDOUT))
|
42
|
-
logger = Ougai::Logger.new(STDOUT)
|
43
|
-
logger.level = level
|
44
|
-
if ZuoraConnect.configuration.json_logging
|
45
|
-
logger.formatter = Ougai::Formatters::ConnectFormatter.new(name)
|
46
|
-
logger.before_log = lambda do |data|
|
47
|
-
data[:trace_id] = ZuoraConnect::RequestIdMiddleware.request_id if ZuoraConnect::RequestIdMiddleware.request_id.present?
|
48
|
-
data[:zuora_trace_id] = ZuoraConnect::RequestIdMiddleware.zuora_request_id if ZuoraConnect::RequestIdMiddleware.zuora_request_id.present?
|
49
|
-
#data[:traces] = {amazon_id: data[:trace_id], zuora_id: data[:zuora_trace_id]}
|
50
|
-
end
|
51
|
-
else
|
52
|
-
logger.formatter = Ougai::Formatters::Customizable.new(
|
53
|
-
format_err: proc do |data|
|
54
|
-
next nil unless data.key?(:err)
|
55
|
-
err = data.delete(:err)
|
56
|
-
" #{err[:name]} (#{err[:message]})\n #{err[:stack]}"
|
57
|
-
end,
|
58
|
-
format_data: proc do |data|
|
59
|
-
data.delete(:app_instance_id); data.delete(:tenant_ids); data.delete(:organization); data.delete(:environment)
|
60
|
-
format('%s %s: %s', 'DATA'.ljust(6), Time.now.strftime('%FT%T.%6NZ'), "#{data.to_json}") if data.present?
|
61
|
-
end,
|
62
|
-
format_msg: proc do |severity, datetime, _progname, data|
|
63
|
-
msg = data.delete(:msg)
|
64
|
-
format('%s %s: %s', severity.ljust(6), datetime, msg)
|
65
|
-
end
|
66
|
-
)
|
67
|
-
logger.formatter.datetime_format = '%FT%T.%6NZ'
|
68
|
-
end
|
69
|
-
else
|
70
|
-
logger = MonoLogger.new(STDOUT)
|
71
|
-
logger.level = level
|
72
|
-
logger.formatter = proc do |serverity, datetime, progname, msg|
|
73
|
-
begin
|
74
|
-
msg = JSON.parse(msg)
|
75
|
-
rescue JSON::ParserError => ex
|
76
|
-
end
|
77
|
-
if ZuoraConnect.configuration.json_logging
|
78
|
-
require 'json'
|
79
|
-
store = {
|
80
|
-
name: name,
|
81
|
-
level: serverity,
|
82
|
-
timestamp: datetime.strftime('%FT%T.%6NZ'),
|
83
|
-
pid: Process.pid,
|
84
|
-
message: name == "ActionMailer" ? msg.strip : msg
|
85
|
-
}
|
86
|
-
JSON.dump(store) + "\n"
|
87
|
-
else
|
88
|
-
format('%s %s: %s', serverity.ljust(6), datetime, msg) + "\n"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
return logger
|
93
|
-
end
|
94
34
|
end
|
95
35
|
|
96
36
|
module Controllers
|
@@ -147,7 +87,7 @@ module ZuoraConnect
|
|
147
87
|
verify_server_cert: false,
|
148
88
|
log_level: Logger::INFO,
|
149
89
|
service_name: ENV['DEIS_APP'].present? ? ENV['DEIS_APP'] : Rails.application.class.parent_name,
|
150
|
-
logger:
|
90
|
+
logger: ZuoraObservability::Logger.custom_logger(name: "ElasticAPM", level: MonoLogger::WARN)
|
151
91
|
})
|
152
92
|
defaults.merge!({disable_send: true}) if defined?(Rails::Console)
|
153
93
|
|
@@ -138,12 +138,8 @@ module ZuoraConnect
|
|
138
138
|
end
|
139
139
|
ZuoraConnect.logger.error(ex) if !ZuoraConnect::AppInstance::IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
|
140
140
|
end
|
141
|
-
|
142
|
-
|
143
|
-
Time.zone = session["#{@appinstance.id}::user::timezone"] ? session["#{@appinstance.id}::user::timezone"] : @appinstance.timezone
|
144
|
-
end
|
145
|
-
rescue
|
146
|
-
ZuoraConnect.logger.error(ex)
|
141
|
+
if @appinstance.user_timezone.blank?
|
142
|
+
@appinstance.set_timezone(timezone: session["#{@appinstance.id}::user::timezone"], type: :default)
|
147
143
|
end
|
148
144
|
end
|
149
145
|
rescue ZuoraConnect::Exceptions::InvalidCredentialSet => ex
|
@@ -306,7 +302,8 @@ module ZuoraConnect
|
|
306
302
|
private
|
307
303
|
def setup_instance_via_prod_mode
|
308
304
|
zuora_entity_id = request.headers['ZuoraCurrentEntity'] || cookies['ZuoraCurrentEntity']
|
309
|
-
|
305
|
+
ZuoraConnect::ZuoraUser.current_user_id = nil
|
306
|
+
|
310
307
|
if zuora_entity_id.present?
|
311
308
|
zuora_tenant_id = cookies['Zuora-Tenant-Id']
|
312
309
|
zuora_user_id = cookies['Zuora-User-Id']
|
@@ -681,27 +678,30 @@ module ZuoraConnect
|
|
681
678
|
|
682
679
|
def setup_instance_via_dev_mode
|
683
680
|
session["appInstance"] = ZuoraConnect.configuration.dev_mode_appinstance
|
684
|
-
|
685
|
-
|
686
|
-
values = {
|
687
|
-
|
681
|
+
session["#{ZuoraConnect.configuration.dev_mode_appinstance}::admin"] = ZuoraConnect.configuration.dev_mode_admin
|
682
|
+
|
683
|
+
values = {
|
684
|
+
id: ZuoraConnect.configuration.dev_mode_appinstance,
|
685
|
+
access_token: ZuoraConnect.configuration.dev_mode_user,
|
686
|
+
refresh_token: ZuoraConnect.configuration.dev_mode_pass,
|
687
|
+
token: ZuoraConnect.configuration.dev_mode_pass+ZuoraConnect.configuration.dev_mode_pass,
|
688
|
+
api_token: ZuoraConnect.configuration.dev_mode_pass+ZuoraConnect.configuration.dev_mode_pass
|
689
|
+
}
|
690
|
+
|
691
|
+
@appinstance = ZuoraConnect::AppInstance.find_by(:id => ZuoraConnect.configuration.dev_mode_appinstance.to_i)
|
688
692
|
ZuoraConnect::ZuoraUser.current_user_id = 0
|
689
693
|
if @appinstance.blank?
|
690
694
|
Apartment::Tenant.switch!("public")
|
691
695
|
begin
|
692
|
-
Apartment::Tenant.create(
|
696
|
+
Apartment::Tenant.create(ZuoraConnect.configuration.dev_mode_appinstance.to_s)
|
693
697
|
rescue Apartment::TenantExists => ex
|
694
|
-
Apartment::Tenant.drop(
|
698
|
+
Apartment::Tenant.drop(ZuoraConnect.configuration.dev_mode_appinstance.to_s)
|
695
699
|
retry
|
696
700
|
end
|
697
|
-
|
698
|
-
@appinstance = ZuoraConnect::AppInstance.new(:id => values[:appinstance].to_i, :access_token => values[:user], :refresh_token => values[:key], :token => "#{values[:key]}#{values[:key]}", :api_token => "#{values[:key]}#{values[:key]}")
|
699
|
-
@appinstance.save(:validate => false)
|
700
|
-
end
|
701
|
-
if @appinstance.access_token.blank? || @appinstance.refresh_token.blank? || @appinstance.token.blank? || @appinstance.api_token.blank?
|
702
|
-
@appinstance.update_attributes!(:access_token => values["user"], :refresh_token => values["key"], :token => "#{values[:key]}#{values[:key]}", :api_token => "#{values[:key]}#{values[:key]}")
|
701
|
+
@appinstance = ZuoraConnect::AppInstance.new()
|
703
702
|
end
|
704
|
-
|
703
|
+
@appinstance.assign_attributes(values)
|
704
|
+
@appinstance.save(:validate => false)
|
705
705
|
end
|
706
706
|
end
|
707
707
|
end
|
data/lib/zuora_connect/engine.rb
CHANGED
@@ -10,9 +10,10 @@ module ZuoraConnect
|
|
10
10
|
|
11
11
|
initializer "connect", before: :load_config_initializers do |app|
|
12
12
|
Rails.application.routes.prepend do
|
13
|
+
get '/connect/internal/data' => 'zuora_observability/metrics#metrics'
|
13
14
|
mount ZuoraConnect::Engine, at: "/connect"
|
14
15
|
match '/api/connect/health', via: :all, to: 'zuora_connect/static#health'
|
15
|
-
match '/api/connect/internal/data', via: :all, to: '
|
16
|
+
match '/api/connect/internal/data', via: :all, to: 'zuora_observability/metrics#metrics'
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
@@ -5,17 +5,6 @@ require 'middleware/bad_multipart_form_data_sanitizer'
|
|
5
5
|
|
6
6
|
module ZuoraConnect
|
7
7
|
class Railtie < Rails::Railtie
|
8
|
-
REQUEST_HEADERS_TO_IGNORE = %W(
|
9
|
-
RAW_POST_DATA
|
10
|
-
REQUEST_METHOD
|
11
|
-
REQUEST_URI
|
12
|
-
REQUEST_PATH
|
13
|
-
PATH_INFO
|
14
|
-
CONTENT_TYPE
|
15
|
-
ORIGINAL_FULLPATH
|
16
|
-
QUERY_STRING
|
17
|
-
)
|
18
|
-
|
19
8
|
config.before_initialize do
|
20
9
|
version = Rails.version
|
21
10
|
if version >= "5.0.0"
|
@@ -43,71 +32,5 @@ module ZuoraConnect
|
|
43
32
|
app.config.middleware.use Rack::Deflater, if: ->(env, *) { env['PATH_INFO'] == '/connect/internal/metrics' }
|
44
33
|
end
|
45
34
|
end
|
46
|
-
|
47
|
-
# hook to process_action
|
48
|
-
ActiveSupport::Notifications.subscribe('process_action.action_controller', ZuoraConnect::PageRequest.new)
|
49
|
-
|
50
|
-
initializer(:rails_stdout_logging, before: :initialize_logger) do
|
51
|
-
require 'lograge'
|
52
|
-
|
53
|
-
Rails.configuration.logger = ZuoraConnect.custom_logger(name: "Rails")
|
54
|
-
if !Rails.env.test? && !Rails.env.development?
|
55
|
-
Rails.configuration.lograge.enabled = true
|
56
|
-
Rails.configuration.colorize_logging = false
|
57
|
-
end
|
58
|
-
|
59
|
-
if Rails.configuration.lograge.enabled
|
60
|
-
if Rails.configuration.logger.class.to_s == 'Ougai::Logger'
|
61
|
-
Rails.configuration.lograge.formatter = Class.new do |fmt|
|
62
|
-
def fmt.call(data)
|
63
|
-
{ msg: 'Rails Request', request: data }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
#Rails.configuration.lograge.formatter = Lograge::Formatters::Json.new
|
68
|
-
Rails.configuration.lograge.custom_options = lambda do |event|
|
69
|
-
exceptions = %w(controller action format)
|
70
|
-
items = {
|
71
|
-
#time: event.time.strftime('%FT%T.%6N'),
|
72
|
-
params: event.payload[:params].as_json(except: exceptions).to_json.to_s
|
73
|
-
}
|
74
|
-
items.merge!({exception_object: event.payload[:exception_object]}) if event.payload[:exception_object].present?
|
75
|
-
items.merge!({exception: event.payload[:exception]}) if event.payload[:exception].present?
|
76
|
-
|
77
|
-
if event.payload[:headers].present?
|
78
|
-
# By convertion, headers usually do not have dots. Nginx even rejects headers with dots
|
79
|
-
# All Rails headers are namespaced, like 'rack.input'.
|
80
|
-
# Thus, we can obtain the client headers by rejecting dots
|
81
|
-
request_headers =
|
82
|
-
event.payload[:headers].env.
|
83
|
-
reject { |key| key.to_s.include?('.') || REQUEST_HEADERS_TO_IGNORE.include?(key.to_s) }
|
84
|
-
begin
|
85
|
-
if request_headers["HTTP_AUTHORIZATION"].present?
|
86
|
-
if request_headers["HTTP_AUTHORIZATION"].include?("Basic")
|
87
|
-
user_password = request_headers["HTTP_AUTHORIZATION"].split("Basic").last.strip
|
88
|
-
user, password = Base64.decode64(user_password).split(":")
|
89
|
-
request_headers["HTTP_AUTHORIZATION"] = "Basic #{user}:ValueFiltered"
|
90
|
-
elsif
|
91
|
-
request_headers["HTTP_AUTHORIZATION"] = "ValueFiltered"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
request_headers["HTTP_API_TOKEN"] = "ValueFiltered" if request_headers["HTTP_API_TOKEN"].present?
|
95
|
-
rescue
|
96
|
-
request_headers.delete("HTTP_API_TOKEN")
|
97
|
-
request_headers.delete("HTTP_AUTHORIZATION")
|
98
|
-
end
|
99
|
-
items.merge!({ headers: request_headers.to_s })
|
100
|
-
end
|
101
|
-
|
102
|
-
if Thread.current[:appinstance].present?
|
103
|
-
items.merge!({connect_user: Thread.current[:appinstance].connect_user, new_session: Thread.current[:appinstance].new_session_message})
|
104
|
-
if Thread.current[:appinstance].logitems.present? && Thread.current[:appinstance].logitems.class == Hash
|
105
|
-
items.merge!(Thread.current[:appinstance].logitems)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
return items
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
35
|
end
|
113
36
|
end
|