zuora_connect 2.0.46 → 2.0.47

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d335470621186c6b48bdd31e22827c74715f1a95f20f98bd1dff32500da61df6
4
- data.tar.gz: 9861e3a42038aa63fa43068ef508863ff5a4ca786485a13161bf2a5f21736921
3
+ metadata.gz: 06f1b41fdad8b24c386edeb2dfc564a6da47f357ace69b4efd4bc7b0943cf9db
4
+ data.tar.gz: dfe171d402ebf4163bf23661f7ab8a2e9c72b9f5c95b74ef49cb72c5e16c20f6
5
5
  SHA512:
6
- metadata.gz: 787b3c48a98332f504687623a0cba9aae789017edcbce071c33ef22f23bed87ada8a03b902b907f48227a2338206e5608e5c2cf2602590666cb96bcc888a2eaa
7
- data.tar.gz: e2329782315fe2aad8cf032cff21b26e0282cc9ecd5ec98a9815af4b750f84efebca61eb4c423345cdc8d1287e85655648624ca09a14388f86e138c5a59f556e
6
+ metadata.gz: 58a94c74ddc5f4412decd99adb337c0caecfdc2f708d22983c3e76733820eff8b4809f353bdd52f68a37b3484692a8f6347df3d07672af8ad22145690f2aad7d
7
+ data.tar.gz: b01d9688693cc196bb30618c39364dc5558dd91dcc3433fbef6332199eb1ef7ca3a8eba87f6e5c0cab1f025cbc132b539ced41fd1cbf62e1613a2818d04ef601
@@ -56,6 +56,13 @@ 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
59
66
  end
60
67
 
61
68
  def initialize_redis_placeholders
@@ -121,7 +128,7 @@ module ZuoraConnect
121
128
  end
122
129
 
123
130
  def default_ougai_items
124
- return {app_instance_id: self.id}
131
+ return {app_instance_id: self.id, tenant_ids: self.zuora_tenant_ids, organization: self.organizations, environment: self.environment}
125
132
  end
126
133
 
127
134
  def new_session(session: self.data_lookup, username: self.access_token, password: self.refresh_token, holding_pattern: false, **args)
@@ -159,26 +166,26 @@ module ZuoraConnect
159
166
 
160
167
  if session.empty?
161
168
  self.new_session_message = "REFRESHING - Session Empty"
162
- ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
169
+ ZuoraConnect.logger.debug(self.new_session_message)
163
170
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
164
171
  self.refresh(session: session)
165
172
 
166
173
  elsif (self.id != session["appInstance"].to_i)
167
174
  self.new_session_message = "REFRESHING - AppInstance ID(#{self.id}) does not match session id(#{session["appInstance"].to_i})"
168
- ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
175
+ ZuoraConnect.logger.debug(self.new_session_message)
169
176
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
170
177
  self.refresh(session: session)
171
178
 
172
179
  elsif session["#{self.id}::task_data"].blank?
173
180
  self.new_session_message = "REFRESHING - Task Data Blank"
174
- ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
181
+ ZuoraConnect.logger.debug(self.new_session_message)
175
182
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
176
183
  self.refresh(session: session)
177
184
 
178
185
  elsif session["#{self.id}::last_refresh"].blank?
179
186
  self.new_session_message = "REFRESHING - No Time on Cookie"
180
187
  recoverable_session = true
181
- ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
188
+ ZuoraConnect.logger.debug(self.new_session_message)
182
189
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
183
190
  self.refresh(session: session)
184
191
 
@@ -186,7 +193,7 @@ module ZuoraConnect
186
193
  elsif (session["#{self.id}::last_refresh"].to_i < INSTANCE_REFRESH_WINDOW.ago.to_i) && self.mark_for_refresh
187
194
  self.new_session_message = "REFRESHING - Session Old by #{time_expire.abs} second"
188
195
  recoverable_session = true
189
- ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
196
+ ZuoraConnect.logger.debug(self.new_session_message)
190
197
  self.refresh(session: session)
191
198
 
192
199
  else
@@ -195,14 +202,14 @@ module ZuoraConnect
195
202
  else
196
203
  self.new_session_message = "REBUILDING - Expires in #{time_expire} seconds"
