zuora_connect 1.7.50 → 1.7.51

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
  SHA1:
3
- metadata.gz: e93429f353316549ed600e4c5f014add881b09a5
4
- data.tar.gz: 578e5ade007ffede35ba3ee75c07a2b9be52371a
3
+ metadata.gz: ad59396c82c4d286dcf2b5afda3ad40983162f76
4
+ data.tar.gz: 9e527b969e5e4372b319cdd68d41ab48896a2ad8
5
5
  SHA512:
6
- metadata.gz: 511c0923a45f4fa760d1b50eed093f89228d47831a86fc07ac8d8521af1ef5c60b4ee41efaf34fbb6c2359ca2740d0ffde34ba3db44c21e199af10b1db6169c3
7
- data.tar.gz: a25e55ca3a252f795b7f53999dbff000ea95a6b32d1c405bd241be891edc70b83c739ba4c5445ed5814997a7b3656fe1e312eac801ad36604131dae0e2a296c0
6
+ metadata.gz: e73d775199745a4efdd392612e7ac4ee4fc9a9629f46f950aa34347070103757cb3aad668c5cb36e8cbfcf8c6fe9d9573bf0e729c2b6cc86e07c832443311bca
7
+ data.tar.gz: deb7f9b329ef3b7574aba311c44880d8c48fe1ff1ef008d2c1c721897b15c08807ac3a05482e876573e4c352ca2f04d6adb1935f312d241e3f70b69f3257c270
@@ -39,6 +39,7 @@ module ZuoraConnect
39
39
  def initialize_redis_placeholder
40
40
  if defined?(Redis.current)
41
41
  Redis.current.zadd("APILimits", 9999999999, "placeholder")
42
+ Redis.current.zadd("InstanceRefreshing", 9999999999, "placeholder")
42
43
  Resque.redis.zadd("PauseQueue", 9999999999, "placeholder")
43
44
  end
44
45
  end
@@ -414,23 +415,33 @@ module ZuoraConnect
414
415
 
415
416
  #### START AppInstance Temporary Persistance Methods ####
416
417
  def marked_for_refresh?
417
- return defined?(Redis.current) ? Redis.current.get("AppInstance:#{self.id}:Refreshing").to_bool : false
418
+ if defined?(Redis.current)
419
+ Redis.current.zremrangebyscore("InstanceRefreshing", "0", "(#{Time.now.to_i}")
420
+ return Redis.current.zscore("InstanceRefreshing", self.id).present?
421
+ else
422
+ return false
423
+ end
418
424
  end
419
425
 
420
426
  def reset_mark_for_refresh
421
- Redis.current.del("AppInstance:#{self.id}:Refreshing") if defined?(Redis.current)
427
+ Redis.current.zrem("InstanceRefreshing", self.id) if defined?(Redis.current)
422
428
  end
423
429
 
424
430
  def reset_mark_refreshed_at
425
- return defined?(Redis.current) ? REFRESH_TIMEOUT.to_i - Redis.current.ttl("AppInstance:#{self.id}:Refreshing") : 0
431
+ return defined?(Redis.current) ? REFRESH_TIMEOUT.to_i - reset_mark_expires_at : 0
426
432
  end
427
433
 
428
434
  def reset_mark_expires_at
429
- return defined?(Redis.current) ? Redis.current.ttl("AppInstance:#{self.id}:Refreshing") : 0
435
+ if defined?(Redis.current)
436
+ refresh_time = Redis.current.zscore("InstanceRefreshing", self.id)
437
+ return refresh_time.present? ? (refresh_time - Time.now.to_i).round(0) : 0
438
+ else
439
+ return 0
440
+ end
430
441
  end
431
442
 
432
443
  def mark_for_refresh
433
- return defined?(Redis.current) ? Redis.current.set("AppInstance:#{self.id}:Refreshing", true, {:nx => true, :ex => REFRESH_TIMEOUT.to_i}) : true
444
+ return defined?(Redis.current) ? Redis.current.zadd("InstanceRefreshing", Time.now.to_i + REFRESH_TIMEOUT.to_i, self.id, {:nx => true}) : true
434
445
  end
435
446
 
436
447
  def data_lookup(session: {})
@@ -542,10 +553,8 @@ module ZuoraConnect
542
553
  ### START Resque Helping Methods ####
543
554
  def api_limit(start: true, time: API_LIMIT_TIMEOUT.to_i)
544
555
  if start
545
- # Redis.current.setex("APILimits:#{self.id}", time, true)
546
556
  Redis.current.zadd("APILimits", Time.now.to_i + time, self.id)
547
557
  else
548
- # Redis.current.del("APILimits:#{self.id}")
549
558
  Redis.current.zrem("APILimits", self.id)
550
559
  end
551
560
  end
@@ -32,7 +32,12 @@ module ZuoraConnect
32
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
- self.write_udp(series: INBOUND_METRICS_NAME, tags: tags, values: values) if INBOUND_METRICS
35
+ if INBOUND_METRICS && !Thread.current[:inbound_metric].to_bool
36
+ self.write_udp(series: INBOUND_METRICS_NAME, tags: tags, values: values)
37
+ Thread.current[:inbound_metric] = true
38
+ else
39
+ return
40
+ end
36
41
  elsif direction == :outbound
37
42
  self.write_udp(series: OUTBOUND_METRICS_NAME, tags: tags, values: values) if OUTBOUND_METRICS
38
43
  else
@@ -63,64 +63,69 @@ module Middleware
63
63
 
64
64
  #Thread.current[:appinstance] = nil
65
65
  start_time = Time.now
