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 +4 -4
- data/lib/middleware/metrics_middleware.rb +71 -50
- data/lib/zuora_connect/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0db9c4ade0f13536864a0cda1feb9f83f60a2d51
|
4
|
+
data.tar.gz: b6582466206b5e6ee3fc6985044cf63e22079dd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
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
|
-
|
65
|
+
#Thread.current[:appinstance] = nil
|
66
|
+
start_time = Time.now
|
67
|
+
@status, @headers, @response = @app.call(env)
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
78
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|