197
204
  end
198
- ZuoraConnect.logger.debug(self.new_session_message, self.default_ougai_items)
205
+ ZuoraConnect.logger.debug(self.new_session_message)
199
206
  self.build_task(task_data: session["#{self.id}::task_data"], session: session)
200
207
  end
201
208
  end
202
209
  return self
203
210
  rescue ZuoraConnect::Exceptions::HoldingPattern => ex
204
211
  while self.marked_for_refresh?
205
- ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'", self.default_ougai_items)
212
+ ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'")
206
213
  sleep(HOLDING_PATTERN_SLEEP)
207
214
  end
208
215
  self.reload_attributes([:refresh_token, :oauth_expires_at, :access_token])
@@ -211,17 +218,17 @@ module ZuoraConnect
211
218
  rescue ZuoraConnect::Exceptions::MissMatch => ex
212
219
  self.delete_app_instance
213
220
  session = {}
214
- ZuoraConnect.logger.error(ex, self.default_ougai_items.merge({app_instance_id_new: self.task_data['id']}))
221
+ ZuoraConnect.logger.error(ex, app_instance_id_new: self.task_data['id'])
215
222
  retry
216
223
  rescue ZuoraConnect::Exceptions::InvalidCredentialSet => ex
217
224
  raise
218
225
  rescue => ex
219
226
  if recoverable_session
220
- ZuoraConnect.logger.warn("REBUILDING - Using backup expired cache", ex, self.default_ougai_items)
227
+ ZuoraConnect.logger.warn("REBUILDING - Using backup expired cache", ex)
221
228
  self.build_task(task_data: session["#{self.id}::task_data"], session: session)
222
229
  return self
223
230
  else
224
- ZuoraConnect.logger.error("Failed new session", ex, self.default_ougai_items)
231
+ ZuoraConnect.logger.error("Failed new session", ex)
225
232
  raise
226
233
  end
227
234
  ensure
@@ -243,19 +250,18 @@ module ZuoraConnect
243
250
  ElasticAPM.set_label(:organization, organizations.first)
244
251
  end
245
252
  end
246
- self.logitem(item: {tenant_ids: tenants, organization: organizations})
247
253
 
248
254
  params = {
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,
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
252
259
  }
253
260
  if self.methods.include?(LOGIN_TENANT_DESTINATION.to_sym)
254
261
  client = self.send(LOGIN_TENANT_DESTINATION).client
255
262
  if defined?(client.rest_domain)
256
- zuora_domain = client.rest_domain
257
- ZuoraConnect::RequestIdMiddleware.zuora_rest_domain = zuora_domain
258
- params.merge!({:zuora_domain => zuora_domain })
263
+ ZuoraConnect::RequestIdMiddleware.zuora_rest_domain = client.rest_domain
264
+ params.merge!({zuora_domain: client.rest_domain, environment: client.environment })
259
265
  end
260
266
  end
261
267
  params = params.reject{|k,v| !self.attributes.keys.member?(k.to_s) || self[k] == v}
@@ -274,7 +280,7 @@ module ZuoraConnect
274
280
  response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
275
281
  response_time = Time.now - start
276
282
 
277
- ZuoraConnect.logger.debug("REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}", self.default_ougai_items)
283
+ ZuoraConnect.logger.debug("REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}")
278
284
  if response.code == 200
279
285
  begin
280
286
  parsed_json = JSON.parse(response.body)
@@ -306,26 +312,26 @@ module ZuoraConnect
306
312
  refresh_count += 1
307
313
  if refresh_count < 3
308
314
  sleep(10)