66
- @status, @headers, @response = @app.call(env)
66
+ begin
67
+ @status, @headers, @response = @app.call(env)
68
+ ensure
69
+
70
+ # If the url contains any CSS or JavaScript files then do not collect metrics for them
71
+ if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| env['PATH_INFO'].include?(word) } || /.*\.js$/.match(env['PATH_INFO'])
72
+ tags = {status: @status, controller: 'ActionController', action: 'Assets', app_instance: 0}
73
+ values = {response_time: ((Time.now - start_time)*1000).round(2) }
74
+ ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: 'request-inbound-assets', tags: tags, values: values)
75
+ end
67
76
 
68
- # If the url contains any CSS or JavaScript files then do not collect metrics for them
69
- if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| env['PATH_INFO'].include?(word) } || /.*\.js$/.match(env['PATH_INFO'])
70
- tags = {status: @status, controller: 'ActionController', action: 'Assets', app_instance: 0}
71
- values = {response_time: ((Time.now - start_time)*1000).round(2) }
72
- ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: 'request-inbound-assets', tags: tags, values: values)
73
- end
77
+ if defined? Prometheus
78
+ #Prometheus Stuff
79
+ if env['PATH_INFO'] == '/connect/internal/metrics'
74
80
 
75
- if defined? Prometheus
76
- #Prometheus Stuff
77
- if env['PATH_INFO'] == '/connect/internal/metrics'
81
+ #Do something before each scrape
82
+ if defined? Resque.redis
83
+ begin
78
84
 
79
- #Do something before each scrape
80
- if defined? Resque.redis
81
- begin
85
+ Resque.redis.ping
82
86
 
83
- Resque.redis.ping
87
+ Prometheus::REDIS_CONNECTION.set({connection:'redis',name: ZuoraConnect::Telegraf.app_name},1)
88
+ Prometheus::FINISHED_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:processed])
89
+ Prometheus::PENDING_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:pending])
90
+ Prometheus::ACTIVE_WORKERS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:working])
91
+ Prometheus::WORKERS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:workers])
92
+ Prometheus::FAILED_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:failed])
84
93
 
85
- Prometheus::REDIS_CONNECTION.set({connection:'redis',name: ZuoraConnect::Telegraf.app_name},1)
86
- Prometheus::FINISHED_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:processed])
87
- Prometheus::PENDING_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:pending])
88
- Prometheus::ACTIVE_WORKERS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:working])
89
- Prometheus::WORKERS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:workers])
90
- Prometheus::FAILED_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:failed])
94
+ rescue Redis::CannotConnectError
95
+ Prometheus::REDIS_CONNECTION.set({connection:'redis',name: ZuoraConnect::Telegraf.app_name},0)
96
+ end
91
97
 
92
- rescue Redis::CannotConnectError
93
- Prometheus::REDIS_CONNECTION.set({connection:'redis',name: ZuoraConnect::Telegraf.app_name},0)
98
+ if ZuoraConnect.configuration.custom_prometheus_update_block != nil
99
+ ZuoraConnect.configuration.custom_prometheus_update_block.call()
100
+ end
94
101
  end
95
102
 
96
- if ZuoraConnect.configuration.custom_prometheus_update_block != nil
97
- ZuoraConnect.configuration.custom_prometheus_update_block.call()
98
- end
99
103
  end
100
-
101
104
  end
102
- end
103
105
 
104
- # Uncomment following block of code for handling engine requests/requests without controller
105
- # else
106
- # # Handling requests which do not have controllers (engines)
107
- if env["SCRIPT_NAME"].present?
108
- controller_path = "#{env['SCRIPT_NAME'][1..-1]}"
109
- controller_path = controller_path.sub("/", "::")
110
- request_path = "#{controller_path}#UnknownAction"
111
- else
112
- # Writing to telegraf: Handle 404
113
- if [404].include?(@status)
114
- content_type = @headers['Content-Type'].split(';')[0] if @headers['Content-Type']
115
- content_type = content_type.gsub('text/javascript', 'application/javascript')
116
- tags = {status: @status, content_type: content_type}
117
-
118
- tags = tags.merge({controller: 'ActionController', action: 'RoutingError' })
119
-
120
- values = {response_time: ((Time.now - start_time)*1000).round(2) }
121
-
122
- ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
106
+ # Uncomment following block of code for handling engine requests/requests without controller
107
+ # else
108
+ # # Handling requests which do not have controllers (engines)
109
+ if env["SCRIPT_NAME"].present?
110
+ controller_path = "#{env['SCRIPT_NAME'][1..-1]}"
111
+ controller_path = controller_path.sub("/", "::")
112
+ request_path = "#{controller_path}#UnknownAction"
113
+ else
114
+ # Writing to telegraf: Handle 404
115
+ if [404, 500].include?(@status)
116
+ content_type = @headers['Content-Type'].split(';')[0] if @headers['Content-Type']
117
+ content_type = content_type.gsub('text/javascript', 'application/javascript')
118
+ tags = {status: @status, content_type: content_type}
119
+
120
+ tags = tags.merge({controller: 'ActionController'})
121
+ tags = tags.merge({action: 'RoutingError' }) if @status == 404
122
+
123
+ values = {response_time: ((Time.now - start_time)*1000).round(2) }
124
+
125
+ ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
126
+ end
123
127
  end
128
+ Thread.current[:inbound_metric] = nil
124
129
  end
125
130
  [@status, @headers, @response]
126
131
  end
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "1.7.50"
3
- end
2
+ VERSION = "1.7.51"
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.50
4
+ version: 1.7.51
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-01-18 00:00:00.000000000 Z
11
+ date: 2019-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment