zuora_connect 1.7.82 → 1.7.83

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 912e1a274c4281b87a68d1b54adc6cd7458eed4b2d22504b805946602865f820
4
- data.tar.gz: 563a6fdf7d917680bed40b011aba28fa2033ad4aa6b3edbc34f40c6e0aaf0458
3
+ metadata.gz: a038229921d3010126de36835cb7fe3fa1eac57c5e953048fee68cb5232dfb43
4
+ data.tar.gz: a96e99330f622128dcd98f452d05ec6d21d847f81bfe693fe367ee6e40e94292
5
5
  SHA512:
6
- metadata.gz: d11dfacabb58dda03407db8900fc1a6692d3790e40cb47edeb772df2c4b20f0033f73c11e641177ed256ee07e8b5c51cc408d2fb3038afb8490510c17918a27d
7
- data.tar.gz: 495d36629ab246132b2403372d0b52753b1b9ee94065ddf5a3025ec2c10f0a9af5d63e57eb1c37be3770201462e915639efb563e0ddf7a01ec24d84b3bdc19e1
6
+ metadata.gz: 54fce1d9d288a4230d412c8c6d212e3ed26c51745273d909bbc7585b418cbc7f87c44ff86a36dc83ae6bdb2fffa997b7dc5eeb7712492d5b0b57cd6e7fc61466
7
+ data.tar.gz: 9e0f20125e971ff542c328d507900839d86a0b108c7ca682ed1c2b6872ca75418226d396777149ce213827c69394055815b9942ac6ff7e499c6aa44e925e08ac
@@ -29,7 +29,7 @@ module ZuoraConnect
29
29
  PaperTrail.whodunnit = "Backend" if defined?(PaperTrail)
30
30
  if defined?(ElasticAPM) && ElasticAPM.running?
31
31
  ElasticAPM.set_user("Backend")
32
- ElasticAPM.set_tag(:app_instance, self.id)
32
+ ElasticAPM.set_tag(:app_instance, self.id)
33
33
  end
34
34
 
35
35
  if INSTANCE_REFRESH_WINDOW > INSTANCE_REDIS_CACHE_PERIOD
@@ -60,13 +60,13 @@ module ZuoraConnect
60
60
  Resque.redis.zrem("PauseQueue", id)
61
61
  end
62
62
  return true
63
- end
63
+ end
64
64
 
65
65
  def apartment_switch(method = nil, migrate = false)
66
66
  switch_count ||= 0
67
67
  if self.persisted?
68
68
  begin
69
- Apartment::Tenant.switch!(self.id)
69
+ Apartment::Tenant.switch!(self.id)
70
70
  rescue Apartment::TenantNotFound => ex
71
71
  sleep(2)
72
72
  begin
@@ -74,9 +74,9 @@ module ZuoraConnect
74
74
  rescue Apartment::TenantExists => ex
75
75
  end
76
76
  if (switch_count += 1) < 2
77
- retry
77
+ retry
78
78
  else
79
- raise
79
+ raise
80
80
  end
81
81
  end
82
82
  if migrate && ActiveRecord::Migrator.needs_migration?
@@ -159,7 +159,7 @@ module ZuoraConnect
159
159
  ZuoraConnect.logger.add(log_level, self.new_session_message)
160
160
  self.build_task(task_data: session["#{self.id}::task_data"], session: session)
161
161
  end
162
- end
162
+ end
163
163
  return self
164
164
  rescue ZuoraConnect::Exceptions::HoldingPattern => ex
165
165
  while self.marked_for_refresh?
@@ -169,7 +169,7 @@ module ZuoraConnect
169
169
  self.reload_attributes([:refresh_token, :oauth_expires_at, :access_token])
170
170
  session = self.data_lookup(session: session)
171
171
  retry
172
- rescue => ex
172
+ rescue => ex
173
173
  if recoverable_session
174
174
  ZuoraConnect.logger.error("REBUILDING - Using backup expired cache")
175
175
  self.build_task(task_data: session["#{self.id}::task_data"], session: session)
@@ -191,7 +191,7 @@ module ZuoraConnect
191
191
  ElasticAPM.set_tag(:organization, organizations.first)
192
192
  end
193
193
  self.logitem(item: {tenant_ids: tenants, organization: organizations})
194
- self.update_column(:name, self.task_data.dig('name')) if ZuoraConnect::AppInstance.column_names.include?('name') && self.task_data.dig('name') != self.name
194
+ self.update_column(:name, self.task_data.dig('name')) if ZuoraConnect::AppInstance.column_names.include?('name') && self.task_data.dig('name') != self.name
195
195
  end
196
196
 
197
197
  def refresh(session: {}, session_fallback: false)
@@ -243,10 +243,44 @@ module ZuoraConnect
243
243
  def self.write_to_telegraf(*args)
244
244
  if ZuoraConnect.configuration.enable_metrics
245
245
  @@telegraf_host = ZuoraConnect::Telegraf.new() if @@telegraf_host == nil