309
- ZuoraConnect.logger.debug("REFRESH TASK - Connection Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
315
+ ZuoraConnect.logger.debug("REFRESH TASK - Connection Failure Retrying(#{refresh_count})", ex)
310
316
  retry
311
317
  else
312
- ZuoraConnect.logger.fatal("REFRESH TASK - Connection Failed", ex, self.default_ougai_items)
318
+ ZuoraConnect.logger.fatal("REFRESH TASK - Connection Failed", ex)
313
319
  raise
314
320
  end
315
321
  rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
316
322
  refresh_count += 1
317
323
  if refresh_count < 3
318
- ZuoraConnect.logger.debug("REFRESH TASK - Communication Failure Retrying(#{refresh_count})", ex, self.default_ougai_items)
324
+ ZuoraConnect.logger.debug("REFRESH TASK - Communication Failure Retrying(#{refresh_count})", ex)
319
325
  self.refresh_oauth if ex.code == 401
320
326
  retry
321
327
  else
322
- ZuoraConnect.logger.fatal("REFRESH TASK - Communication Failed #{ex.code}", ex, self.default_ougai_items)
328
+ ZuoraConnect.logger.fatal("REFRESH TASK - Communication Failed #{ex.code}", ex)
323
329
  raise
324
330
  end
325
331
  end
326
332
  rescue => ex
327
333
  if self['zuora_logins'].present?
328
- ZuoraConnect.logger.warn("REFRESH TASK - Fallback to local encrypted store", ex, self.default_ougai_items)
334
+ ZuoraConnect.logger.warn("REFRESH TASK - Fallback to local encrypted store", ex)
329
335
  skip_connect = true
330
336
  retry
331
337
  end
@@ -637,7 +643,7 @@ module ZuoraConnect
637
643
  def check_oauth_state(method=nil)
638
644
  #Refresh token if already expired
639
645
  if self.oauth_expired?
640
- ZuoraConnect.logger.debug("Before '#{method}' method, Oauth expired", self.default_ougai_items)
646
+ ZuoraConnect.logger.debug("Before '#{method}' method, Oauth expired")
641
647
  self.refresh_oauth
642
648
  end
643
649
  end
@@ -656,7 +662,7 @@ module ZuoraConnect
656
662
  }
657
663
  response = HTTParty.post("#{ZuoraConnect.configuration.url}/oauth/token",:body => params)
658
664
  response_time = Time.now - start
659
- ZuoraConnect.logger.debug("REFRESH OAUTH - In #{response_time.round(2).to_s}", self.default_ougai_items)
665
+ ZuoraConnect.logger.debug("REFRESH OAUTH - In #{response_time.round(2).to_s}")
660
666
 
661
667
  if response.code == 200
662
668
  response_body = JSON.parse(response.body)
@@ -671,10 +677,10 @@ module ZuoraConnect
671
677
  rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS + ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
672
678
  if (refresh_oauth_count += 1) < 3
673
679
  sleep(5)
674
- ZuoraConnect.logger.debug("REFRESH OAUTH - Connection Failure Retrying(#{refresh_oauth_count})", ex, self.default_ougai_items)
680
+ ZuoraConnect.logger.debug("REFRESH OAUTH - Connection Failure Retrying(#{refresh_oauth_count})", ex)
675
681
  retry
676
682
  else
677
- ZuoraConnect.logger.fatal("REFRESH OAUTH - Connection Failed", ex, self.default_ougai_items)
683
+ ZuoraConnect.logger.fatal("REFRESH OAUTH - Connection Failed", ex)
678
684
  raise
679
685
  end
680
686
  rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
@@ -685,10 +691,10 @@ module ZuoraConnect
685
691
  return if !self.oauth_expired?
686
692
 
687
693
  if (refresh_oauth_count += 1) < 3
688
- ZuoraConnect.logger.debug("REFRESH OAUTH - Communication Failure Retrying(#{refresh_oauth_count})", ex, self.default_ougai_items)
694
+ ZuoraConnect.logger.debug("REFRESH OAUTH - Communication Failure Retrying(#{refresh_oauth_count})", ex)
689
695
  retry
690
696
  else
691
- ZuoraConnect.logger.fatal("REFRESH OAUTH - Communication Failed #{ex.code}", ex, self.default_ougai_items)
697
+ ZuoraConnect.logger.fatal("REFRESH OAUTH - Communication Failed #{ex.code}", ex)
692
698
  raise
693
699
  end
694
700
  end
@@ -738,10 +744,10 @@ module ZuoraConnect
738
744
  end
739
745
  end
740
746
  if cached_instance.blank?
741
- ZuoraConnect.logger.debug("Cached AppInstance Missing", self.default_ougai_items)
747
+ ZuoraConnect.logger.debug("Cached AppInstance Missing")
742
748
  return session
