zuora_connect 3.0.0.pre.i → 3.0.0.pre.p
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/app/models/zuora_connect/app_instance_base.rb +20 -7
- data/app/models/zuora_connect/telegraf.rb +73 -0
- data/config/initializers/prometheus.rb +0 -23
- data/config/initializers/resque.rb +0 -14
- data/config/initializers/unicorn.rb +1 -1
- data/lib/metrics/influx/point_value.rb +79 -0
- data/lib/metrics/net.rb +7 -7
- data/lib/middleware/metrics_middleware.rb +34 -3
- data/lib/zuora_connect.rb +1 -0
- data/lib/zuora_connect/configuration.rb +2 -1
- data/lib/zuora_connect/controllers/helpers.rb +12 -9
- data/lib/zuora_connect/railtie.rb +3 -0
- data/lib/zuora_connect/version.rb +1 -1
- metadata +9 -103
- data/test/controllers/zuora_connect/api/v1/app_instance_controller_test.rb +0 -13
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/bin/setup +0 -29
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -26
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -41
- data/test/dummy/config/environments/production.rb +0 -79
- data/test/dummy/config/environments/test.rb +0 -42
- data/test/dummy/config/initializers/assets.rb +0 -11
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/routes.rb +0 -4
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/public/404.html +0 -67
- data/test/dummy/public/422.html +0 -67
- data/test/dummy/public/500.html +0 -66
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/zuora_connect/app_instances.yml +0 -11
- data/test/integration/navigation_test.rb +0 -8
- data/test/lib/generators/zuora_connect/datatable_generator_test.rb +0 -16
- data/test/models/zuora_connect/app_instance_test.rb +0 -9
- data/test/test_helper.rb +0 -21
- data/test/zuora_connect_test.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48c5c6950c9bae664c28fa538b8e5893fc2e477d2d0f1cb609076fe7d465ad76
|
4
|
+
data.tar.gz: 00dabe2bc4bfe823c9c17cd85e335b802c543b84b04b7ced36f9492277d45c18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0a69fc47ca4a1835e8712cc4d88c32d4208407a7bbd7e89df37d2f4bd8915b1a0665d5bf780313b40777c1b4c3c35438e908fcdeabefcca5109e8de7e2dedb6
|
7
|
+
data.tar.gz: 55e492a0fb4cc472ce7fe3f09978032ea48a4eda2f2890efeb3b681b7b55b170b7ed3867d9fab5ba44777c0437d6d4329dd060b0fb24fc959546a0e149ef61fa
|
@@ -12,6 +12,7 @@ module ZuoraConnect
|
|
12
12
|
|
13
13
|
self.table_name = "zuora_connect_app_instances"
|
14
14
|
attr_accessor :options, :mode, :logins, :task_data, :last_refresh, :username, :password, :s3_client, :api_version, :drop_message, :new_session_message, :connect_user, :logitems, :user_timezone
|
15
|
+
@@telegraf_host = nil
|
15
16
|
REFRESH_TIMEOUT = 2.minute #Used to determine how long to wait on current refresh call before executing another
|
16
17
|
INSTANCE_REFRESH_WINDOW = 1.hours #Used to set how how long till app starts attempting to refresh cached task connect data
|
17
18
|
INSTANCE_REDIS_CACHE_PERIOD = 24.hours #Used to determine how long to cached task data will live for
|
@@ -348,7 +349,7 @@ module ZuoraConnect
|
|
348
349
|
|
349
350
|
def refresh(session: {})
|
350
351
|
refresh_count ||= 0
|
351
|
-
skip_connect ||=
|
352
|
+
skip_connect ||= ZuoraConnect.configuration.skip_connect
|
352
353
|
begin
|
353
354
|
#Check how app was deployed
|
354
355
|
if !self.auto_deployed? && !skip_connect
|
@@ -362,9 +363,9 @@ module ZuoraConnect
|
|
362
363
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("JSON parse error", response.body, response.code)
|
363
364
|
end
|
364
365
|
|
365
|
-
self.build_task(task_data: parsed_json, session: session)
|
366
|
+
self.build_task(task_data: parsed_json, session: session)
|
366
367
|
self.set_backup_creds
|
367
|
-
self.save(validate: false) if self.changed?
|
368
|
+
self.save(validate: false) if self.changed?
|
368
369
|
else
|
369
370
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
370
371
|
end
|
@@ -412,8 +413,8 @@ module ZuoraConnect
|
|
412
413
|
def set_backup_creds
|
413
414
|
if self.kms_key.present? && self.kms_key.match(/^arn:aws:.*/) && self.task_data.present?
|
414
415
|
self.zuora_logins = self.strip_cache_data(object: self.task_data.dup, keys: ['applications', 'tokens', 'user_settings'])
|
415
|
-
end
|
416
|
-
end
|
416
|
+
end
|
417
|
+
end
|
417
418
|
|
418
419
|
def zuora_logins=(val)
|
419
420
|
write_attribute(:zuora_logins, kms_encrypt(val.to_json))
|
@@ -478,6 +479,15 @@ module ZuoraConnect
|
|
478
479
|
end
|
479
480
|
Thread.current[:appinstance] = self
|
480
481
|
end
|
482
|
+
|
483
|
+
def self.write_to_telegraf(*args)
|
484
|
+
if ZuoraConnect.configuration.enable_metrics && !defined?(Prometheus)
|
485
|
+
@@telegraf_host = ZuoraConnect::Telegraf.new() if @@telegraf_host == nil
|
486
|
+
unicorn_stats = ZuoraObservability::Metrics.unicorn_listener if defined?(Unicorn) && Unicorn.respond_to?(:listener_names)
|
487
|
+
@@telegraf_host.write(direction: 'Raindrops', tags: {}, values: unicorn_stats) unless unicorn_stats.blank?
|
488
|
+
return @@telegraf_host.write(*args)
|
489
|
+
end
|
490
|
+
end
|
481
491
|
#### END Task Methods ####
|
482
492
|
|
483
493
|
#### START Task Methods ####
|
@@ -600,7 +610,10 @@ module ZuoraConnect
|
|
600
610
|
self.provisioned_app = nil
|
601
611
|
end
|
602
612
|
end
|
603
|
-
self.
|
613
|
+
if self.changed?
|
614
|
+
self.save(:validate => false)
|
615
|
+
self.refresh
|
616
|
+
end
|
604
617
|
|
605
618
|
return parsed_json
|
606
619
|
end
|
@@ -1029,7 +1042,7 @@ module ZuoraConnect
|
|
1029
1042
|
catalog_container = catalog_container[object_id]
|
1030
1043
|
end
|
1031
1044
|
|
1032
|
-
return catalog_container
|
1045
|
+
return catalog_container || {}
|
1033
1046
|
end
|
1034
1047
|
|
1035
1048
|
if defined?(Redis.current) && object_id.present? && object_id.class == String && object_id.present?
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module ZuoraConnect
|
2
|
+
class Telegraf
|
3
|
+
attr_accessor :host
|
4
|
+
|
5
|
+
OUTBOUND_METRICS = true
|
6
|
+
OUTBOUND_METRICS_NAME = "request-outbound"
|
7
|
+
INBOUND_METRICS = true
|
8
|
+
INBOUND_METRICS_NAME = "request-inbound"
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.connect
|
12
|
+
end
|
13
|
+
|
14
|
+
def connect
|
15
|
+
ZuoraConnect.logger.debug(self.format_metric_log('Telegraf','Need new connection')) if ZuoraConnect.configuration.telegraf_debug
|
16
|
+
uri = URI.parse(ZuoraConnect.configuration.telegraf_endpoint)
|
17
|
+
self.host = UDPSocket.new.tap do |socket|
|
18
|
+
socket.connect uri.host, uri.port
|
19
|
+
end
|
20
|
+
rescue => ex
|
21
|
+
self.host = nil
|
22
|
+
ZuoraConnect.logger.warn(self.format_metric_log('Telegraf', "Failed to connect: #{ex.class}")) if Rails.env.to_s != 'production'
|
23
|
+
end
|
24
|
+
|
25
|
+
def write(direction: 'Unknown', tags: {}, values: {})
|
26
|
+
time = Benchmark.measure do |bench|
|
27
|
+
# To avoid writing metrics from rspec tests
|
28
|
+
if Rails.env.to_sym != :test
|
29
|
+
app_instance = Thread.current[:appinstance].present? ? Thread.current[:appinstance].id : 0
|
30
|
+
tags = { app_name: ZuoraObservability::Env.app_name, process_type: ZuoraObservability::Env.process_type, app_instance: app_instance, pod_name: ZuoraObservability::Env.pod_name}.merge(tags)
|
31
|
+
|
32
|
+
if direction == :inbound
|
33
|
+
if INBOUND_METRICS && !Thread.current[:inbound_metric].to_bool
|
34
|
+
self.write_udp(series: INBOUND_METRICS_NAME, tags: tags, values: values)
|
35
|
+
Thread.current[:inbound_metric] = true
|
36
|
+
else
|
37
|
+
return
|
38
|
+
end
|
39
|
+
elsif direction == :outbound
|
40
|
+
self.write_udp(series: OUTBOUND_METRICS_NAME, tags: tags, values: values) if OUTBOUND_METRICS
|
41
|
+
else
|
42
|
+
self.write_udp(series: direction, tags: tags, values: values)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
if ZuoraConnect.configuration.telegraf_debug
|
47
|
+
ZuoraConnect.logger.debug(self.format_metric_log('Telegraf', tags.to_s))
|
48
|
+
ZuoraConnect.logger.debug(self.format_metric_log('Telegraf', values.to_s))
|
49
|
+
ZuoraConnect.logger.debug(self.format_metric_log('Telegraf', "Writing '#{direction.capitalize}': #{time.real.round(5)} ms"))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def write_udp(series: '', tags: {}, values: {})
|
55
|
+
return if !values.present?
|
56
|
+
self.host.write InfluxDB::PointValue.new({series: series, tags: tags, values: values}).dump
|
57
|
+
rescue => ex
|
58
|
+
self.connect
|
59
|
+
ZuoraConnect.logger.warn(self.format_metric_log('Telegraf',"Failed to write udp: #{ex.class}")) if Rails.env.to_s != 'production'
|
60
|
+
end
|
61
|
+
|
62
|
+
def format_metric_log(message, dump = nil)
|
63
|
+
message_color, dump_color = "1;91", "0;1"
|
64
|
+
log_entry = " \e[#{message_color}m#{message}\e[0m "
|
65
|
+
log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
|
66
|
+
if Rails.env == :development
|
67
|
+
log_entry
|
68
|
+
else
|
69
|
+
[message, dump].compact.join(' - ')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -15,29 +15,6 @@ if defined? Prometheus
|
|
15
15
|
dir: prometheus_path
|
16
16
|
)
|
17
17
|
|
18
|
-
class ResqueExporter
|
19
|
-
require 'prometheus/client/formats/text'
|
20
|
-
require 'fileutils'
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
@lock = Monitor.new
|
24
|
-
@registry = Prometheus::Client.registry
|
25
|
-
@path = ENV['RESQUE_EXPORTER_PATH'] || Rails.root.join('tmp/resque_exporter')
|
26
|
-
FileUtils.mkdir_p(@path)
|
27
|
-
end
|
28
|
-
|
29
|
-
def export
|
30
|
-
filename = File.join(@path, 'resque_export.prom')
|
31
|
-
@lock.synchronize do
|
32
|
-
File.open(filename, 'w+') do |file|
|
33
|
-
file.write(Prometheus::Client::Formats::Text.marshal(@registry))
|
34
|
-
end
|
35
|
-
end
|
36
|
-
rescue
|
37
|
-
# Ignored
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
18
|
most_recent_aggregation = {}
|
42
19
|
sum_aggregation = {}
|
43
20
|
if defined?(Unicorn)
|
@@ -5,20 +5,6 @@ if defined?(Resque::Worker)
|
|
5
5
|
Resque::Job.send(:include, Resque::SelfLookup)
|
6
6
|
end
|
7
7
|
|
8
|
-
if defined?(Resque::Job) && defined?(Prometheus)
|
9
|
-
module ResquePrometheusExtensions
|
10
|
-
EXPORTER = Prometheus::ResqueExporter.new
|
11
|
-
def perform
|
12
|
-
super
|
13
|
-
EXPORTER.export
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Resque::Job
|
18
|
-
prepend ResquePrometheusExtensions
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
8
|
Resque.module_eval do
|
23
9
|
# Returns a hash, mapping queue names to queue sizes
|
24
10
|
def queue_sizes
|
@@ -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
|
+
ZuoraConnect::AppInstance.write_to_telegraf(direction: 'Unicorn-Killer', tags: {app_instance: 0}, values: {kill: 1})
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module InfluxDB
|
2
|
+
# Convert data point to string using Line protocol
|
3
|
+
class PointValue
|
4
|
+
attr_reader :series, :values, :tags, :timestamp
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@series = escape data[:series], :measurement
|
8
|
+
@values = escape_values data[:values]
|
9
|
+
@tags = escape_tags data[:tags]
|
10
|
+
@timestamp = data[:timestamp]
|
11
|
+
end
|
12
|
+
|
13
|
+
def dump
|
14
|
+
dump = @series.dup
|
15
|
+
dump << ",#{@tags}" if @tags
|
16
|
+
dump << " #{@values}"
|
17
|
+
dump << " #{@timestamp}" if @timestamp
|
18
|
+
dump
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
ESCAPES = {
|
24
|
+
measurement: [' '.freeze, ','.freeze],
|
25
|
+
tag_key: ['='.freeze, ' '.freeze, ','.freeze],
|
26
|
+
tag_value: ['='.freeze, ' '.freeze, ','.freeze],
|
27
|
+
field_key: ['='.freeze, ' '.freeze, ','.freeze, '"'.freeze],
|
28
|
+
field_value: ["\\".freeze, '"'.freeze],
|
29
|
+
}.freeze
|
30
|
+
|
31
|
+
private_constant :ESCAPES
|
32
|
+
|
33
|
+
def escape(str, type)
|
34
|
+
# rubocop:disable Layout/AlignParameters
|
35
|
+
str = str.encode "UTF-8".freeze, "UTF-8".freeze,
|
36
|
+
invalid: :replace,
|
37
|
+
undef: :replace,
|
38
|
+
replace: "".freeze
|
39
|
+
# rubocop:enable Layout/AlignParameters
|
40
|
+
|
41
|
+
ESCAPES[type].each do |ch|
|
42
|
+
str = str.gsub(ch) { "\\#{ch}" }
|
43
|
+
end
|
44
|
+
str
|
45
|
+
end
|
46
|
+
|
47
|
+
def escape_values(values)
|
48
|
+
return if values.nil?
|
49
|
+
values.map do |k, v|
|
50
|
+
key = escape(k.to_s, :field_key)
|
51
|
+
val = escape_value(v)
|
52
|
+
"#{key}=#{val}"
|
53
|
+
end.join(",".freeze)
|
54
|
+
end
|
55
|
+
|
56
|
+
def escape_value(value)
|
57
|
+
if value.is_a?(String)
|
58
|
+
'"'.freeze + escape(value, :field_value) + '"'.freeze
|
59
|
+
elsif value.is_a?(Integer)
|
60
|
+
"#{value}i"
|
61
|
+
else
|
62
|
+
value.to_s
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def escape_tags(tags)
|
67
|
+
return if tags.nil?
|
68
|
+
|
69
|
+
tags = tags.map do |k, v|
|
70
|
+
key = escape(k.to_s, :tag_key)
|
71
|
+
val = escape(v.to_s, :tag_value)
|
72
|
+
|
73
|
+
"#{key}=#{val}" unless key == "".freeze || val == "".freeze
|
74
|
+
end.compact
|
75
|
+
|
76
|
+
tags.join(",") unless tags.empty?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
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
|
+
ZuoraConnect::AppInstance.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,6 +1,37 @@
|
|
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
|
+
|
4
35
|
class MetricsMiddleware
|
5
36
|
|
6
37
|
require "zuora_connect/version"
|
@@ -36,9 +67,9 @@ module ZuoraConnect
|
|
36
67
|
if defined?(Prometheus) && env['PATH_INFO'] == '/connect/internal/metrics'
|
37
68
|
|
38
69
|
# Prometheus Stuff
|
39
|
-
metrics = ZuoraObservability::Metrics.resque
|
70
|
+
metrics = ZuoraObservability::Metrics.resque
|
40
71
|
metrics = defined?(ZuoraConnect::AppInstance.get_metrics) ? ZuoraConnect::AppInstance.get_metrics(metrics) : metrics
|
41
|
-
|
72
|
+
|
42
73
|
redis_up = metrics.present? && metrics.dig(:Resque, :Workers_Total).present? ? 1 : 0
|
43
74
|
Prometheus::REDIS_CONNECTION.set(redis_up)
|
44
75
|
|
@@ -77,7 +108,7 @@ module ZuoraConnect
|
|
77
108
|
|
78
109
|
values = {response_time: ((Time.now - start_time)*1000).round(2) }
|
79
110
|
|
80
|
-
|
111
|
+
ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
|
81
112
|
end
|
82
113
|
end
|
83
114
|
Thread.current[:inbound_metric] = nil
|
data/lib/zuora_connect.rb
CHANGED
@@ -9,6 +9,7 @@ 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 'metrics/influx/point_value'
|
12
13
|
require 'metrics/net'
|
13
14
|
require 'mono_logger'
|
14
15
|
require 'zuora_connect/zuora_audit'
|
@@ -7,7 +7,7 @@ module ZuoraConnect
|
|
7
7
|
|
8
8
|
attr_accessor :oauth_client_id, :oauth_client_secret, :oauth_client_redirect_uri
|
9
9
|
|
10
|
-
attr_accessor :dev_mode_logins, :dev_mode_options, :dev_mode_mode, :dev_mode_appinstance, :dev_mode_user, :dev_mode_pass, :dev_mode_admin, :dev_mode_secret_access_key,:dev_mode_access_key_id,:aws_region, :s3_bucket_name, :s3_folder_name, :json_logging, :insert_migrations
|
10
|
+
attr_accessor :dev_mode_logins, :dev_mode_options, :dev_mode_mode, :dev_mode_appinstance, :dev_mode_user, :dev_mode_pass, :dev_mode_admin, :dev_mode_secret_access_key,:dev_mode_access_key_id,:aws_region, :s3_bucket_name, :s3_folder_name, :json_logging, :insert_migrations, :skip_connect
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@default_locale = :en
|
@@ -20,6 +20,7 @@ module ZuoraConnect
|
|
20
20
|
@silencer_resque_finish = true
|
21
21
|
@blpop_queue = false
|
22
22
|
@insert_migrations = true
|
23
|
+
@skip_connect = false
|
23
24
|
|
24
25
|
# Setting the app name for telegraf write
|
25
26
|
@enable_metrics = false
|
@@ -125,7 +125,7 @@ module ZuoraConnect
|
|
125
125
|
PaperTrail.whodunnit = session["#{@appinstance.id}::user::email"] if defined?(PaperTrail)
|
126
126
|
end
|
127
127
|
|
128
|
-
locale = (session["#{@appinstance.id}::user::locale"] || "").gsub("_", "-")
|
128
|
+
locale = (session["#{@appinstance.id}::user::locale"] || "").gsub("_", "-")
|
129
129
|
begin
|
130
130
|
I18n.locale = locale.present? ? locale : @appinstance.locale
|
131
131
|
rescue I18n::InvalidLocale => ex
|
@@ -280,6 +280,7 @@ module ZuoraConnect
|
|
280
280
|
next_instance_id,
|
281
281
|
zuora_entity_id,
|
282
282
|
rest_domain,
|
283
|
+
tenant_id: request.headers['zuora-tenant-id'],
|
283
284
|
retry_count: retry_count
|
284
285
|
)
|
285
286
|
rescue ActiveRecord::RecordNotUnique
|
@@ -302,6 +303,7 @@ module ZuoraConnect
|
|
302
303
|
private
|
303
304
|
def setup_instance_via_prod_mode
|
304
305
|
zuora_entity_id = request.headers['ZuoraCurrentEntity'] || cookies['ZuoraCurrentEntity']
|
306
|
+
ZuoraConnect::ZuoraUser.current_user_id = nil
|
305
307
|
|
306
308
|
if zuora_entity_id.present?
|
307
309
|
zuora_tenant_id = cookies['Zuora-Tenant-Id']
|
@@ -417,7 +419,6 @@ module ZuoraConnect
|
|
417
419
|
if defined?(@appinstance) && !@appinstance['zuora_logins'].nil?
|
418
420
|
#Add user/update
|
419
421
|
begin
|
420
|
-
ZuoraConnect::ZuoraUser.reset_table_name
|
421
422
|
@zuora_user = ZuoraConnect::ZuoraUser.where(:zuora_user_id => zuora_user_id).first
|
422
423
|
rescue ActiveRecord::StatementInvalid => ex
|
423
424
|
if ex.message.include?("PG::UndefinedTable") && ex.message.include?("zuora_users")
|
@@ -636,7 +637,7 @@ module ZuoraConnect
|
|
636
637
|
(ZuoraConnect::AppInstance.all.where("id > #{min_instance_id}").order(id: :desc).limit(1).pluck(:id).first || min_instance_id) + 1
|
637
638
|
end
|
638
639
|
|
639
|
-
def new_instance(id, zuora_entity_id, rest_domain, task_data: nil, retry_count: 0)
|
640
|
+
def new_instance(id, zuora_entity_id, rest_domain, tenant_id: nil, task_data: nil, retry_count: 0)
|
640
641
|
app_instance = ZuoraConnect::AppInstance.new(
|
641
642
|
:id => id,
|
642
643
|
:api_token => generate_token,
|
@@ -646,6 +647,8 @@ module ZuoraConnect
|
|
646
647
|
:zuora_entity_ids => [zuora_entity_id]
|
647
648
|
)
|
648
649
|
|
650
|
+
app_instance[:zuora_tenant_ids] = [tenant_id.to_s] if tenant_id.present?
|
651
|
+
|
649
652
|
if task_data.nil?
|
650
653
|
# no encryption
|
651
654
|
app_instance['zuora_logins'] = task_data
|
@@ -678,15 +681,15 @@ module ZuoraConnect
|
|
678
681
|
def setup_instance_via_dev_mode
|
679
682
|
session["appInstance"] = ZuoraConnect.configuration.dev_mode_appinstance
|
680
683
|
session["#{ZuoraConnect.configuration.dev_mode_appinstance}::admin"] = ZuoraConnect.configuration.dev_mode_admin
|
681
|
-
|
684
|
+
|
682
685
|
values = {
|
683
686
|
id: ZuoraConnect.configuration.dev_mode_appinstance,
|
684
|
-
access_token: ZuoraConnect.configuration.dev_mode_user,
|
685
|
-
refresh_token: ZuoraConnect.configuration.dev_mode_pass,
|
686
|
-
token: ZuoraConnect.configuration.dev_mode_pass+ZuoraConnect.configuration.dev_mode_pass,
|
687
|
+
access_token: ZuoraConnect.configuration.dev_mode_user,
|
688
|
+
refresh_token: ZuoraConnect.configuration.dev_mode_pass,
|
689
|
+
token: ZuoraConnect.configuration.dev_mode_pass+ZuoraConnect.configuration.dev_mode_pass,
|
687
690
|
api_token: ZuoraConnect.configuration.dev_mode_pass+ZuoraConnect.configuration.dev_mode_pass
|
688
691
|
}
|
689
|
-
|
692
|
+
|
690
693
|
@appinstance = ZuoraConnect::AppInstance.find_by(:id => ZuoraConnect.configuration.dev_mode_appinstance.to_i)
|
691
694
|
ZuoraConnect::ZuoraUser.current_user_id = 0
|
692
695
|
if @appinstance.blank?
|
@@ -704,4 +707,4 @@ module ZuoraConnect
|
|
704
707
|
end
|
705
708
|
end
|
706
709
|
end
|
707
|
-
end
|
710
|
+
end
|