zuora_connect 2.0.46a → 2.0.46

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: a34f4afae372d7790b9304b6513451ab159dfebd4aaf4b0ac9d4eb1815a506f2
4
- data.tar.gz: 032b9cc5dabbaac3e8a0c873b8511fe273a499909c51a5744ed2c9583db2c965
3
+ metadata.gz: d335470621186c6b48bdd31e22827c74715f1a95f20f98bd1dff32500da61df6
4
+ data.tar.gz: 9861e3a42038aa63fa43068ef508863ff5a4ca786485a13161bf2a5f21736921
5
5
  SHA512:
6
- metadata.gz: 4d3bb428adef914f118c7ffacdaad023fc9bae36d689ea76757a6c244be38f74fc7ff0f3dba8b0e8b5cadc61509ea0e2f7200984a446dfd5f3daaf005aaf80a7
7
- data.tar.gz: 06dccc05037fe18c29501d2f9a5db21473e5e7492b80d525fa4c3c1abc1c3cae831ac206e32eea34a3d3022bb37697a8dfe164cfbabfb31c42f1d698f4cfda7f
6
+ metadata.gz: 787b3c48a98332f504687623a0cba9aae789017edcbce071c33ef22f23bed87ada8a03b902b907f48227a2338206e5608e5c2cf2602590666cb96bcc888a2eaa
7
+ data.tar.gz: e2329782315fe2aad8cf032cff21b26e0282cc9ecd5ec98a9815af4b750f84efebca61eb4c423345cdc8d1287e85655648624ca09a14388f86e138c5a59f556e
@@ -56,13 +56,6 @@ module ZuoraConnect
56
56
  raise "The instance refresh window cannot be greater than the instance cache period"
57
57
  end
58
58
  self.apartment_switch(nil, false)
59
-
60
- if ZuoraConnect.logger.is_a?(Ougai::Logger)
61
- ZuoraConnect.logger.with_fields.merge!(default_ougai_items)
62
- end
63
- if Rails.logger.is_a?(Ougai::Logger)
64
- Rails.logger.with_fields.merge!(default_ougai_items)
65
- end
66
59
  end
67
60
 
68
61
  def initialize_redis_placeholders
@@ -128,7 +121,7 @@ module ZuoraConnect
128
121
  end
129
122
 
130
123
  def default_ougai_items
131
- return {app_instance_id: self.id, tenant_ids: self.zuora_tenant_ids, organization: self.organizations, environment: self.environment}
124
+ return {app_instance_id: self.id}
132
125
  end
133
126
 
134
127
  def new_session(session: self.data_lookup, username: self.access_token, password: self.refresh_token, holding_pattern: false, **args)
@@ -166,26 +159,26 @@ module ZuoraConnect
166
159
 
167
160
  if session.empty?
168
161
  self.new_session_message = "REFRESHING - Session Empty"
169
- ZuoraConnect.logger.debug(self.new_session_message)
162
+ ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
170
163
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
171
164
  self.refresh(session: session)
172
165
 
173
166
  elsif (self.id != session["appInstance"].to_i)
174
167
  self.new_session_message = "REFRESHING - AppInstance ID(#{self.id}) does not match session id(#{session["appInstance"].to_i})"
175
- ZuoraConnect.logger.debug(self.new_session_message)
168
+ ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
176
169
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
177
170
  self.refresh(session: session)
178
171
 
179
172
  elsif session["#{self.id}::task_data"].blank?
180
173
  self.new_session_message = "REFRESHING - Task Data Blank"
181
- ZuoraConnect.logger.debug(self.new_session_message)
174
+ ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
182
175
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
183
176
  self.refresh(session: session)
184
177
 
185
178
  elsif session["#{self.id}::last_refresh"].blank?
186
179
  self.new_session_message = "REFRESHING - No Time on Cookie"
187
180
  recoverable_session = true
188
- ZuoraConnect.logger.debug(self.new_session_message)
181
+ ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
189
182
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
190
183
  self.refresh(session: session)
191
184
 
@@ -193,7 +186,7 @@ module ZuoraConnect
193
186
  elsif (session["#{self.id}::last_refresh"].to_i < INSTANCE_REFRESH_WINDOW.ago.to_i) && self.mark_for_refresh
194
187
  self.new_session_message = "REFRESHING - Session Old by #{time_expire.abs} second"
