zuora_connect 1.7.23 → 1.7.24
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 +33 -18
- data/app/models/zuora_connect/telegraf.rb +18 -13
- data/config/initializers/prometheus.rb +4 -5
- data/config/initializers/redis.rb +2 -2
- data/db/migrate/20181206162339_add_fields_to_instance.rb +5 -0
- data/lib/middleware/metrics_middleware.rb +7 -9
- data/lib/zuora_connect/version.rb +1 -1
- metadata +28 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d3874ddaa25d77cca54a3953967aa1ea6ec2265
|
4
|
+
data.tar.gz: 9314b8f38d9a6928597a2dbe305a041dc277a7ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c6eff061cacb73bf43f542a981677a25bb6d6612abbf9b104821c5d1a9bf1e952a0adbb36e5edbb687d4e90aa7d3c7c773c6f79a61ad1ab1ac135b2f2ac4b6c
|
7
|
+
data.tar.gz: c4822a28c7597c4f43b797bdd9fb742f7f179e0e83cabab623d05a95c74c5afc36c46b69431495c43ea6bdbd37002f71b8a5fe2ca11453493e5c3504af2d241e
|
@@ -46,6 +46,7 @@ module ZuoraConnect
|
|
46
46
|
self.last_refresh = session["#{self.id}::last_refresh"]
|
47
47
|
self.connect_user = session["#{self.id}::user::email"] if session["#{self.id}::user::email"].present?
|
48
48
|
PaperTrail.whodunnit = self.connect_user if defined?(PaperTrail)
|
49
|
+
recoverable_session = false
|
49
50
|
|
50
51
|
## DEV MODE TASK DATA MOCKUP
|
51
52
|
if ZuoraConnect.configuration.mode != "Production"
|
@@ -71,43 +72,46 @@ module ZuoraConnect
|
|
71
72
|
|
72
73
|
if session.empty?
|
73
74
|
self.new_session_message = "REFRESHING - Session Empty"
|
75
|
+
Rails.logger.add(log_level, self.new_session_message)
|
74
76
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
75
|
-
self.refresh(session)
|
77
|
+
self.refresh(session: session)
|
76
78
|
|
77
79
|
elsif (self.id != session["appInstance"].to_i)
|
78
80
|
self.new_session_message = "REFRESHING - AppInstance ID(#{self.id}) does not match session id(#{session["appInstance"].to_i})"
|
81
|
+
Rails.logger.add(log_level, self.new_session_message)
|
79
82
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
80
|
-
self.refresh(session)
|
83
|
+
self.refresh(session: session)
|
81
84
|
|
82
85
|
elsif session["#{self.id}::task_data"].blank?
|
83
86
|
self.new_session_message = "REFRESHING - Task Data Blank"
|
87
|
+
Rails.logger.add(log_level, self.new_session_message)
|
84
88
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
85
|
-
self.refresh(session)
|
89
|
+
self.refresh(session: session)
|
86
90
|
|
87
91
|
elsif session["#{self.id}::last_refresh"].blank?
|
88
92
|
self.new_session_message = "REFRESHING - No Time on Cookie"
|
93
|
+
recoverable_session = true
|
94
|
+
Rails.logger.add(log_level, self.new_session_message)
|
89
95
|
raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
|
90
|
-
self.refresh(session)
|
96
|
+
self.refresh(session: session)
|
91
97
|
|
92
98
|
# If the cache is expired and we can aquire a refresh lock
|
93
99
|
elsif (session["#{self.id}::last_refresh"].to_i < INSTANCE_REFRESH_WINDOW.ago.to_i) && self.mark_for_refresh
|
94
100
|
self.new_session_message = "REFRESHING - Session Old by #{time_expire.abs} second"
|
95
|
-
|
101
|
+
recoverable_session = true
|
102
|
+
Rails.logger.add(log_level, self.new_session_message)
|
103
|
+
self.refresh(session: session)
|
104
|
+
|
96
105
|
else
|
97
106
|
if time_expire < 0
|
98
107
|
self.new_session_message = ["REBUILDING - Expired by #{time_expire} seconds", self.marked_for_refresh? ? " cache updating as of #{self.reset_mark_refreshed_at} seconds ago" : nil].compact.join(',')
|
99
108
|
else
|
100
109
|
self.new_session_message = "REBUILDING - Expires in #{time_expire} seconds"
|
101
110
|
end
|
111
|
+
Rails.logger.add(log_level, self.new_session_message)
|
102
112
|
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
103
113
|
end
|
104
114
|
end
|
105
|
-
begin
|
106
|
-
I18n.locale = self.locale
|
107
|
-
rescue I18n::InvalidLocale => ex
|
108
|
-
Rails.logger.debug("Invalid Locale: #{ex.message}")
|
109
|
-
end
|
110
|
-
Time.zone = self.timezone
|
111
115
|
return self
|
112
116
|
rescue ZuoraConnect::Exceptions::HoldingPattern => ex
|
113
117
|
while self.marked_for_refresh?
|
@@ -117,12 +121,25 @@ module ZuoraConnect
|
|
117
121
|
self.reload_attributes([:refresh_token, :oauth_expires_at, :access_token])
|
118
122
|
session = self.data_lookup(session: session)
|
119
123
|
retry
|
120
|
-
|
124
|
+
rescue => ex
|
125
|
+
if recoverable_session
|
126
|
+
Rails.logger.error("REBUILDING - Using backup expired cache")
|
127
|
+
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
128
|
+
return self
|
129
|
+
else
|
130
|
+
raise
|
131
|
+
end
|
121
132
|
ensure
|
122
|
-
|
133
|
+
begin
|
134
|
+
I18n.locale = self.locale
|
135
|
+
rescue I18n::InvalidLocale => ex
|
136
|
+
Rails.logger.debug("Invalid Locale: #{ex.message}")
|
137
|
+
end
|
138
|
+
Time.zone = self.timezone
|
139
|
+
self.update_column(:name, self.task_data.dig('name')) if self.task_data.dig('name') != self.name
|
123
140
|
end
|
124
141
|
|
125
|
-
def refresh(session
|
142
|
+
def refresh(session: {}, session_fallback: false)
|
126
143
|
refresh_count ||= 0
|
127
144
|
start = Time.now
|
128
145
|
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
@@ -168,13 +185,11 @@ module ZuoraConnect
|
|
168
185
|
end
|
169
186
|
|
170
187
|
def self.get_metrics(type)
|
171
|
-
namespace = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
|
172
|
-
|
173
188
|
@data = {}
|
174
189
|
|
175
190
|
if type == "versions"
|
176
191
|
@data = {
|
177
|
-
app_name:
|
192
|
+
app_name: ZuoraConnect::Telegraf.app_name,
|
178
193
|
url: "dummy",
|
179
194
|
Version_Gem: ZuoraConnect::VERSION,
|
180
195
|
Version_Zuora: ZuoraAPI::VERSION ,
|
@@ -186,7 +201,7 @@ module ZuoraConnect
|
|
186
201
|
begin
|
187
202
|
Resque.redis.ping
|
188
203
|
@data = {
|
189
|
-
app_name:
|
204
|
+
app_name: ZuoraConnect::Telegraf.app_name,
|
190
205
|
url: "dummy",
|
191
206
|
Resque:{
|
192
207
|
Jobs_Finished: Resque.info[:processed] ,
|
@@ -29,7 +29,7 @@ module ZuoraConnect
|
|
29
29
|
# To avoid writing metrics from rspec tests
|
30
30
|
if Rails.env.to_sym != :test
|
31
31
|
app_instance = Thread.current[:appinstance].present? ? Thread.current[:appinstance].id : 0
|
32
|
-
tags = { app_name: app_name, process_type: process_type, app_instance: app_instance, pod_name: pod_name}.merge(tags)
|
32
|
+
tags = { app_name: self.class.app_name, process_type: self.class.process_type, app_instance: app_instance, pod_name: self.class.pod_name}.merge(tags)
|
33
33
|
|
34
34
|
if direction == :inbound
|
35
35
|
self.write_udp(series: INBOUND_METRICS_NAME, tags: tags, values: values) if INBOUND_METRICS
|
@@ -59,17 +59,29 @@ module ZuoraConnect
|
|
59
59
|
Rails.logger.warn(self.format_metric_log('Telegraf', ex.message))
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
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
|
+
log_entry
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.app_name
|
63
70
|
return ENV['DEIS_APP'].present? ? ENV['DEIS_APP'] : Rails.application.class.parent_name
|
64
71
|
end
|
65
72
|
|
66
|
-
def pod_name
|
67
|
-
return ENV['HOSTNAME'].present? ? ENV['HOSTNAME'] :
|
73
|
+
def self.pod_name
|
74
|
+
return ENV['HOSTNAME'].present? ? ENV['HOSTNAME'] : Socket.gethostname
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.full_process_name(process_name: nil, function: nil)
|
78
|
+
keys = [self.pod_name, process_name.present? ? process_name : self.process_type, Process.pid, function]
|
79
|
+
return keys.compact.join('][').prepend('[').concat(']')
|
68
80
|
end
|
69
81
|
|
70
82
|
# Returns the process type if any
|
71
|
-
def process_type
|
72
|
-
p_type =
|
83
|
+
def self.process_type(default: 'Unknown')
|
84
|
+
p_type = default
|
73
85
|
if ENV['HOSTNAME'] && ENV['DEIS_APP']
|
74
86
|
temp = ENV['HOSTNAME'].split(ENV['DEIS_APP'])[1]
|
75
87
|
temp = temp.split(/(-[0-9a-zA-Z]{5})$/)[0] # remove the 5 char hash
|
@@ -77,12 +89,5 @@ module ZuoraConnect
|
|
77
89
|
end
|
78
90
|
return p_type
|
79
91
|
end
|
80
|
-
|
81
|
-
def format_metric_log(message, dump = nil)
|
82
|
-
message_color, dump_color = "1;91", "0;1"
|
83
|
-
log_entry = " \e[#{message_color}m#{message}\e[0m "
|
84
|
-
log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
|
85
|
-
log_entry
|
86
|
-
end
|
87
92
|
end
|
88
93
|
end
|
@@ -3,7 +3,6 @@ if defined? Prometheus
|
|
3
3
|
require "zuora_connect/version"
|
4
4
|
require "zuora_api/version"
|
5
5
|
|
6
|
-
app_name = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
|
7
6
|
# Create a default Prometheus registry for our metrics.
|
8
7
|
prometheus = Prometheus::Client.registry
|
9
8
|
|
@@ -14,10 +13,10 @@ if defined? Prometheus
|
|
14
13
|
RUBY_V = Prometheus::Client::Gauge.new(:ruby_version, 'The current Ruby version.')
|
15
14
|
|
16
15
|
# Register your metrics with the registry we previously created.
|
17
|
-
prometheus.register(ZUORA_VERSION);ZUORA_VERSION.set({version:ZuoraAPI::VERSION,name:app_name},0)
|
18
|
-
prometheus.register(CONNECT_VERSION);CONNECT_VERSION.set({version:ZuoraConnect::VERSION,name:app_name},0)
|
19
|
-
prometheus.register(RAILS_VERSION);RAILS_VERSION.set({version:Rails.version,name:app_name},0)
|
20
|
-
prometheus.register(RUBY_V);RUBY_V.set({version:RUBY_VERSION,name:app_name},0)
|
16
|
+
prometheus.register(ZUORA_VERSION);ZUORA_VERSION.set({version: ZuoraAPI::VERSION, name: ZuoraConnect::Telegraf.app_name},0)
|
17
|
+
prometheus.register(CONNECT_VERSION);CONNECT_VERSION.set({version: ZuoraConnect::VERSION, name: ZuoraConnect::Telegraf.app_name},0)
|
18
|
+
prometheus.register(RAILS_VERSION);RAILS_VERSION.set({version: Rails.version, name: ZuoraConnect::Telegraf.app_name},0)
|
19
|
+
prometheus.register(RUBY_V);RUBY_V.set({version: RUBY_VERSION, name: ZuoraConnect::Telegraf.app_name},0)
|
21
20
|
|
22
21
|
# Do they have resque jobs?
|
23
22
|
if defined? Resque.redis
|
@@ -1,9 +1,9 @@
|
|
1
1
|
redis_url = ENV["REDIS_URL"].present? ? ENV["REDIS_URL"] : defined?(Rails.application.secrets.redis) ? Rails.application.secrets.redis : 'redis://localhost:6379/1'
|
2
2
|
resque_url = ENV["RESQUE_URL"].present? ? ENV["RESQUE_URL"] : defined?(Rails.application.secrets.resque) ? Rails.application.secrets.resque : 'redis://localhost:6379/1'
|
3
3
|
if defined?(Redis.current)
|
4
|
-
Redis.current = Redis.new(:url => redis_url, :timeout => 10, :reconnect_attempts => 2)
|
4
|
+
Redis.current = Redis.new(:id => "#{ZuoraConnect::Telegraf.full_process_name(process_name: 'Redis')}", :url => redis_url, :timeout => 10, :reconnect_attempts => 2)
|
5
5
|
if defined?(Resque.redis)
|
6
|
-
Resque.redis = resque_url != redis_url ? Redis.new(:url => resque_url, :timeout => 10, :reconnect_attempts => 2) : Redis.current
|
6
|
+
Resque.redis = resque_url != redis_url ? Redis.new(:id => "#{ZuoraConnect::Telegraf.full_process_name(process_name: 'Resque')}", :url => resque_url, :timeout => 10, :reconnect_attempts => 2) : Redis.current
|
7
7
|
end
|
8
8
|
end
|
9
9
|
if defined?(RedisBrowser)
|
@@ -58,21 +58,19 @@ module Middleware
|
|
58
58
|
|
59
59
|
#Do something before each scrape
|
60
60
|
if defined? Resque.redis
|
61
|
-
|
62
|
-
app_name = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
|
63
61
|
begin
|
64
62
|
|
65
63
|
Resque.redis.ping
|
66
64
|
|
67
|
-
Prometheus::REDIS_CONNECTION.set({connection:'redis',name:app_name},1)
|
68
|
-
Prometheus::FINISHED_JOBS.set({type:'resque',name:app_name},Resque.info[:processed])
|
69
|
-
Prometheus::PENDING_JOBS.set({type:'resque',name:app_name},Resque.info[:pending])
|
70
|
-
Prometheus::ACTIVE_WORKERS.set({type:'resque',name:app_name},Resque.info[:working])
|
71
|
-
Prometheus::WORKERS.set({type:'resque',name:app_name},Resque.info[:workers])
|
72
|
-
Prometheus::FAILED_JOBS.set({type:'resque',name:app_name},Resque.info[:failed])
|
65
|
+
Prometheus::REDIS_CONNECTION.set({connection:'redis',name: ZuoraConnect::Telegraf.app_name},1)
|
66
|
+
Prometheus::FINISHED_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:processed])
|
67
|
+
Prometheus::PENDING_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:pending])
|
68
|
+
Prometheus::ACTIVE_WORKERS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:working])
|
69
|
+
Prometheus::WORKERS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:workers])
|
70
|
+
Prometheus::FAILED_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:failed])
|
73
71
|
|
74
72
|
rescue Redis::CannotConnectError
|
75
|
-
Prometheus::REDIS_CONNECTION.set({connection:'redis',name:app_name},0)
|
73
|
+
Prometheus::REDIS_CONNECTION.set({connection:'redis',name: ZuoraConnect::Telegraf.app_name},0)
|
76
74
|
end
|
77
75
|
|
78
76
|
if ZuoraConnect.configuration.custom_prometheus_update_block != nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuora_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connect Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apartment
|
@@ -284,6 +284,7 @@ files:
|
|
284
284
|
- db/migrate/20110503003603_add_catalog_mappings_to_app_instance.rb
|
285
285
|
- db/migrate/20110503003604_catalog_default.rb
|
286
286
|
- db/migrate/20180301052853_add_catalog_attempted_at.rb
|
287
|
+
- db/migrate/20181206162339_add_fields_to_instance.rb
|
287
288
|
- lib/metrics/influx/point_value.rb
|
288
289
|
- lib/metrics/net.rb
|
289
290
|
- lib/middleware/metrics_middleware.rb
|
@@ -366,43 +367,43 @@ specification_version: 4
|
|
366
367
|
summary: Summary of Connect.
|
367
368
|
test_files:
|
368
369
|
- test/test_helper.rb
|
369
|
-
- test/lib/generators/zuora_connect/datatable_generator_test.rb
|
370
|
-
- test/zuora_connect_test.rb
|
371
370
|
- test/models/zuora_connect/app_instance_test.rb
|
372
|
-
- test/
|
371
|
+
- test/zuora_connect_test.rb
|
373
372
|
- test/integration/navigation_test.rb
|
373
|
+
- test/lib/generators/zuora_connect/datatable_generator_test.rb
|
374
374
|
- test/fixtures/zuora_connect/app_instances.yml
|
375
|
-
- test/dummy/
|
376
|
-
- test/dummy/
|
377
|
-
- test/dummy/
|
378
|
-
- test/dummy/
|
379
|
-
- test/dummy/
|
380
|
-
- test/dummy/
|
375
|
+
- test/dummy/bin/setup
|
376
|
+
- test/dummy/bin/rails
|
377
|
+
- test/dummy/bin/rake
|
378
|
+
- test/dummy/bin/bundle
|
379
|
+
- test/dummy/public/500.html
|
380
|
+
- test/dummy/public/422.html
|
381
|
+
- test/dummy/public/404.html
|
382
|
+
- test/dummy/public/favicon.ico
|
383
|
+
- test/dummy/config/environment.rb
|
381
384
|
- test/dummy/config/application.rb
|
382
|
-
- test/dummy/config/
|
385
|
+
- test/dummy/config/routes.rb
|
383
386
|
- test/dummy/config/environments/development.rb
|
384
387
|
- test/dummy/config/environments/test.rb
|
385
388
|
- test/dummy/config/environments/production.rb
|
386
389
|
- test/dummy/config/database.yml
|
387
|
-
- test/dummy/config/routes.rb
|
388
|
-
- test/dummy/config/environment.rb
|
389
390
|
- test/dummy/config/locales/en.yml
|
390
|
-
- test/dummy/config/
|
391
|
+
- test/dummy/config/boot.rb
|
392
|
+
- test/dummy/config/secrets.yml
|
393
|
+
- test/dummy/config/initializers/mime_types.rb
|
391
394
|
- test/dummy/config/initializers/session_store.rb
|
395
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
392
396
|
- test/dummy/config/initializers/inflections.rb
|
393
|
-
- test/dummy/config/initializers/mime_types.rb
|
394
397
|
- test/dummy/config/initializers/wrap_parameters.rb
|
395
|
-
- test/dummy/config/initializers/cookies_serializer.rb
|
396
398
|
- test/dummy/config/initializers/assets.rb
|
397
399
|
- test/dummy/config/initializers/backtrace_silencers.rb
|
398
|
-
- test/dummy/config/
|
399
|
-
- test/dummy/config.ru
|
400
|
-
- test/dummy/bin/setup
|
401
|
-
- test/dummy/bin/bundle
|
402
|
-
- test/dummy/bin/rails
|
403
|
-
- test/dummy/bin/rake
|
404
|
-
- test/dummy/public/500.html
|
405
|
-
- test/dummy/public/404.html
|
406
|
-
- test/dummy/public/422.html
|
407
|
-
- test/dummy/public/favicon.ico
|
400
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
408
401
|
- test/dummy/README.rdoc
|
402
|
+
- test/dummy/config.ru
|
403
|
+
- test/dummy/Rakefile
|
404
|
+
- test/dummy/app/views/layouts/application.html.erb
|
405
|
+
- test/dummy/app/helpers/application_helper.rb
|
406
|
+
- test/dummy/app/assets/stylesheets/application.css
|
407
|
+
- test/dummy/app/assets/javascripts/application.js
|
408
|
+
- test/dummy/app/controllers/application_controller.rb
|
409
|
+
- test/controllers/zuora_connect/api/v1/app_instance_controller_test.rb
|