743
749
  else
744
- ZuoraConnect.logger.debug("Cached AppInstance Found", self.default_ougai_items)
750
+ ZuoraConnect.logger.debug("Cached AppInstance Found")
745
751
  return decrypt_data(data: cached_instance, rescue_return: session).merge(session)
746
752
  end
747
753
  else
@@ -757,7 +763,7 @@ module ZuoraConnect
757
763
  if defined?(Redis.current)
758
764
  #Task data must be present and the last refresh cannot be old. We dont want to overwite new cache data with old
759
765
  if self.task_data.present? && (self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i)
760
- ZuoraConnect.logger.debug("Caching AppInstance", self.default_ougai_items)
766
+ ZuoraConnect.logger.debug("Caching AppInstance")
761
767
  Redis.current.setex("AppInstance:#{self.id}", INSTANCE_REDIS_CACHE_PERIOD.to_i, self.encrypt_data(data: self.save_data))
762
768
  end
763
769
  end
@@ -821,10 +827,10 @@ module ZuoraConnect
821
827
  begin
822
828
  return JSON.parse(encryptor.decrypt_and_verify(CGI::unescape(data)))
823
829
  rescue ActiveSupport::MessageVerifier::InvalidSignature => ex
824
- ZuoraConnect.logger.error("Error Decrypting", ex, self.default_ougai_items) if log_fatal
830
+ ZuoraConnect.logger.error("Error Decrypting", ex) if log_fatal
825
831
  return rescue_return
826
832
  rescue JSON::ParserError => ex
827
- ZuoraConnect.logger.error("JSON Parse Error", ex, self.default_ougai_items) if log_fatal
833
+ ZuoraConnect.logger.error("JSON Parse Error", ex) if log_fatal
828
834
  return encryptor.decrypt_and_verify(CGI::unescape(data))
829
835
  end
830
836
  end
@@ -1185,7 +1191,7 @@ module ZuoraConnect
1185
1191
 
1186
1192
  def method_missing(method_sym, *arguments, &block)
1187
1193
  if method_sym.to_s.include?("login")
1188
- ZuoraConnect.logger.fatal("Method Missing #{method_sym}. Instance Data: #{self.task_data} Instance Logins: #{self.logins}", self.default_ougai_items)
1194
+ ZuoraConnect.logger.fatal("Method Missing #{method_sym}. Instance Data: #{self.task_data} Instance Logins: #{self.logins}")
1189
1195
  end
1190
1196
  super
1191
1197
  end
@@ -0,0 +1,13 @@
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
@@ -23,12 +23,17 @@ 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
26
31
  dump({
27
32
  name: progname || @app_name,
28
33
  pid: $$,
29
34
  level: severity,
30
35
  timestamp: time.utc.strftime('%FT%T.%6NZ'),
31
- }.merge(data.merge({message: data.delete(:msg)})))
36
+ }.merge(data))
32
37
  end
33
38
 
34
39
  def convert_time(data)