195
188
  recoverable_session = true
196
- ZuoraConnect.logger.debug(self.new_session_message)
189
+ ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
197
190
  self.refresh(session: session)
198
191
 
199
192
  else
@@ -202,14 +195,14 @@ module ZuoraConnect
202
195
  else
203
196
  self.new_session_message = "REBUILDING - Expires in #{time_expire} seconds"
204
197
  end
205
- ZuoraConnect.logger.debug(self.new_session_message)
198
+ ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
206
199
  self.build_task(task_data: session["#{self.id}::task_data"], session: session)
207
200
  end
208
201
  end
209
202
  return self
210
203
  rescue ZuoraConnect::Exceptions::HoldingPattern => ex
211
204
  while self.marked_for_refresh?
212
- ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'")
205
+ ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'", self.default_ougai_items)
213
206
  sleep(HOLDING_PATTERN_SLEEP)
214
207
  end
215
208
  self.reload_attributes([:refresh_token, :oauth_expires_at, :access_token])
@@ -218,17 +211,17 @@ module ZuoraConnect
218
211
  rescue ZuoraConnect::Exceptions::MissMatch => ex
219
212
  self.delete_app_instance
220
213
  session = {}
221
- ZuoraConnect.logger.error(ex, app_instance_id_new: self.task_data['id'])
214
+ ZuoraConnect.logger.error(ex, self.default_ougai_items.merge({app_instance_id_new: self.task_data['id']}))
222
215
  retry
223
216
  rescue ZuoraConnect::Exceptions::InvalidCredentialSet => ex
224
217
  raise
225
218
  rescue => ex
226
219
  if recoverable_session
227
- ZuoraConnect.logger.warn("REBUILDING - Using backup expired cache", ex)
220
+ ZuoraConnect.logger.warn("REBUILDING - Using backup expired cache", ex, self.default_ougai_items)
228
221
  self.build_task(task_data: session["#{self.id}::task_data"], session: session)
229
222
  return self
230
223
  else
231
- ZuoraConnect.logger.error("Failed new session", ex)
224
+ ZuoraConnect.logger.error("Failed new session", ex, self.default_ougai_items)
232
225
  raise
233
226
  end
234
227
  ensure
@@ -250,18 +243,19 @@ module ZuoraConnect
250
243
  ElasticAPM.set_label(:organization, organizations.first)
251
244
  end
252
245
  end
246
+ self.logitem(item: {tenant_ids: tenants, organization: organizations})
253
247
 
254
248
  params = {
255
- name: self.task_data.dig('name'),
256
- zuora_entity_ids: (self.task_data.dig(LOGIN_TENANT_DESTINATION,'entities') || []).map{|e| e['id']}.uniq,
257
- zuora_tenant_ids: tenants.map(&:to_s).uniq,
258
- organizations: organizations
249
+ :name => self.task_data.dig('name'),
250
+ :zuora_entity_ids => (self.task_data.dig(LOGIN_TENANT_DESTINATION,'entities') || []).map{|e| e['id']}.uniq,
251
+ :zuora_tenant_ids => tenants.map(&:to_s).uniq,
259
252
  }
260
253
  if self.methods.include?(LOGIN_TENANT_DESTINATION.to_sym)
261
254
  client = self.send(LOGIN_TENANT_DESTINATION).client
262
255
  if defined?(client.rest_domain)
263
- ZuoraConnect::RequestIdMiddleware.zuora_rest_domain = client.rest_domain
264
- params.merge!({zuora_domain: client.rest_domain, environment: client.environment })
256
+ zuora_domain = client.rest_domain
257
+ ZuoraConnect::RequestIdMiddleware.zuora_rest_domain = zuora_domain
258
+ params.merge!({:zuora_domain => zuora_domain })
265
259
  end
266
260
  end
267
261
  params = params.reject{|k,v| !self.attributes.keys.member?(k.to_s) || self[k] == v}
@@ -280,7 +274,7 @@ module ZuoraConnect
280
274
  response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
281
275
  response_time = Time.now - start
282
276
 
283
- ZuoraConnect.logger.debug("REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}")
277
+ ZuoraConnect.logger.debug("REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}", self.default_ougai_items)
284
278
  if response.code == 200
285
279
  begin
286
280
  parsed_json = JSON.parse(response.body)
