zuora_connect 3.0.0.pre.j → 3.0.0.pre.q
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/config/initializers/zuora_observability.rb +21 -0
- 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 +2 -2
- data/lib/zuora_connect/configuration.rb +2 -2
- data/lib/zuora_connect/controllers/helpers.rb +13 -11
- data/lib/zuora_connect/railtie.rb +3 -0
- data/lib/zuora_connect/version.rb +1 -1
- metadata +46 -145
- 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: 9348d7aa606a5c6a3100f94afd22efdb2ad2c8405342708420e0e15753cb4816
|
4
|
+
data.tar.gz: ea4ece99e78a056adb90fd21c4308e374365f0c64036e118fc78e83bdea441b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec5539d89ee66fa7d02dc64add2073c5281cd138342e28600f54085d2664bc7db7df2f9995617f5fd79607a80eb3c28e09dd0893b68d22a6355f8965a8333ff3
|
7
|
+
data.tar.gz: a3c30217361264f6c934484e550e26d9183cb7aeec362abd2da73be352dba20564f0b2dc6252af15355d307ff64440b7d9c619eab380e8ce2d0b95116a35cc3f
|
@@ -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,21 @@
|
|
1
|
+
ZuoraObservability.configure do |config|
|
2
|
+
config.zecs_service_hook = lambda do |controller|
|
3
|
+
custom_payload = {}
|
4
|
+
if controller.instance_variable_defined?(:@appinstance)
|
5
|
+
appinstance = controller.instance_variable_get(:@appinstance)
|
6
|
+
if appinstance.logitems.present? && appinstance.logitems.class == Hash
|
7
|
+
ActiveSupport::Deprecation.warn("logitems is deprecated, please use zecs_service_hook. See 'https://gitlab.zeta.tools/extension-products/incubating-projects/zuora_observability/-/blob/master/doc/logging.md' for more details.")
|
8
|
+
custom_payload.merge!(appinstance.logitems)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
custom_payload
|
12
|
+
end
|
13
|
+
config.add_custom_payload_hook do |controller|
|
14
|
+
custom_payload = {}
|
15
|
+
if controller.instance_variable_defined?(:@appinstance)
|
16
|
+
appinstance = controller.instance_variable_get(:@appinstance)
|
17
|
+
custom_payload.merge!({ email: appinstance.connect_user })
|
18
|
+
end
|
19
|
+
custom_payload
|
20
|
+
end
|
21
|
+
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,8 +9,8 @@ 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
|
-
require 'mono_logger'
|
14
14
|
require 'zuora_connect/zuora_audit'
|
15
15
|
require 'active_record'
|
16
16
|
require 'zuora_observability'
|
@@ -87,7 +87,7 @@ module ZuoraConnect
|
|
87
87
|
verify_server_cert: false,
|
88
88
|
log_level: Logger::INFO,
|
89
89
|
service_name: ENV['DEIS_APP'].present? ? ENV['DEIS_APP'] : Rails.application.class.parent_name,
|
90
|
-
logger: ZuoraObservability::Logger.custom_logger(name: "ElasticAPM", level:
|
90
|
+
logger: ZuoraObservability::Logger.custom_logger(name: "ElasticAPM", level: Logger::WARN)
|
91
91
|
})
|
92
92
|
defaults.merge!({disable_send: true}) if defined?(Rails::Console)
|
93
93
|
|