zuora_connect 1.7.33 → 1.7.34

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: 2f654b5c863ebf96eb976039e87ffb65a17308e0
4
- data.tar.gz: fa630ad385d7876d468aaa63695829f77e10e61d
3
+ metadata.gz: 0db9c4ade0f13536864a0cda1feb9f83f60a2d51
4
+ data.tar.gz: b6582466206b5e6ee3fc6985044cf63e22079dd1
5
5
  SHA512:
6
- metadata.gz: abb8e9351ec64a2ee3ef7ba8c3e6cb28d08a345594eac30ab6f3941d23f19bc77a771f7471120e468f36872596f3e98ef7407af633b3d2fe383a869540b2f0f3
7
- data.tar.gz: 2bcf6376f63b0fa8fcf4592ab1c3204dfefd60b0b219d27bac2a2411b11bec30f2a8ad7999c227f78d1826fa74e0960c81d3f4c40fecae6eba3535419968b156
6
+ metadata.gz: 7d1b60cc22ff13938b7fc0334f13e14d66a765b0ee29cbca006599474ef75d10a152451cef66b8584a0e78e54680883834a6adf2f31bf14ed99120695ff16c7f
7
+ data.tar.gz: 473e3dea8f6ef996cb5caef766121ec143b2abc2903ba0005ff5c7c25684906bb5e10f2c77be343f3a750262e5ac2ef0021ec97043317075302cf1d3d1fae01e
@@ -42,68 +42,89 @@ module Middleware
42
42
  end
43
43
 
44
44
  def call(env)
45
- #Thread.current[:appinstance] = nil
46
- start_time = Time.now
47
- @status, @headers, @response = @app.call(env)
48
-
49
- # If the url contains any CSS or JavaScript files then do not collect metrics for them
50
- if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| env['PATH_INFO'].include?(word) } || /.*\.js$/.match(env['PATH_INFO'])
51
- tags = {status: @status, controller: 'ActionController', action: 'Assets', app_instance: 0}
52
- values = {response_time: ((Time.now - start_time)*1000).round(2) }
53
- ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: 'request-inbound-assets', tags: tags, values: values)
54
- end
45
+ @bad_headers = ["HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED_HOST", "HTTP_X_FORWARDED_PORT", "HTTP_X_FORWARDED_PROTO", "HTTP_X_FORWARDED_SCHEME", "HTTP_X_FORWARDED_SSL"]
46
+ if !ActionDispatch::Request::HTTP_METHODS.include?(env["REQUEST_METHOD"].upcase)
47
+ [405, {"Content-Type" => "text/plain"}, ["Method Not Allowed"]]
48
+ else
49
+ if (env['HTTP_ZUORA_LAYOUT_FETCH_TEMPLATE_ID'].present?)
50
+ Thread.current[:isHallway] = "/#{env['HTTP_ZUORA_LAYOUT_FETCH_TEMPLATE_ID']}"
51
+ env['PATH_INFO'] = env['PATH_INFO'].gsub(Thread.current[:isHallway], '')
52
+ env['REQUEST_URI'] = env['REQUEST_URI'].gsub(Thread.current[:isHallway], '')
53
+ env['REQUEST_PATH'] = env['REQUEST_PATH'].gsub(Thread.current[:isHallway], '')
54
+
55
+ #We need the forwarded host header to identify location of tenant
56
+ @bad_headers.delete('HTTP_X_FORWARDED_HOST')
57
+ else
58
+ Thread.current[:isHallway] = nil
59
+ end
55
60
 
56
- if defined? Prometheus
57
- #Prometheus Stuff
58
- if env['PATH_INFO'] == '/connect/internal/metrics'
61
+ #Remove bad headers
62
+ @bad_headers.each { |header| env.delete(header) }
59
63
 
60
- #Do something before each scrape
61
- if defined? Resque.redis
62
- begin
63
64
 
64
- Resque.redis.ping
65
+ #Thread.current[:appinstance] = nil
66
+ start_time = Time.now
67
+ @status, @headers, @response = @app.call(env)
65
68
 