@@ -312,26 +306,26 @@ module ZuoraConnect
312
306
  refresh_count += 1
313
307
  if refresh_count < 3
314
308
  sleep(10)
315
- ZuoraConnect.logger.debug("REFRESH TASK - Connection Failure Retrying(#{refresh_count})", ex)
309
+ ZuoraConnect.logger.debug("REFRESH TASK - Connection Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
316
310
  retry
317
311
  else
318
- ZuoraConnect.logger.fatal("REFRESH TASK - Connection Failed", ex)
312
+ ZuoraConnect.logger.fatal("REFRESH TASK - Connection Failed", ex, self.default_ougai_items)
319
313
  raise
320
314
  end
321
315
  rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
322
316
  refresh_count += 1
323
317
  if refresh_count < 3
324
- ZuoraConnect.logger.debug("REFRESH TASK - Communication Failure Retrying(#{refresh_count})", ex)
318
+ ZuoraConnect.logger.debug("REFRESH TASK - Communication Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
325
319
  self.refresh_oauth if ex.code == 401
326
320
  retry
327
321
  else
328
- ZuoraConnect.logger.fatal("REFRESH TASK - Communication Failed #{ex.code}", ex)
322
+ ZuoraConnect.logger.fatal("REFRESH TASK - Communication Failed #{ex.code}", ex, self.default_ougai_items)
329
323
  raise
330
324
  end
331
325
  end
332
326
  rescue => ex
333
327
  if self['zuora_logins'].present?
334
- ZuoraConnect.logger.warn("REFRESH TASK - Fallback to local encrypted store", ex)
328
+ ZuoraConnect.logger.warn("REFRESH TASK - Fallback to local encrypted store", ex, self.default_ougai_items)
335
329
  skip_connect = true
336
330
  retry
337
331
  end
@@ -643,7 +637,7 @@ module ZuoraConnect
643
637
  def check_oauth_state(method=nil)
644
638
  #Refresh token if already expired
645
639
  if self.oauth_expired?
646
- ZuoraConnect.logger.debug("Before '#{method}' method, Oauth expired")
640
+ ZuoraConnect.logger.debug("Before '#{method}' method, Oauth expired", self.default_ougai_items)
647
641
  self.refresh_oauth
648
642
  end
649
643
  end
@@ -662,7 +656,7 @@ module ZuoraConnect
662
656
  }
663
657
  response = HTTParty.post("#{ZuoraConnect.configuration.url}/oauth/token",:body => params)
664
658
  response_time = Time.now - start
665
- ZuoraConnect.logger.debug("REFRESH OAUTH - In #{response_time.round(2).to_s}")
659
+ ZuoraConnect.logger.debug("REFRESH OAUTH - In #{response_time.round(2).to_s}", self.default_ougai_items)
666
660
 
667
661
  if response.code == 200
668
662
  response_body = JSON.parse(response.body)
@@ -677,10 +671,10 @@ module ZuoraConnect
677
671
  rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
678
672
  if (refresh_oauth_count += 1) < 3
679
673
  sleep(5)
680
- ZuoraConnect.logger.debug("REFRESH OAUTH - Connection Failure Retrying(#{refresh_oauth_count})", ex)
674
+ ZuoraConnect.logger.debug("REFRESH OAUTH - Connection Failure Retrying(#{refresh_oauth_count})", ex, self.default_ougai_items)
681
675
  retry
682
676
  else
683
- ZuoraConnect.logger.fatal("REFRESH OAUTH - Connection Failed", ex)
677
+ ZuoraConnect.logger.fatal("REFRESH OAUTH - Connection Failed", ex, self.default_ougai_items)
684
678
  raise
685
679
  end
686
680
  rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
@@ -691,10 +685,10 @@ module ZuoraConnect
691
685
  return if !self.oauth_expired?
692
686
 
693
687
  if (refresh_oauth_count += 1) < 3
694
- ZuoraConnect.logger.debug("REFRESH OAUTH - Communication Failure Retrying(#{refresh_oauth_count})", ex)
688
+ ZuoraConnect.logger.debug("REFRESH OAUTH - Communication Failure Retrying(#{refresh_oauth_count})", ex, self.default_ougai_items)
695
689
  retry
696
690
  else
697
- ZuoraConnect.logger.fatal("REFRESH OAUTH - Communication Failed #{ex.code}", ex)
691
+ ZuoraConnect.logger.fatal("REFRESH OAUTH - Communication Failed #{ex.code}", ex, self.default_ougai_items)
698
692
  raise
699
693
  end
700
694
  end
@@ -744,10 +738,10 @@ module ZuoraConnect
744
738
  end
745
739
  end
746
740
  if cached_instance.blank?
747
- ZuoraConnect.logger.debug("Cached AppInstance Missing")
741
+ ZuoraConnect.logger.debug("Cached AppInstance Missing", self.default_ougai_items)
748
742
  return session
749
743
  else
750
- ZuoraConnect.logger.debug("Cached AppInstance Found")
744
+ ZuoraConnect.logger.debug("Cached AppInstance Found", self.default_ougai_items)
751
745
  return decrypt_data(data: cached_instance, rescue_return: session).merge(session)
752
746
  end
753
747
  else
@@ -763,7 +757,7 @@ module ZuoraConnect
763
757
  if defined?(Redis.current)
764
758
  #Task data must be present and the last refresh cannot be old. We dont want to overwite new cache data with old
765
759
  if self.task_data.present? && (self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i)
766
- ZuoraConnect.logger.debug("Caching AppInstance")
760
+ ZuoraConnect.logger.debug("Caching AppInstance", self.default_ougai_items)
767
761
  Redis.current.setex("AppInstance:#{self.id}", INSTANCE_REDIS_CACHE_PERIOD.to_i, self.encrypt_data(data: self.save_data))
768
762
  end
769
763
  end
@@ -827,10 +821,10 @@ module ZuoraConnect
827
821
  begin
828
822
  return JSON.parse(encryptor.decrypt_and_verify(CGI::unescape(data)))
829
823
  rescue ActiveSupport::MessageVerifier::InvalidSignature => ex
830
- ZuoraConnect.logger.error("Error Decrypting", ex) if log_fatal
824
+ ZuoraConnect.logger.error("Error Decrypting", ex, self.default_ougai_items) if log_fatal
831
825
  return rescue_return
832
826
  rescue JSON::ParserError => ex
833
- ZuoraConnect.logger.error("JSON Parse Error", ex) if log_fatal
827
+ ZuoraConnect.logger.error("JSON Parse Error", ex, self.default_ougai_items) if log_fatal
834
828
  return encryptor.decrypt_and_verify(CGI::unescape(data))
835
829
  end
836
830
  end
@@ -1191,7 +1185,7 @@ module ZuoraConnect
1191
1185
 
1192
1186
  def method_missing(method_sym, *arguments, &block)
1193
1187
  if method_sym.to_s.include?("login")
1194
- ZuoraConnect.logger.fatal("Method Missing #{method_sym}. Instance Data: #{self.task_data} Instance Logins: #{self.logins}")
1188
+ ZuoraConnect.logger.fatal("Method Missing #{method_sym}. Instance Data: #{self.task_data} Instance Logins: #{self.logins}", self.default_ougai_items)
1195
1189
  end
1196
1190
  super
1197
1191
  end
@@ -23,17 +23,12 @@ module Ougai
23
23
  end
24
24
 
25
25
  def _call(severity, time, progname, data)
26
- data.merge!({message: data.delete(:msg)})
27
- if data[:timestamp].present?
28
- time = data[:timestamp]
29
- data.delete(:timestamp)
30
- end
31
26
  dump({
32
27
  name: progname || @app_name,
33
28
  pid: $$,
34
29
  level: severity,
35
30
  timestamp: time.utc.strftime('%FT%T.%6NZ'),
36
- }.merge(data))
31
+ }.merge(data.merge({message: data.delete(:msg)})))
37
32
  end