@@ -0,0 +1,69 @@
1
+ module Resque
2
+ module Plugins
3
+ module AppInstanceJob
4
+ def around_perform(args)
5
+ case args.class.to_s
6
+ when "Array"
7
+ if args.first.class == Hash
8
+ data = args.first.merge({:worker_class => self.to_s})
9
+ else
10
+ data = {:worker_class => self.to_s, :args => args}
11
+ end
12
+ when "Hash"
13
+ data = args.merge({:worker_class => self.to_s})
14
+ end
15
+ if Rails.logger.is_a?(Ougai::Logger)
16
+ Rails.logger.with_fields = {job: data, trace_id: SecureRandom.uuid, name: "RailsWorker"}
17
+ end
18
+
19
+ begin
20
+ connection_count ||= 0
21
+ @appinstance = ZuoraConnect::AppInstance.find(args['app_instance_id'].to_i)
22
+ Rails.logger.info('Starting job')
23
+
24
+ @appinstance.new_session(holding_pattern: true)
25
+ rescue ActiveRecord::RecordNotFound => exception
26
+ # If we can't find app_instance let make sure we cleanup
27
+ Rails.logger.info("No instance found, purge")
28
+ ZuoraConnect::AppInstance.new(id: args['app_instance_id'].to_i).prune_data
29
+ return
30
+ rescue ActiveRecord::StatementInvalid => exception
31
+ if (connection_count += 1) <= 3 &&
32
+ (
33
+ exception.message.include?("PG::UnableToSend: no connection to the server") ||
34
+ exception.message.include?("PG::ConnectionBad: PQconsumeInput()") ||
35
+ exception.message.include?("PG::ConnectionBad: PQsocket()") ||
36
+ exception.message.include?("PG::UnableToSend: SSL SYSCALL")
37
+ )
38
+
39
+ sleep 30
40
+ ActiveRecord::Base.establish_connection
41
+ retry
42
+ else
43
+ raise
44
+ end
45
+ rescue PG::ConnectionBad => exception
46
+ Rails.logger.info("Bad Connection Restart")
47
+ Resque.enqueue_to(self.job.queue, self.job.payload['class'], args)
48
+ return
49
+ rescue ZuoraConnect::Exceptions::ConnectCommunicationError => exception
50
+ Rails.logger.warn("Enqueue Job Again ~ 2 mins", exception)
51
+ @appinstance.queue_pause(time: 2.minutes.to_i)
52
+ Resque.enqueue_to(self.job.queue, self.job.payload['class'], args)
53
+ return
54
+ rescue Net::ReadTimeout, Net::OpenTimeout, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError => exception
55
+ Rails.logger.warn("Enqueue Job Again ~ 2 mins", exception)
56
+ @appinstance.queue_pause(time: 2.minutes.to_i)
57
+ Resque.enqueue_to(self.job.queue, self.job.payload['class'], args)
58
+ return
59
+ end
60
+ yield
61
+ rescue
62
+ raise
63
+ ensure
64
+ @appinstance.cache_app_instance if defined?(@appinstance)
65
+ Rails.logger.flush if Rails.logger.methods.include?(:flush)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -17,15 +17,12 @@ module Resque
17
17
  when "Hash"
18
18
  data = args.merge({:worker_class => self.to_s})
19
19
  end
20
- Rails.logger.with_fields = {job: data, trace_id: SecureRandom.uuid, name: "RailsWorker"} if Rails.logger.class.to_s == 'Ougai::Logger' && ZuoraConnect.configuration.json_logging
21
-
20
+ if Rails.logger.is_a?(Ougai::Logger)
21
+ Rails.logger.with_fields = {job: data, trace_id: SecureRandom.uuid, name: "RailsWorker"}
22
+ end
22
23
  data = {:msg => 'Starting job', :job => data}
23
-
24
- app_instance_id = data.dig(:job, 'app_instance_id')
25
- if app_instance_id.present?
26
- Rails.logger.before_log = lambda do |data|
27
- data[:app_instance_id] = app_instance_id
28
- end
24
+ if data.dig(:job, 'app_instance_id').present?
25
+ data[:app_instance_id] = data.dig(:job, 'app_instance_id')
29
26
  end
30
27
 
31
28
  Rails.logger.info(data) if data.present?
@@ -8,6 +8,7 @@ require 'resque/dynamic_queues'
8
8
  require 'resque/silence_done'
9
9
  require 'resque/self_lookup'
10
10
  require 'resque/plugins/custom_logger'
11
+ require 'resque/plugins/app_instance_job'
11
12
  require 'logging/connect_formatter'
12
13
  require 'metrics/influx/point_value'
13
14
  require 'metrics/net'
@@ -41,16 +42,6 @@ module ZuoraConnect
41
42
  data[:trace_id] = ZuoraConnect::RequestIdMiddleware.request_id if ZuoraConnect::RequestIdMiddleware.request_id.present?
42
43
  data[:zuora_trace_id] = ZuoraConnect::RequestIdMiddleware.zuora_request_id if ZuoraConnect::RequestIdMiddleware.zuora_request_id.present?
43
44
  #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
54
45
  end
55
46
  else