246
+ unicorn_stats = self.unicorn_listener_stats() if defined?(Unicorn) && Unicorn.respond_to?(:listener_names)
247
+ @@telegraf_host.write(direction: 'Raindrops', tags: {}, values: unicorn_stats) unless unicorn_stats.blank?
246
248
  return @@telegraf_host.write(*args)
247
249
  end
248
250
  end
249
251
 
252
+ def self.unicorn_listener_stats ()
253
+ stats_hash = {}
254
+ stats_hash["total_active"] = 0
255
+ stats_hash["total_queued"] = 0
256
+
257
+ begin
258
+ tmp = Unicorn.listener_names
259
+ unix = tmp.grep(%r{\A/})
260
+ tcp = tmp.grep(/\A.+:\d+\z/)
261
+ tcp = nil if tcp.empty?
262
+ unix = nil if unix.empty?
263
+
264
+
265
+ Raindrops::Linux.tcp_listener_stats(tcp).each do |addr,stats|
266
+ stats_hash["active_#{addr}"] = stats.active
267
+ stats_hash["queued_#{addr}"] = stats.queued
268
+ stats_hash["total_active"] = stats.active + stats_hash["total_active"]
269
+ stats_hash["total_queued"] = stats.queued + stats_hash["total_queued"]
270
+ end if tcp
271
+
272
+ Raindrops::Linux.unix_listener_stats(unix).each do |addr,stats|
273
+ stats_hash["active_#{addr}"] = stats.active
274
+ stats_hash["queued_#{addr}"] = stats.queued
275
+ stats_hash["total_active"] = stats.active + stats_hash["total_active"]
276
+ stats_hash["total_queued"] = stats.queued + stats_hash["total_queued"]
277
+ end if unix
278
+ rescue => ex
279
+ ZuoraConnect.logger.error(ex)
280
+ end
281
+ return stats_hash
282
+ end
283
+
250
284
  def self.get_metrics(type)
251
285
  @data = {}
252
286
 
@@ -301,7 +335,7 @@ module ZuoraConnect
301
335
  else
302
336
  tmp.client.current_session = session["#{self.id}::#{k}:current_session"] if session["#{self.id}::#{k}:current_session"]
303
337
  tmp.client.bearer_token = session["#{self.id}::#{k}:bearer_token"] if session["#{self.id}::#{k}:bearer_token"] && tmp.client.respond_to?(:bearer_token) ## need incase session id goes from basic to aouth in same redis store
304
- tmp.client.oauth_session_expires_at = session["#{self.id}::#{k}:oauth_session_expires_at"] if session["#{self.id}::#{k}:oauth_session_expires_at"] && tmp.client.respond_to?(:oauth_session_expires_at)
338
+ tmp.client.oauth_session_expires_at = session["#{self.id}::#{k}:oauth_session_expires_at"] if session["#{self.id}::#{k}:oauth_session_expires_at"] && tmp.client.respond_to?(:oauth_session_expires_at)
305
339
  end
306
340
  end
307
341
  self.logins[k] = tmp
@@ -561,13 +595,13 @@ module ZuoraConnect
561
595
  def decrypt_data(data: nil, rescue_return: nil, log_fatal: true)
562
596
  return data if data.blank?
563
597
  if Rails.env == 'development'
564
- begin
598
+ begin
565
599
  return JSON.parse(data)
566
600
  rescue JSON::ParserError => ex
567
601
  return data
568
602
  end
569
603
  else
570
- begin
604
+ begin
571
605
  return JSON.parse(encryptor.decrypt_and_verify(CGI::unescape(data)))
572
606
  rescue ActiveSupport::MessageVerifier::InvalidSignature => ex
573
607
  ZuoraConnect.logger.add(Logger::FATAL, 'Error Decrypting') if log_fatal
@@ -622,7 +656,7 @@ module ZuoraConnect
622
656
  if paused_user == current_user || paused_user.blank?
623
657
  Resque.redis.zrem("PauseQueue", "#{self.id}__#{paused_user}")
624
658
  else
625
- raise "Can only unpause for user #{paused_user}."
659
+ raise "Can only unpause for user #{paused_user}."
626
660
  end
627
661
  end
628
662
  ### END Resque Helping Methods ####
@@ -836,7 +870,7 @@ module ZuoraConnect
836
870
  if cache
837
871
  Redis.current.sadd("Catalog:#{self.id}:Keys", ["Catalog:#{self.id}:#{object_id}:Hierarchy", "Catalog:#{self.id}:#{object_id}:Children:#{child_objects}"])
838
872
  Redis.current.set("Catalog:#{self.id}:#{object_id}:Hierarchy", encrypt_data(data: object_hierarchy))
839
- Redis.current.set("Catalog:#{self.id}:#{object_id}:Children:#{child_objects}", encrypt_data(data: stub_catalog))
873
+ Redis.current.set("Catalog:#{self.id}:#{object_id}:Children:#{child_objects}", encrypt_data(data: stub_catalog))
840
874
  else