38
33
 
39
34
  def convert_time(data)
data/lib/zuora_connect.rb CHANGED
@@ -41,6 +41,16 @@ module ZuoraConnect
41
41
  data[:trace_id] = ZuoraConnect::RequestIdMiddleware.request_id if ZuoraConnect::RequestIdMiddleware.request_id.present?
42
42
  data[:zuora_trace_id] = ZuoraConnect::RequestIdMiddleware.zuora_request_id if ZuoraConnect::RequestIdMiddleware.zuora_request_id.present?
43
43
  #data[:traces] = {amazon_id: data[:trace_id], zuora_id: data[:zuora_trace_id]}
44
+ if !['ElasticAPM', 'ResqueScheduler', 'ResquePool', 'Resque', 'Makara'].include?(name)
45
+ if Thread.current[:appinstance].present? && Thread.current[:appinstance].id.present?
46
+ data[:app_instance_id] = Thread.current[:appinstance].id
47
+ logitems = Thread.current[:appinstance].logitems
48
+ if logitems.present? && logitems.class == Hash
49
+ data[:tenant_ids] = logitems[:tenant_ids] if logitems[:tenant_ids].present?
50
+ data[:organization] = logitems[:organization] if logitems[:organization].present?
51
+ end
52
+ end
53
+ end
44
54
  end