56
47
  logger.formatter = Ougai::Formatters::Customizable.new(
@@ -60,6 +51,7 @@ module ZuoraConnect
60
51
  " #{err[:name]} (#{err[:message]})\n #{err[:stack]}"
61
52
  end,
62
53
  format_data: proc do |data|
54
+ data.delete(:app_instance_id); data.delete(:tenant_ids); data.delete(:organization); data.delete(:environment)
63
55
  format('%s %s: %s', 'DATA'.ljust(6), Time.now.strftime('%FT%T.%6NZ'), "#{data.to_json}") if data.present?
64
56
  end,
65
57
  format_msg: proc do |severity, datetime, _progname, data|
@@ -86,16 +78,6 @@ module ZuoraConnect
86
78
  pid: Process.pid,
87
79
  message: name == "ActionMailer" ? msg.strip : msg
88
80
  }
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
99
81
  JSON.dump(store) + "\n"
100
82
  else
101
83
  format('%s %s: %s', serverity.ljust(6), datetime, msg) + "\n"
@@ -6,8 +6,11 @@ module ZuoraConnect
6
6
 
7
7
  def authenticate_app_api_request
8
8
  #Skip session for api requests
9
- Thread.current[:appinstance] = nil
10
9
  request.session_options[:skip] = true
10
+
11
+ Thread.current[:appinstance] = nil
12
+ if ZuoraConnect.logger.is_a?(Ougai::Logger); ZuoraConnect.logger.with_fields = {}; end
13
+ if Rails.logger.is_a?(Ougai::Logger); Rails.logger.with_fields = {}; end
11
14
  if defined?(ElasticAPM) && ElasticAPM.running?
12
15
  if ElasticAPM.respond_to?(:set_label)
13
16
  ElasticAPM.set_label(:trace_id, request.uuid) if defined?(ElasticAPM) && ElasticAPM.running?
@@ -17,8 +20,8 @@ module ZuoraConnect
17
20
  end
18
21
  start_time = Time.now
19
22
  if request.headers["API-Token"].present?
20
- @appinstance = ZuoraConnect::AppInstance.where(:api_token => request.headers["API-Token"]).first
21
- ZuoraConnect.logger.debug("[#{@appinstance.id}] API REQUEST - API token") if @appinstance.present?
23
+ @appinstance = ZuoraConnect::AppInstance.find_by(:api_token => request.headers["API-Token"])
24
+ ZuoraConnect.logger.debug("API REQUEST - API token") if @appinstance.present?
22
25
  check_instance
23
26
  elsif ZuoraConnect::AppInstance::INTERNAL_HOSTS.include?(request.headers.fetch("HOST", nil))
24
27
  zuora_host, zuora_entity_id, zuora_instance_id = [request.headers['zuora-host'], (request.headers['zuora-entity-ids'] || "").gsub('-',''), request.headers['zuora-instance-id']]
@@ -53,9 +56,9 @@ module ZuoraConnect
53
56
 
54
57
  elsif request.headers.fetch("Authorization", "").include?("Basic ")
55
58
  authenticate_or_request_with_http_basic do |username, password|
56
- @appinstance = ZuoraConnect::AppInstance.where(:token => password).first
57
- @appinstance ||= ZuoraConnect::AppInstance.where(:api_token => password).first
58
- ZuoraConnect.logger.debug("[#{@appinstance.id}] API REQUEST - Basic Auth") if @appinstance.present?
59
+ @appinstance = ZuoraConnect::AppInstance.find_by(:token => password)
60
+ @appinstance ||= ZuoraConnect::AppInstance.find_by(:api_token => password)
61
+ ZuoraConnect.logger.debug("API REQUEST - Basic Auth") if @appinstance.present?
59
62
  check_instance
60
63
  end
61
64
  else
@@ -63,7 +66,7 @@ module ZuoraConnect
63
66
  end
64
67
 
65
68
  if @appinstance.present?
66
- ZuoraConnect.logger.debug("[#{@appinstance.id}] Authenticate App API Request Completed In - #{(Time.now - start_time).round(2)}s")
69
+ ZuoraConnect.logger.debug("Authenticate App API Request Completed In - #{(Time.now - start_time).round(2)}s")
67
70
  end
68
71
  end
69
72
 
@@ -85,6 +88,9 @@ module ZuoraConnect
85
88
  end
86
89
 
87
90
  def authenticate_connect_app_request