841
875
  Redis.current.sadd("Catalog:#{self.id}:Keys", ["Catalog:#{self.id}:#{object_id}:Hierarchy"])
842
876
  Redis.current.set("Catalog:#{self.id}:#{object_id}:Hierarchy", encrypt_data(data: object_hierarchy))
@@ -875,7 +909,7 @@ module ZuoraConnect
875
909
  self.update_functions
876
910
  if index_table
877
911
  ActiveRecord::Base.connection.execute('SELECT "shared_extensions".refresh_aggregate_table(\'%s\', \'%s\', %s, \'Index\');' % [aggregate_name, table_name, ActiveRecord::Base.connection.quote(where_clause)])
878
- else
912
+ else
879
913
  ActiveRecord::Base.connection.execute('SELECT "shared_extensions".refresh_aggregate_table(\'%s\', \'%s\', %s, \'NO\');' % [aggregate_name, table_name, ActiveRecord::Base.connection.quote(where_clause)])
880
914
  end
881
915
  end
@@ -949,4 +983,4 @@ module ZuoraConnect
949
983
  method_hook :refresh, :updateOption, :update_logins, :before => :check_oauth_state
950
984
  method_hook :new_session, :refresh, :build_task, :after => :apartment_switch
951
985
  end
952
- end
986
+ end
@@ -2,7 +2,7 @@ if defined?(Unicorn::WorkerKiller)
2
2
  Unicorn::WorkerKiller.module_eval do
3
3
  self.singleton_class.send(:alias_method, :kill_self_old, :kill_self)
4
4
  def self.kill_self(logger, start_time)
5
- self.kill_self_old(@unicorn_logger, start_time)
5
+ self.kill_self_old(logger, start_time)
6
6
  ZuoraConnect::AppInstance.write_to_telegraf(direction: 'Unicorn-Killer', tags: {app_instance: 0}, values: {kill: 1})
7
7
  end
8
8
  end
@@ -53,7 +53,10 @@ module ZuoraConnect
53
53
  env['REQUEST_PATH'] = env['REQUEST_PATH'].gsub(Thread.current[:isHallway], '')
54
54
 
55
55
  #We need the forwarded host header to identify location of tenant
56
- @bad_headers.delete('HTTP_X_FORWARDED_HOST')
56
+ whitelist = Regexp.new(".*[\.]zuora[\.]com$|^zuora[\.]com$")
57
+ if whitelist.match(env['HTTP_X_FORWARDED_HOST']).present?
58
+ @bad_headers.delete('HTTP_X_FORWARDED_HOST')
59
+ end
57
60
  else
58
61
  Thread.current[:isHallway] = nil
59
62
  end
@@ -1,6 +1,7 @@
1
1
  module ZuoraConnect
2
2
  class RequestIdMiddleware
3
3
  mattr_accessor :request_id
4
+ mattr_accessor :zuora_request_id
4
5
 
5
6
  def initialize(app)
6
7
  @app = app
@@ -8,6 +9,7 @@ module ZuoraConnect
8
9
 
9
10
  def call(env)
10
11
  self.request_id = env['action_dispatch.request_id']
12
+ self.zuora_request_id = env["HTTP_ZUORA_REQUEST_ID"]
11
13
  @app.call(env)
12
14
  end
13
15
  end
@@ -37,6 +37,8 @@ module ZuoraConnect
37
37
  logger.level = level
38
38
  logger.before_log = lambda do |data|
39
39
  data[:trace_id] = ZuoraConnect::RequestIdMiddleware.request_id if ZuoraConnect::RequestIdMiddleware.request_id.present?
40
+ data[:zuora_trace_id] = ZuoraConnect::RequestIdMiddleware.zuora_request_id if ZuoraConnect::RequestIdMiddleware.zuora_request_id.present?
41
+ #data[:traces] = {amazon_id: data[:trace_id], zuora_id: data[:zuora_trace_id]}
40
42
  if !['ElasticAPM', 'ResqueScheduler', 'ResquePool', 'Resque', 'Makara'].include?(name)
41
43
  if Thread.current[:appinstance].present?
42
44
  data[:app_instance_id] = Thread.current[:appinstance].id
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "1.7.82"
2
+ VERSION = "1.7.83"
3
3
  end
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.82
4
+ version: 1.7.83
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-30 00:00:00.000000000 Z
11
+ date: 2019-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -154,6 +154,20 @@ dependencies:
154
154
  - - "<"
155
155
  - !ruby/object:Gem::Version
156
156
  version: '5.1'
157
+ - !ruby/object:Gem::Dependency
158
+ name: raindrops
159
+ requirement: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ type: :runtime
165
+ prerelease: false
166
+ version_requirements: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
157
171
  - !ruby/object:Gem::Dependency
158
172
  name: rspec
159
173
  requirement: !ruby/object:Gem::Requirement