45
55
  else
46
56
  logger.formatter = Ougai::Formatters::Customizable.new(
@@ -76,6 +86,16 @@ module ZuoraConnect
76
86
  pid: Process.pid,
77
87
  message: name == "ActionMailer" ? msg.strip : msg
78
88
  }
89
+ if !['ElasticAPM', 'ResqueScheduler', 'ResquePool','Resque', 'Makara'].include?(name)
90
+ if Thread.current[:appinstance].present? && Thread.current[:appinstance].id.present?
91
+ store[:app_instance_id] = Thread.current[:appinstance].id
92
+ logitems = Thread.current[:appinstance].logitems
93
+ if logitems.present? && logitems.class == Hash
94
+ store[:tenant_ids] = logitems[:tenant_ids] if logitems[:tenant_ids].present?
95
+ store[:organization] = logitems[:organization] if logitems[:organization].present?
96
+ end
97
+ end
98
+ end
79
99
  JSON.dump(store) + "\n"
80
100
  else
81
101
  format('%s %s: %s', serverity.ljust(6), datetime, msg) + "\n"
@@ -62,7 +62,7 @@ module ZuoraConnect
62
62
  items.merge!({exception: event.payload[:exception]}) if event.payload[:exception].present?
63
63
 
64
64
  if Thread.current[:appinstance].present?
65
- items.merge!({connect_user: Thread.current[:appinstance].connect_user, new_session: Thread.current[:appinstance].new_session_message})
65
+ items.merge!({appinstance_id: Thread.current[:appinstance].id, connect_user: Thread.current[:appinstance].connect_user, new_session: Thread.current[:appinstance].new_session_message})
66
66
  if Thread.current[:appinstance].logitems.present? && Thread.current[:appinstance].logitems.class == Hash
67
67
  items.merge!(Thread.current[:appinstance].logitems)
68
68
  end
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "2.0.46a"
2
+ VERSION = "2.0.46"
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: 2.0.46a
4
+ version: 2.0.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-05 00:00:00.000000000 Z
11
+ date: 2020-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -338,7 +338,6 @@ files:
338
338
  - db/migrate/20190520232221_add_zuora_user_table_and_alter_app_instance_id_table.rb
339
339
  - db/migrate/20190520232222_add_unique_index.rb
340
340
  - db/migrate/20190520232223_add_provisioning_fields.rb
341
- - db/migrate/20190520232224_add_environment_fields.rb
342
341
  - lib/logging/connect_formatter.rb
343
342
  - lib/metrics/influx/point_value.rb
344
343
  - lib/metrics/net.rb
@@ -414,9 +413,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
414
413
  version: '0'
415
414
  required_rubygems_version: !ruby/object:Gem::Requirement
416
415
  requirements:
417
- - - ">"
416
+ - - ">="
418
417
  - !ruby/object:Gem::Version
419
- version: 1.3.1
418
+ version: '0'
420
419
  requirements: []
421
420
  rubygems_version: 3.0.3
422
421
  signing_key:
@@ -1,13 +0,0 @@
1
- class AddEnvironmentFields < ActiveRecord::Migration[5.0]
2
- def change
3
- unless column_exists? :zuora_connect_app_instances, :environment
4
- add_column :zuora_connect_app_instances, :environment, :text, default: ""
5
- end
6
- unless column_exists? :zuora_connect_app_instances, :organizations
7
- add_column :zuora_connect_app_instances, :organizations, :jsonb, default: []
8
- end
9
- if column_exists? :zuora_connect_app_instances, :organizations
10
- change_column :zuora_connect_app_instances, :organizations, :jsonb, default: []
11
- end
12
- end
13
- end