91
+ Thread.current[:appinstance] = nil
92
+ if ZuoraConnect.logger.is_a?(Ougai::Logger); ZuoraConnect.logger.with_fields = {}; end
93
+ if Rails.logger.is_a?(Ougai::Logger); Rails.logger.with_fields = {}; end
88
94
  if defined?(ElasticAPM) && ElasticAPM.running?
89
95
  if ElasticAPM.respond_to?(:set_label)
90
96
  ElasticAPM.set_label(:trace_id, request.uuid)
@@ -92,7 +98,6 @@ module ZuoraConnect
92
98
  ElasticAPM.set_label(:trace_id, request.uuid)
93
99
  end
94
100
  end
95
- Thread.current[:appinstance] = nil
96
101
  start_time = Time.now
97
102
 
98
103
  if ZuoraConnect.configuration.mode == "Production"
@@ -134,7 +139,7 @@ module ZuoraConnect
134
139
  ZuoraConnect.logger.error(ex)
135
140
  end
136
141
 
137
- ZuoraConnect.logger.debug("[#{@appinstance.blank? ? "N/A" : @appinstance.id}] Authenticate App Request Completed In - #{(Time.now - start_time).round(2)}s")
142
+ ZuoraConnect.logger.debug("Authenticate App Request Completed In - #{(Time.now - start_time).round(2)}s")
138
143
 
139
144
  rescue ZuoraConnect::Exceptions::InvalidCredentialSet => ex
140
145
  id = @appinstance.id
@@ -491,7 +496,7 @@ module ZuoraConnect
491
496
 
492
497
  ZuoraConnect.logger.debug({msg: 'Setup values', connect: values}) if Rails.env != "production"
493
498
 
494
- @appinstance = ZuoraConnect::AppInstance.where(:id => values["appInstance"].to_i).first
499
+ @appinstance = ZuoraConnect::AppInstance.find_by(:id => values["appInstance"].to_i)
495
500
 
496
501
  if @appinstance.blank?
497
502
  Apartment::Tenant.switch!("public")
@@ -514,7 +519,7 @@ module ZuoraConnect
514
519
  end
515
520
  else
516
521
  if session["appInstance"].present?
517
- @appinstance = ZuoraConnect::AppInstance.where(:id => session["appInstance"]).first
522
+ @appinstance = ZuoraConnect::AppInstance.find_by(:id => session["appInstance"])
518
523
  else
519
524
  raise ZuoraConnect::Exceptions::AccessDenied.new("No application state or session found.")
520
525
  end
@@ -526,7 +531,7 @@ module ZuoraConnect
526
531
  user = ZuoraConnect.configuration.dev_mode_user
527
532
  key = ZuoraConnect.configuration.dev_mode_pass
528
533
  values = {:user => user , :key => key, :appinstance => session["appInstance"]}
529
- @appinstance = ZuoraConnect::AppInstance.where(:id => values[:appinstance].to_i).first
534
+ @appinstance = ZuoraConnect::AppInstance.find_by(:id => values[:appinstance].to_i)
530
535
  if @appinstance.blank?
531
536
  Apartment::Tenant.switch!("public")
532
537
  begin
@@ -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!({appinstance_id: Thread.current[:appinstance].id, connect_user: Thread.current[:appinstance].connect_user, new_session: Thread.current[:appinstance].new_session_message})
65
+ items.merge!({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.46"
2
+ VERSION = "2.0.47"
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.46
4
+ version: 2.0.47
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-03 00:00:00.000000000 Z
11
+ date: 2020-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -338,6 +338,7 @@ 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
341
342
  - lib/logging/connect_formatter.rb
342
343
  - lib/metrics/influx/point_value.rb
343
344
  - lib/metrics/net.rb
@@ -347,6 +348,7 @@ files:
347
348
  - lib/middleware/request_id_middleware.rb
348
349
  - lib/resque/additions.rb
349
350
  - lib/resque/dynamic_queues.rb
351
+ - lib/resque/plugins/app_instance_job.rb
350
352
  - lib/resque/plugins/custom_logger.rb
351
353
  - lib/resque/self_lookup.rb
352
354
  - lib/resque/silence_done.rb