zuora_connect 2.0.60u → 3.0.0l
Sign up to get free protection for your applications and to get access to all the features.
- 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 +31 -106
- 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 +22 -15
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9a8f69b209e1762d0c1972e864b17330becc946114bd8c78313bf5221e7f4fc
|
4
|
+
data.tar.gz: ff25b1fe4224b67bd2e8c387406a04237b9828e3e21adf3ed75ab282694f061d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13fb0d5ad358b91fa77a23fe72091482df39bf2dbd5acc846419666550d7f1d1078cf1e150444237c3554eebb1c8d6484beec541562ce1e5180507a1cbd8a6da
|
7
|
+
data.tar.gz: 99007a267042763f665a2d195e160682a346d96388f081c548f26c6730a7c0ef6adc9633e9576f230ac4665e91e073289de110a212e9f41f66e964704e55e6f1
|
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
15
15
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
16
16
|
end
|
17
17
|
|
18
|
-
APP_RAKEFILE = File.expand_path("../
|
18
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
19
19
|
load 'rails/tasks/engine.rake'
|
20
20
|
|
21
21
|
|
@@ -1,16 +1,12 @@
|
|
1
1
|
module ZuoraConnect
|
2
2
|
class StaticController < ApplicationController
|
3
|
-
before_action :authenticate_connect_app_request, :except => [:
|
4
|
-
before_action :clear_connect_app_session, :only => [:
|
5
|
-
after_action :persist_connect_app_session, :except => [:
|
3
|
+
before_action :authenticate_connect_app_request, :except => [:health, :initialize_app, :provision, :instance_user]
|
4
|
+
before_action :clear_connect_app_session, :only => [:health, :initialize_app, :provision, :instance_user]
|
5
|
+
after_action :persist_connect_app_session, :except => [:health, :initialize_app, :provision, :instance_user]
|
6
6
|
|
7
7
|
skip_before_action :verify_authenticity_token, :only => [:initialize_app, :provision]
|
8
8
|
http_basic_authenticate_with name: ENV['PROVISION_USER'], password: ENV['PROVISION_SECRET'], :only => [:provision, :instance_user]
|
9
9
|
|
10
|
-
def metrics
|
11
|
-
type = params[:type].present? ? params[:type] : "versions"
|
12
|
-
render json: ZuoraConnect::AppInstance.get_metrics(type).to_json, status: 200
|
13
|
-
end
|
14
10
|
|
15
11
|
def health
|
16
12
|
if params[:error].present?
|
@@ -12,7 +12,6 @@ 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
|
16
15
|
REFRESH_TIMEOUT = 2.minute #Used to determine how long to wait on current refresh call before executing another
|
17
16
|
INSTANCE_REFRESH_WINDOW = 1.hours #Used to set how how long till app starts attempting to refresh cached task connect data
|
18
17
|
INSTANCE_REDIS_CACHE_PERIOD = 24.hours #Used to determine how long to cached task data will live for
|
@@ -35,7 +34,7 @@ module ZuoraConnect
|
|
35
34
|
Aws::Errors::MissingCredentialsError,
|
36
35
|
Aws::S3::Errors::AccessDenied,
|
37
36
|
Aws::SES::Errors::AccessDenied,
|
38
|
-
Aws::KMS::Errors::AccessDeniedException
|
37
|
+
Aws::KMS::Errors::AccessDeniedException
|
39
38
|
].freeze
|
40
39
|
AWS_AUTH_ERRORS_MSG = "AWS Auth Errors".freeze
|
41
40
|
|
@@ -153,7 +152,8 @@ module ZuoraConnect
|
|
153
152
|
if ZuoraConnect.configuration.mode != "Production"
|
154
153
|
mock_task_data = {
|
155
154
|
"id" => ZuoraConnect.configuration.dev_mode_appinstance,
|
156
|
-
"mode" => ZuoraConnect.configuration.dev_mode_mode
|
155
|
+
"mode" => ZuoraConnect.configuration.dev_mode_mode,
|
156
|
+
"name" => "Developer Instance"
|
157
157
|
}
|
158
158
|
|
159
159
|
case ZuoraConnect.configuration.dev_mode_options.class
|
@@ -169,6 +169,7 @@ module ZuoraConnect
|
|
169
169
|
end
|
170
170
|
|
171
171
|
self.build_task(task_data: mock_task_data, session: session)
|
172
|
+
self.set_backup_creds if !self['zuora_logins'].present?
|
172
173
|
self.last_refresh = Time.now.to_i
|
173
174
|
else
|
174
175
|
time_expire = (session["#{self.id}::last_refresh"] || Time.now).to_i - INSTANCE_REFRESH_WINDOW.ago.to_i
|
@@ -263,7 +264,7 @@ module ZuoraConnect
|
|
263
264
|
end
|
264
265
|
|
265
266
|
params = {
|
266
|
-
name: self.task_data.dig('name'),
|
267
|
+
name: self.task_data.dig('name'),
|
267
268
|
zuora_entity_ids: (self.task_data.dig(LOGIN_TENANT_DESTINATION,'entities') || []).map{|e| e['id']}.uniq,
|
268
269
|
zuora_tenant_ids: tenants.map(&:to_s).uniq,
|
269
270
|
organizations: organizations
|
@@ -272,7 +273,7 @@ module ZuoraConnect
|
|
272
273
|
client = self.send(LOGIN_TENANT_DESTINATION).client
|
273
274
|
if defined?(client.rest_domain)
|
274
275
|
ZuoraConnect::RequestIdMiddleware.zuora_rest_domain = client.rest_domain
|
275
|
-
params.merge!({zuora_domain: client.rest_domain, environment: client.environment })
|
276
|
+
params.merge!({zuora_domain: client.rest_domain, environment: client.environment })
|
276
277
|
end
|
277
278
|
end
|
278
279
|
params = params.reject{|k,v| !self.attributes.keys.member?(k.to_s) || self[k] == v}
|
@@ -290,10 +291,7 @@ module ZuoraConnect
|
|
290
291
|
elsif type == :user
|
291
292
|
begin
|
292
293
|
sql = <<-eos
|
293
|
-
SELECT zuora_users.zuora_identity_response
|
294
|
-
FROM "#{self.id}".zuora_users
|
295
|
-
ORDER BY zuora_users.updated_at DESC
|
296
|
-
LIMIT 1;
|
294
|
+
SELECT zuora_users.zuora_identity_response FROM "#{self.id}".zuora_users ORDER BY zuora_users.updated_at DESC LIMIT 1;
|
297
295
|
eos
|
298
296
|
user = ActiveRecord::Base.connection.execute(sql).to_a.first
|
299
297
|
|
@@ -301,7 +299,10 @@ module ZuoraConnect
|
|
301
299
|
zuora_identity_response = JSON.parse(user.fetch('zuora_identity_response', '{}'))
|
302
300
|
self.user_timezone = zuora_identity_response.values.first&.dig('timeZone')
|
303
301
|
else
|
304
|
-
|
302
|
+
if (Redis.current.hget(TIMEZONE_LOG_RATE_LIMIT_KEY, self.id).to_i + TIMEZONE_LOG_PERIOD.to_i) <= Time.now.to_i
|
303
|
+
Rails.logger.error('Cannot find any user to set the timezone', app_instance_id: self.id)
|
304
|
+
Redis.current.hset(TIMEZONE_LOG_RATE_LIMIT_KEY, self.id, Time.now.to_i)
|
305
|
+
end
|
305
306
|
end
|
306
307
|
rescue => ex
|
307
308
|
Rails.logger.error('There is an error while getting timezone users', ex)
|
@@ -345,12 +346,12 @@ module ZuoraConnect
|
|
345
346
|
self.id >= 25000000
|
346
347
|
end
|
347
348
|
|
348
|
-
def refresh(session: {})
|
349
|
+
def refresh(session: {})
|
349
350
|
refresh_count ||= 0
|
350
351
|
skip_connect ||= false
|
351
352
|
begin
|
352
353
|
#Check how app was deployed
|
353
|
-
if self.
|
354
|
+
if !self.auto_deployed? && !skip_connect
|
354
355
|
self.check_oauth_state
|
355
356
|
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
356
357
|
|
@@ -362,16 +363,8 @@ module ZuoraConnect
|
|
362
363
|
end
|
363
364
|
|
364
365
|
self.build_task(task_data: parsed_json, session: session)
|
365
|
-
|
366
|
-
|
367
|
-
self.zuora_logins = self.strip_cache_data(object: parsed_json.dup, keys: ['applications', 'tokens', 'user_settings'])
|
368
|
-
self.save(:validate => false)
|
369
|
-
rescue Aws::KMS::Errors::ValidationException, *AWS_AUTH_ERRORS => ex
|
370
|
-
Rails.logger.warn(AWS_AUTH_ERRORS_MSG, ex)
|
371
|
-
rescue => ex
|
372
|
-
Rails.logger.error(AWS_AUTH_ERRORS_MSG, ex)
|
373
|
-
end
|
374
|
-
end
|
366
|
+
self.set_backup_creds
|
367
|
+
self.save(validate: false) if self.changed?
|
375
368
|
else
|
376
369
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
377
370
|
end
|
@@ -416,8 +409,16 @@ module ZuoraConnect
|
|
416
409
|
end
|
417
410
|
|
418
411
|
#### START KMS ENCRYPTION Methods ####
|
412
|
+
def set_backup_creds
|
413
|
+
if self.kms_key.present? && self.kms_key.match(/^arn:aws:.*/) && self.task_data.present?
|
414
|
+
self.zuora_logins = self.strip_cache_data(object: self.task_data.dup, keys: ['applications', 'tokens', 'user_settings'])
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
419
418
|
def zuora_logins=(val)
|
420
419
|
write_attribute(:zuora_logins, kms_encrypt(val.to_json))
|
420
|
+
rescue Aws::KMS::Errors::ValidationException, Aws::KMS::Errors::NotFoundException, *AWS_AUTH_ERRORS => ex
|
421
|
+
Rails.logger.warn(AWS_AUTH_ERRORS_MSG, ex)
|
421
422
|
end
|
422
423
|
|
423
424
|
def zuora_logins
|
@@ -477,82 +478,6 @@ module ZuoraConnect
|
|
477
478
|
end
|
478
479
|
Thread.current[:appinstance] = self
|
479
480
|
end
|
480
|
-
|
481
|
-
def self.write_to_telegraf(*args)
|
482
|
-
if ZuoraConnect.configuration.enable_metrics && !defined?(Prometheus)
|
483
|
-
@@telegraf_host = ZuoraConnect::Telegraf.new() if @@telegraf_host == nil
|
484
|
-
unicorn_stats = self.unicorn_listener_stats() if defined?(Unicorn) && Unicorn.respond_to?(:listener_names)
|
485
|
-
@@telegraf_host.write(direction: 'Raindrops', tags: {}, values: unicorn_stats) unless unicorn_stats.blank?
|
486
|
-
return @@telegraf_host.write(*args)
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
def self.unicorn_listener_stats ()
|
491
|
-
stats_hash = {}
|
492
|
-
stats_hash["total_active"] = 0
|
493
|
-
stats_hash["total_queued"] = 0
|
494
|
-
|
495
|
-
begin
|
496
|
-
tmp = Unicorn.listener_names
|
497
|
-
unix = tmp.grep(%r{\A/})
|
498
|
-
tcp = tmp.grep(/\A.+:\d+\z/)
|
499
|
-
tcp = nil if tcp.empty?
|
500
|
-
unix = nil if unix.empty?
|
501
|
-
|
502
|
-
|
503
|
-
Raindrops::Linux.tcp_listener_stats(tcp).each do |addr,stats|
|
504
|
-
stats_hash["active_#{addr}"] = stats.active
|
505
|
-
stats_hash["queued_#{addr}"] = stats.queued
|
506
|
-
stats_hash["total_active"] = stats.active + stats_hash["total_active"]
|
507
|
-
stats_hash["total_queued"] = stats.queued + stats_hash["total_queued"]
|
508
|
-
end if tcp
|
509
|
-
|
510
|
-
Raindrops::Linux.unix_listener_stats(unix).each do |addr,stats|
|
511
|
-
stats_hash["active_#{addr}"] = stats.active
|
512
|
-
stats_hash["queued_#{addr}"] = stats.queued
|
513
|
-
stats_hash["total_active"] = stats.active + stats_hash["total_active"]
|
514
|
-
stats_hash["total_queued"] = stats.queued + stats_hash["total_queued"]
|
515
|
-
end if unix
|
516
|
-
rescue IOError => ex
|
517
|
-
rescue => ex
|
518
|
-
ZuoraConnect.logger.error(ex)
|
519
|
-
end
|
520
|
-
return stats_hash
|
521
|
-
end
|
522
|
-
|
523
|
-
def self.get_metrics(type)
|
524
|
-
@data = {}
|
525
|
-
|
526
|
-
if type == "versions"
|
527
|
-
@data = {
|
528
|
-
app_name: ZuoraConnect::Telegraf.app_name,
|
529
|
-
url: "dummy",
|
530
|
-
Version_Gem: ZuoraConnect::VERSION,
|
531
|
-
Version_Zuora: ZuoraAPI::VERSION ,
|
532
|
-
Version_Ruby: RUBY_VERSION,
|
533
|
-
Version_Rails: Rails.version,
|
534
|
-
hold: 1
|
535
|
-
}
|
536
|
-
elsif type == "stats"
|
537
|
-
begin
|
538
|
-
Resque.redis.ping
|
539
|
-
@resque = Resque.info
|
540
|
-
@data = {
|
541
|
-
app_name: ZuoraConnect::Telegraf.app_name,
|
542
|
-
url: "dummy",
|
543
|
-
Resque:{
|
544
|
-
Jobs_Finished: @resque[:processed] ,
|
545
|
-
Jobs_Failed: @resque[:failed],
|
546
|
-
Jobs_Pending: @resque[:pending],
|
547
|
-
Workers_Active: @resque[:working],
|
548
|
-
Workers_Total: @resque[:workers]
|
549
|
-
}
|
550
|
-
}
|
551
|
-
rescue
|
552
|
-
end
|
553
|
-
end
|
554
|
-
return @data
|
555
|
-
end
|
556
481
|
#### END Task Methods ####
|
557
482
|
|
558
483
|
#### START Task Methods ####
|
@@ -595,7 +520,7 @@ module ZuoraConnect
|
|
595
520
|
end
|
596
521
|
rescue ZuoraConnect::Exceptions::MissMatch => ex
|
597
522
|
raise
|
598
|
-
rescue ZuoraConnect::Exceptions::InvalidCredentialSet => ex
|
523
|
+
rescue ZuoraConnect::Exceptions::InvalidCredentialSet => ex
|
599
524
|
raise
|
600
525
|
rescue => ex
|
601
526
|
ZuoraConnect.logger.error("Build Task Error", ex)
|
@@ -651,12 +576,12 @@ module ZuoraConnect
|
|
651
576
|
self.refresh if !defined?(self.target_login)
|
652
577
|
|
653
578
|
response = HTTParty.get("#{ZuoraConnect.configuration.url}/api/#{self.api_version}/tenants/search?hostname=#{self.target_login.client.hostname}&node_id=#{self.zuora_entity_ids.first}")
|
654
|
-
|
579
|
+
|
655
580
|
if response.success?
|
656
581
|
parsed_json = JSON.parse(response.body)
|
657
|
-
|
582
|
+
|
658
583
|
#Set Org
|
659
|
-
if self.
|
584
|
+
if self.auto_deployed? && parsed_json['organization'].present?
|
660
585
|
login_cache = self.zuora_logins
|
661
586
|
login_cache.delete('organization')
|
662
587
|
self.zuora_logins = login_cache.merge({'organizations' => [parsed_json['organization']]})
|
@@ -676,7 +601,7 @@ module ZuoraConnect
|
|
676
601
|
end
|
677
602
|
end
|
678
603
|
self.save(:validate => false)
|
679
|
-
|
604
|
+
|
680
605
|
return parsed_json
|
681
606
|
end
|
682
607
|
rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
|
@@ -730,7 +655,7 @@ module ZuoraConnect
|
|
730
655
|
end
|
731
656
|
|
732
657
|
def refresh_oauth
|
733
|
-
refresh_oauth_count ||= 0
|
658
|
+
refresh_oauth_count ||= 0
|
734
659
|
response = HTTParty.post("#{ZuoraConnect.configuration.url}/oauth/token", body: {
|
735
660
|
:grant_type => "refresh_token",
|
736
661
|
:redirect_uri => ZuoraConnect.configuration.oauth_client_redirect_uri,
|
@@ -1104,7 +1029,7 @@ module ZuoraConnect
|
|
1104
1029
|
catalog_container = catalog_container[object_id]
|
1105
1030
|
end
|
1106
1031
|
|
1107
|
-
return catalog_container
|
1032
|
+
return catalog_container || {}
|
1108
1033
|
end
|
1109
1034
|
|
1110
1035
|
if defined?(Redis.current) && object_id.present? && object_id.class == String && object_id.present?
|
@@ -1366,7 +1291,7 @@ module ZuoraConnect
|
|
1366
1291
|
|
1367
1292
|
def self.without_sticking
|
1368
1293
|
if self.connection.respond_to?(:without_sticking)
|
1369
|
-
self.connection.without_sticking do
|
1294
|
+
self.connection.without_sticking do
|
1370
1295
|
yield
|
1371
1296
|
end
|
1372
1297
|
else
|
@@ -26,7 +26,7 @@ module ActiveRecord
|
|
26
26
|
if oids
|
27
27
|
query += "WHERE t.oid::integer IN (%s)" % oids.join(", ")
|
28
28
|
else
|
29
|
-
query += initializer.query_conditions_for_initial_load
|
29
|
+
query += initializer.query_conditions_for_initial_load
|
30
30
|
end
|
31
31
|
|
32
32
|
execute_and_clear(query, "SCHEMA", []) do |records|
|
@@ -49,10 +49,10 @@ if defined? Prometheus
|
|
49
49
|
prometheus = Prometheus::Client.registry
|
50
50
|
|
51
51
|
# Create your metrics.
|
52
|
-
ZUORA_VERSION = prometheus.gauge(:zuora_version, docstring: 'The current Zuora Gem version.', labels: %i(version name), preset_labels: { version: ZuoraAPI::VERSION, name:
|
53
|
-
CONNECT_VERSION = prometheus.gauge(:gem_version, docstring: 'The current Connect Gem version.', labels: %i(version name), preset_labels: { version: ZuoraConnect::VERSION, name:
|
54
|
-
RAILS_VERSION = prometheus.gauge(:rails_version, docstring: 'The current Rails version.', labels: %i(version name), preset_labels: { version: Rails.version, name:
|
55
|
-
RUBY_V = prometheus.gauge(:ruby_version, docstring: 'The current Ruby version.', labels: %i(version name), preset_labels: { version: RUBY_VERSION, name:
|
52
|
+
ZUORA_VERSION = prometheus.gauge(:zuora_version, docstring: 'The current Zuora Gem version.', labels: %i(version name), preset_labels: { version: ZuoraAPI::VERSION, name: ZuoraObservability::Env.app_name }, store_settings: most_recent_aggregation)
|
53
|
+
CONNECT_VERSION = prometheus.gauge(:gem_version, docstring: 'The current Connect Gem version.', labels: %i(version name), preset_labels: { version: ZuoraConnect::VERSION, name: ZuoraObservability::Env.app_name }, store_settings: most_recent_aggregation)
|
54
|
+
RAILS_VERSION = prometheus.gauge(:rails_version, docstring: 'The current Rails version.', labels: %i(version name), preset_labels: { version: Rails.version, name: ZuoraObservability::Env.app_name }, store_settings: most_recent_aggregation)
|
55
|
+
RUBY_V = prometheus.gauge(:ruby_version, docstring: 'The current Ruby version.', labels: %i(version name), preset_labels: { version: RUBY_VERSION, name: ZuoraObservability::Env.app_name }, store_settings: most_recent_aggregation)
|
56
56
|
|
57
57
|
ZUORA_VERSION.set(0)
|
58
58
|
CONNECT_VERSION.set(0)
|
@@ -61,12 +61,12 @@ if defined? Prometheus
|
|
61
61
|
|
62
62
|
# Do they have resque jobs?
|
63
63
|
if defined? Resque.redis
|
64
|
-
REDIS_CONNECTION = prometheus.gauge(:redis_connection, docstring: 'The status of the redis connection, 0 or 1', labels: %i(connection name), preset_labels: {connection:'redis', name:
|
65
|
-
JOBS_FINISHED = prometheus.gauge(:jobs_finished, docstring: 'Done resque jobs', labels: %i(type name), preset_labels: {type:'resque', name:
|
66
|
-
WORKERS_TOTAL = prometheus.gauge(:workers_total, docstring: 'Total resque workers', labels: %i(type name), preset_labels: {type:'resque', name:
|
67
|
-
WORKERS_ACTIVE = prometheus.gauge(:workers_active, docstring: 'Active resque workers', labels: %i(type name), preset_labels: {type:'resque', name:
|
68
|
-
JOBS_FAILED = prometheus.gauge(:jobs_failed, docstring: 'Failed resque jobs', labels: %i(type name), preset_labels: {type:'resque', name:
|
69
|
-
JOBS_PENDING = prometheus.gauge(:jobs_pending, docstring: 'Pending resque jobs', labels: %i(type name), preset_labels: {type:'resque', name:
|
64
|
+
REDIS_CONNECTION = prometheus.gauge(:redis_connection, docstring: 'The status of the redis connection, 0 or 1', labels: %i(connection name), preset_labels: {connection:'redis', name: ZuoraObservability::Env.app_name}, store_settings: most_recent_aggregation)
|
65
|
+
JOBS_FINISHED = prometheus.gauge(:jobs_finished, docstring: 'Done resque jobs', labels: %i(type name), preset_labels: {type:'resque', name: ZuoraObservability::Env.app_name}, store_settings: most_recent_aggregation)
|
66
|
+
WORKERS_TOTAL = prometheus.gauge(:workers_total, docstring: 'Total resque workers', labels: %i(type name), preset_labels: {type:'resque', name: ZuoraObservability::Env.app_name}, store_settings: most_recent_aggregation)
|
67
|
+
WORKERS_ACTIVE = prometheus.gauge(:workers_active, docstring: 'Active resque workers', labels: %i(type name), preset_labels: {type:'resque', name: ZuoraObservability::Env.app_name}, store_settings: most_recent_aggregation)
|
68
|
+
JOBS_FAILED = prometheus.gauge(:jobs_failed, docstring: 'Failed resque jobs', labels: %i(type name), preset_labels: {type:'resque', name: ZuoraObservability::Env.app_name}, store_settings: most_recent_aggregation)
|
69
|
+
JOBS_PENDING = prometheus.gauge(:jobs_pending, docstring: 'Pending resque jobs', labels: %i(type name), preset_labels: {type:'resque', name: ZuoraObservability::Env.app_name}, store_settings: most_recent_aggregation)
|
70
70
|
end
|
71
71
|
|
72
72
|
if defined?(Unicorn) && Unicorn.respond_to?(:listener_names)
|
@@ -74,17 +74,17 @@ if defined? Prometheus
|
|
74
74
|
:unicorn_kills,
|
75
75
|
docstring: 'Unicorn Kills',
|
76
76
|
labels: %i(type name),
|
77
|
-
preset_labels: {type:'Unicorn-Killer', name:
|
77
|
+
preset_labels: {type:'Unicorn-Killer', name: ZuoraObservability::Env.app_name},
|
78
78
|
store_settings: sum_aggregation
|
79
79
|
)
|
80
80
|
|
81
|
-
|
81
|
+
ZuoraObservability::Metrics.unicorn_listener.each do |key, _|
|
82
82
|
gauge_name = "unicorn_#{key}".gsub(/[^a-zA-Z0-9_]/, '_')
|
83
83
|
gauge = prometheus.gauge(
|
84
84
|
gauge_name.to_sym,
|
85
85
|
docstring: 'Unicorn Stats',
|
86
86
|
labels: %i(type name),
|
87
|
-
preset_labels: { type: 'unicorn', name:
|
87
|
+
preset_labels: { type: 'unicorn', name: ZuoraObservability::Env.app_name },
|
88
88
|
store_settings: most_recent_aggregation
|
89
89
|
)
|
90
90
|
Prometheus.const_set(
|
@@ -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
|