66
- Prometheus::REDIS_CONNECTION.set({connection:'redis',name: ZuoraConnect::Telegraf.app_name},1)
67
- Prometheus::FINISHED_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:processed])
68
- Prometheus::PENDING_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:pending])
69
- Prometheus::ACTIVE_WORKERS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:working])
70
- Prometheus::WORKERS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:workers])
71
- Prometheus::FAILED_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:failed])
69
+ # If the url contains any CSS or JavaScript files then do not collect metrics for them
70
+ if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| env['PATH_INFO'].include?(word) } || /.*\.js$/.match(env['PATH_INFO'])
71
+ tags = {status: @status, controller: 'ActionController', action: 'Assets', app_instance: 0}
72
+ values = {response_time: ((Time.now - start_time)*1000).round(2) }
73
+ ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: 'request-inbound-assets', tags: tags, values: values)
74
+ end
72
75
 
73
- rescue Redis::CannotConnectError
74
- Prometheus::REDIS_CONNECTION.set({connection:'redis',name: ZuoraConnect::Telegraf.app_name},0)
75
- end
76
+ if defined? Prometheus
77
+ #Prometheus Stuff
78
+ if env['PATH_INFO'] == '/connect/internal/metrics'
79
+
80
+ #Do something before each scrape
81
+ if defined? Resque.redis
82
+ begin
83
+
84
+ Resque.redis.ping
85
+
86
+ Prometheus::REDIS_CONNECTION.set({connection:'redis',name: ZuoraConnect::Telegraf.app_name},1)
87
+ Prometheus::FINISHED_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:processed])
88
+ Prometheus::PENDING_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:pending])
89
+ Prometheus::ACTIVE_WORKERS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:working])
90
+ Prometheus::WORKERS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:workers])
91
+ Prometheus::FAILED_JOBS.set({type:'resque',name: ZuoraConnect::Telegraf.app_name},Resque.info[:failed])
76
92
 
77
- if ZuoraConnect.configuration.custom_prometheus_update_block != nil
78
- ZuoraConnect.configuration.custom_prometheus_update_block.call()
93
+ rescue Redis::CannotConnectError
94
+ Prometheus::REDIS_CONNECTION.set({connection:'redis',name: ZuoraConnect::Telegraf.app_name},0)
95
+ end
96
+
97
+ if ZuoraConnect.configuration.custom_prometheus_update_block != nil
98
+ ZuoraConnect.configuration.custom_prometheus_update_block.call()
99
+ end
79
100
  end
80
- end
81
101
 
102
+ end
82
103
  end
83
- end
84
104
 
85
- # Uncomment following block of code for handling engine requests/requests without controller
86
- # else
87
- # # Handling requests which do not have controllers (engines)
88
- if env["SCRIPT_NAME"].present?
89
- controller_path = "#{env['SCRIPT_NAME'][1..-1]}"
90
- controller_path = controller_path.sub("/", "::")
91
- request_path = "#{controller_path}#UnknownAction"
92
- else
93
- # Writing to telegraf: Handle 404
94
- if [404].include?(@status)
95
- content_type = @headers['Content-Type'].split(';')[0] if @headers['Content-Type']
96
- content_type = content_type.gsub('text/javascript', 'application/javascript')
97
- tags = {status: @status, content_type: content_type}
98
-
99
- tags = tags.merge({controller: 'ActionController', action: 'RoutingError' })
100
-
101
- values = {response_time: ((Time.now - start_time)*1000).round(2) }
102
-
103
- ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
105
+ # Uncomment following block of code for handling engine requests/requests without controller
106
+ # else
107
+ # # Handling requests which do not have controllers (engines)
108
+ if env["SCRIPT_NAME"].present?
109
+ controller_path = "#{env['SCRIPT_NAME'][1..-1]}"
110
+ controller_path = controller_path.sub("/", "::")
111
+ request_path = "#{controller_path}#UnknownAction"
112
+ else
113
+ # Writing to telegraf: Handle 404
114
+ if [404].include?(@status)
115
+ content_type = @headers['Content-Type'].split(';')[0] if @headers['Content-Type']
116
+ content_type = content_type.gsub('text/javascript', 'application/javascript')
117
+ tags = {status: @status, content_type: content_type}
118
+
119
+ tags = tags.merge({controller: 'ActionController', action: 'RoutingError' })
120
+
121
+ values = {response_time: ((Time.now - start_time)*1000).round(2) }
122
+
123
+ ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
124
+ end
104
125
  end
126
+ [@status, @headers, @response]
105
127
  end
106
- [@status, @headers, @response]
107
128
  end
108
129
  end
109
130
  end
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "1.7.33"
2
+ VERSION = "1.7.34"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.33
4
+ version: 1.7.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team