zuora_connect 1.7.02 → 1.7.03
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 043bacd1f74b2e3a3e22d8cffe8f642081b5d265
|
4
|
+
data.tar.gz: f5cae6cafedaa42f6ed37028d4794b17c858d1f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d641103cfb8016b386f8a47e5d75740ad044967ce988264b775d74fa19cb6bf7fd1c36097713c80ab680ee09dab3e429b50cfabcc6b00302eb2cd565a4a8529
|
7
|
+
data.tar.gz: 0ada5cd7bff5dae2135e6d8871d34df83450e594125030e5cf3a44e3ac34662483a66f649807db57166df7bf01e9c20a29ada8e2500e85afd85863c49d674132
|
@@ -25,102 +25,6 @@ module ZuoraConnect
|
|
25
25
|
self.apartment_switch(nil, true)
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.write_metric(series: 'Unknown', tags: {}, values: {})
|
29
|
-
begin
|
30
|
-
if @@telegraf_host.blank?
|
31
|
-
Rails.logger.debug('Need new connection') if ZuoraConnect.configuration.telegraf_debug
|
32
|
-
uri = URI.parse(ZuoraConnect.configuration.telegraf_endpoint)
|
33
|
-
@@telegraf_host = UDPSocket.new.tap do |socket|
|
34
|
-
socket.connect uri.host, uri.port
|
35
|
-
end
|
36
|
-
end
|
37
|
-
@@telegraf_host.write InfluxDB::PointValue.new({series: series, tags: tags, values: values}).dump
|
38
|
-
rescue => ex
|
39
|
-
@@telegraf_host = nil
|
40
|
-
Rails.logger.tagged("Telegraf") do
|
41
|
-
logger.warn('Failed to write')
|
42
|
-
logger.warn(ex.class)
|
43
|
-
logger.warn(ex.message)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Methods for writing Telegraf metrics
|
49
|
-
|
50
|
-
# Returns the process type if any
|
51
|
-
def self.get_process_type
|
52
|
-
p_type = 'Unknown'
|
53
|
-
if ENV['HOSTNAME'] && ENV['DEIS_APP']
|
54
|
-
temp = ENV['HOSTNAME'].split(ENV['DEIS_APP'])[1]
|
55
|
-
temp = temp.split(/(-[0-9a-zA-Z]{5})$/)[0] # remove the 5 char hash
|
56
|
-
p_type = temp[1, temp.rindex("-")-1]
|
57
|
-
end
|
58
|
-
return p_type
|
59
|
-
end
|
60
|
-
|
61
|
-
# Write to telegraf
|
62
|
-
def self.write_to_telegraf(direction: nil, tags: {}, values: {})
|
63
|
-
time = Benchmark.measure do |bench|
|
64
|
-
# To avoid writing metrics from rspec tests
|
65
|
-
if ENV['DEIS_APP'] || true
|
66
|
-
# Getting the process type
|
67
|
-
p_type = self.get_process_type
|
68
|
-
app_instance = Thread.current[:appinstance].present? ? Thread.current[:appinstance].id : 0
|
69
|
-
tags = tags.merge({ app_name: ZuoraConnect.configuration.app_name, process_type: p_type, app_instance: app_instance})
|
70
|
-
|
71
|
-
if direction == :inbound && ZuoraConnect.configuration.enable_inbound_metrics_flag
|
72
|
-
series = ZuoraConnect.configuration.influxdb_series_name_inbound
|
73
|
-
self.write_metric(series: series, tags: tags, values: values)
|
74
|
-
elsif direction == :outbound && ZuoraConnect.configuration.enable_outbound_metrics_flag
|
75
|
-
series = ZuoraConnect.configuration.influxdb_series_name_outbound
|
76
|
-
self.write_metric(series: series, tags: tags, values: values)
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
81
|
-
if ZuoraConnect.configuration.telegraf_debug
|
82
|
-
Rails.logger.debug(tags.to_s)
|
83
|
-
Rails.logger.debug(values.to_s)
|
84
|
-
Rails.logger.debug("Writing #{direction.capitalize}: #{time.real.round(4)}")
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.get_metrics(type)
|
89
|
-
namespace = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
|
90
|
-
|
91
|
-
@data = {}
|
92
|
-
|
93
|
-
if type == "versions"
|
94
|
-
@data = {
|
95
|
-
app_name: namespace,
|
96
|
-
url: "dummy",
|
97
|
-
Version_Gem: ZuoraConnect::VERSION,
|
98
|
-
Version_Zuora: ZuoraAPI::VERSION ,
|
99
|
-
Version_Ruby: RUBY_VERSION,
|
100
|
-
Version_Rails: Rails.version,
|
101
|
-
hold: 1
|
102
|
-
}
|
103
|
-
elsif type == "stats"
|
104
|
-
begin
|
105
|
-
Resque.redis.ping
|
106
|
-
@data = {
|
107
|
-
app_name: namespace,
|
108
|
-
url: "dummy",
|
109
|
-
Resque:{
|
110
|
-
Jobs_Finished: Resque.info[:processed] ,
|
111
|
-
Jobs_Failed: Resque.info[:failed],
|
112
|
-
Jobs_Pending: Resque.info[:pending],
|
113
|
-
Workers_Active: Resque.info[:working],
|
114
|
-
Workers_Total: Resque.info[:workers]
|
115
|
-
}
|
116
|
-
}
|
117
|
-
rescue
|
118
|
-
end
|
119
|
-
end
|
120
|
-
return @data
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
28
|
def apartment_switch(method = nil, migrate = false)
|
125
29
|
begin
|
126
30
|
Apartment::Tenant.switch!(self.id) if self.persisted?
|
@@ -158,7 +62,7 @@ module ZuoraConnect
|
|
158
62
|
mock_task_data[k] = v
|
159
63
|
end
|
160
64
|
|
161
|
-
build_task(mock_task_data, session)
|
65
|
+
self.build_task(task_data: mock_task_data, session: session)
|
162
66
|
else
|
163
67
|
time_expire = (session["#{self.id}::last_refresh"] || Time.now).to_i - INSTANCE_REFRESH_WINDOW.ago.to_i
|
164
68
|
|
@@ -192,7 +96,7 @@ module ZuoraConnect
|
|
192
96
|
else
|
193
97
|
Rails.logger.info("[#{self.id}] REBUILDING - Expires in #{time_expire} seconds")
|
194
98
|
end
|
195
|
-
build_task(session["#{self.id}::task_data"], session)
|
99
|
+
self.build_task(task_data: session["#{self.id}::task_data"], session: session)
|
196
100
|
end
|
197
101
|
end
|
198
102
|
begin
|
@@ -220,7 +124,7 @@ module ZuoraConnect
|
|
220
124
|
|
221
125
|
Rails.logger.debug("[#{self.id}] REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}")
|
222
126
|
if response.code == 200
|
223
|
-
build_task(JSON.parse(response.body), session)
|
127
|
+
self.build_task(task_data: JSON.parse(response.body), session: session)
|
224
128
|
self.last_refresh = Time.now.to_i
|
225
129
|
self.cache_app_instance
|
226
130
|
self.reset_mark_for_refresh
|
@@ -249,14 +153,56 @@ module ZuoraConnect
|
|
249
153
|
end
|
250
154
|
end
|
251
155
|
|
156
|
+
#### START Metrics Mathods ####
|
157
|
+
def self.write_to_telegraf(*args)
|
158
|
+
@@telegraf_host = ZuoraConnect::Telegraf.new() if @@telegraf_host == nil
|
159
|
+
return @@telegraf_host.write(*args)
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.get_metrics(type)
|
163
|
+
namespace = ENV['DEIS_APP'].present? ? "#{ENV['DEIS_APP']}" : "#{Rails.application.class.parent_name}"
|
164
|
+
|
165
|
+
@data = {}
|
166
|
+
|
167
|
+
if type == "versions"
|
168
|
+
@data = {
|
169
|
+
app_name: namespace,
|
170
|
+
url: "dummy",
|
171
|
+
Version_Gem: ZuoraConnect::VERSION,
|
172
|
+
Version_Zuora: ZuoraAPI::VERSION ,
|
173
|
+
Version_Ruby: RUBY_VERSION,
|
174
|
+
Version_Rails: Rails.version,
|
175
|
+
hold: 1
|
176
|
+
}
|
177
|
+
elsif type == "stats"
|
178
|
+
begin
|
179
|
+
Resque.redis.ping
|
180
|
+
@data = {
|
181
|
+
app_name: namespace,
|
182
|
+
url: "dummy",
|
183
|
+
Resque:{
|
184
|
+
Jobs_Finished: Resque.info[:processed] ,
|
185
|
+
Jobs_Failed: Resque.info[:failed],
|
186
|
+
Jobs_Pending: Resque.info[:pending],
|
187
|
+
Workers_Active: Resque.info[:working],
|
188
|
+
Workers_Total: Resque.info[:workers]
|
189
|
+
}
|
190
|
+
}
|
191
|
+
rescue
|
192
|
+
end
|
193
|
+
end
|
194
|
+
return @data
|
195
|
+
end
|
196
|
+
#### END Task Mathods ####
|
197
|
+
|
252
198
|
#### START Task Mathods ####
|
253
|
-
def build_task(task_data, session)
|
254
|
-
|
255
|
-
|
256
|
-
|
199
|
+
def build_task(task_data: {}, session: {})
|
200
|
+
self.task_data = task_data
|
201
|
+
self.mode = self.task_data["mode"]
|
202
|
+
self.task_data.each do |k,v|
|
257
203
|
if k.match(/^(.*)_login$/)
|
258
204
|
tmp = ZuoraConnect::Login.new(v)
|
259
|
-
if
|
205
|
+
if v["tenant_type"] == "Zuora"
|
260
206
|
if tmp.entities.size > 0
|
261
207
|
tmp.entities.each do |value|
|
262
208
|
entity_id = value["id"]
|
@@ -269,16 +215,16 @@ module ZuoraConnect
|
|
269
215
|
tmp.client.bearer_token = session["#{self.id}::#{k}:bearer_token"] if session["#{self.id}::#{k}:bearer_token"] && tmp.client.respond_to?(:bearer_token) ## need incase session id goes from basic to aouth in same redis store
|
270
216
|
tmp.client.oauth_session_expires_at = session["#{self.id}::#{k}:oauth_session_expires_at"] if session["#{self.id}::#{k}:oauth_session_expires_at"] && tmp.client.respond_to?(:oauth_session_expires_at)
|
271
217
|
end
|
272
|
-
|
218
|
+
self.logins[k] = tmp
|
273
219
|
self.attr_builder(k, @logins[k])
|
274
|
-
elsif k == "options"
|
275
|
-
v.each do |opt|
|
276
|
-
@options[opt["config_name"]] = opt
|
277
|
-
end
|
278
|
-
elsif k == "user_settings"
|
279
|
-
self.timezone = v["timezone"]
|
280
|
-
self.locale = v["local"]
|
281
220
|
end
|
221
|
+
elsif k == "options"
|
222
|
+
v.each do |opt|
|
223
|
+
self.options[opt["config_name"]] = opt
|
224
|
+
end
|
225
|
+
elsif k == "user_settings"
|
226
|
+
self.timezone = v["timezone"]
|
227
|
+
self.locale = v["local"]
|
282
228
|
end
|
283
229
|
end
|
284
230
|
rescue => ex
|
@@ -299,7 +245,7 @@ module ZuoraConnect
|
|
299
245
|
parsed_json = JSON.parse(response.body)
|
300
246
|
if response.code == 200
|
301
247
|
if defined?(Redis.current)
|
302
|
-
self.build_task(parsed_json, self.data_lookup)
|
248
|
+
self.build_task(task_data: parsed_json, session: self.data_lookup)
|
303
249
|
self.last_refresh = Time.now.to_i
|
304
250
|
self.cache_app_instance
|
305
251
|
end
|
@@ -499,8 +445,7 @@ module ZuoraConnect
|
|
499
445
|
|
500
446
|
def encrypt_data(data: nil)
|
501
447
|
return data if data.blank?
|
502
|
-
|
503
|
-
if ['development', 'test'].include?(Rails.env)
|
448
|
+
if Rails.env == 'development'
|
504
449
|
return data.to_json
|
505
450
|
else
|
506
451
|
return encryptor.encrypt_and_sign(data.to_json)
|
@@ -5,15 +5,14 @@ module ZuoraConnect
|
|
5
5
|
@clients = {}
|
6
6
|
if fields["tenant_type"] == "Zuora"
|
7
7
|
login_fields = fields.map{|k,v| [k.to_sym, v]}.to_h
|
8
|
-
|
9
|
-
fields["authentication_type"] = "basic" if fields["authentication_type"].nil? || fields["authentication_type"].blank?
|
8
|
+
login_type = fields.dig("authentication_type").blank? ? 'Basic' : fields.dig("authentication_type").capitalize
|
10
9
|
|
11
|
-
@clients["Default"] = "::ZuoraAPI::#{
|
10
|
+
@clients["Default"] = "::ZuoraAPI::#{login_type}".constantize.new(login_fields)
|
12
11
|
@default_entity = fields["entities"][0]["id"] if fields["entities"].size == 1 if fields["entities"] && fields["entities"].size > 0
|
13
12
|
if fields["entities"] && fields["entities"].size > 0
|
14
13
|
fields["entities"].each do |entity|
|
15
14
|
params = {:entity_id => entity["id"]}.merge(login_fields)
|
16
|
-
@clients[entity["id"]] = "::ZuoraAPI::#{
|
15
|
+
@clients[entity["id"]] = "::ZuoraAPI::#{login_type}".constantize.new(params)
|
17
16
|
end
|
18
17
|
end
|
19
18
|
self.attr_builder("available_entities", @clients.keys)
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module ZuoraConnect
|
2
|
+
class Telegraf
|
3
|
+
attr_accessor :host
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.connect
|
7
|
+
end
|
8
|
+
|
9
|
+
def connect
|
10
|
+
Rails.logger.debug(self.format_metric_log('Telegraf','Need new connection')) if ZuoraConnect.configuration.telegraf_debug
|
11
|
+
uri = URI.parse(ZuoraConnect.configuration.telegraf_endpoint)
|
12
|
+
self.host = UDPSocket.new.tap do |socket|
|
13
|
+
socket.connect uri.host, uri.port
|
14
|
+
end
|
15
|
+
rescue => ex
|
16
|
+
self.host = nil
|
17
|
+
Rails.logger.warn(self.format_metric_log('Telegraf', 'Failed to connect'))
|
18
|
+
Rails.logger.warn(self.format_metric_log('Telegraf', ex.class))
|
19
|
+
Rails.logger.warn(self.format_metric_log('Telegraf', ex.message))
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(direction: 'Default', tags: {}, values: {})
|
23
|
+
time = Benchmark.measure do |bench|
|
24
|
+
# To avoid writing metrics from rspec tests
|
25
|
+
if ENV['DEIS_APP'] || true
|
26
|
+
# Getting the process type
|
27
|
+
p_type = self.get_process_type
|
28
|
+
app_instance = Thread.current[:appinstance].present? ? Thread.current[:appinstance].id : 0
|
29
|
+
tags = tags.merge({ app_name: ZuoraConnect.configuration.app_name, process_type: p_type, app_instance: app_instance})
|
30
|
+
|
31
|
+
if direction == :inbound && ZuoraConnect.configuration.enable_inbound_metrics_flag
|
32
|
+
series = ZuoraConnect.configuration.influxdb_series_name_inbound
|
33
|
+
self.write_udp(series: series, tags: tags, values: values)
|
34
|
+
elsif direction == :outbound && ZuoraConnect.configuration.enable_outbound_metrics_flag
|
35
|
+
series = ZuoraConnect.configuration.influxdb_series_name_outbound
|
36
|
+
self.write_udp(series: series, tags: tags, values: values)
|
37
|
+
else
|
38
|
+
self.write_udp(series: direction, tags: tags, values: values)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
if ZuoraConnect.configuration.telegraf_debug
|
43
|
+
Rails.logger.debug(self.format_metric_log('Telegraf', tags.to_s))
|
44
|
+
Rails.logger.debug(self.format_metric_log('Telegraf', values.to_s))
|
45
|
+
Rails.logger.debug(self.format_metric_log('Telegraf', "Writing '#{direction.capitalize}': #{time.real.round(5)} ms"))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def write_udp(series: '', tags: {}, values: {})
|
51
|
+
return if !values.present?
|
52
|
+
|
53
|
+
self.host.write InfluxDB::PointValue.new({series: series, tags: tags, values: values}).dump
|
54
|
+
rescue => ex
|
55
|
+
self.connect
|
56
|
+
Rails.logger.warn(self.format_metric_log('Telegraf','Failed to write udp'))
|
57
|
+
Rails.logger.warn(self.format_metric_log('Telegraf', ex.class))
|
58
|
+
Rails.logger.warn(self.format_metric_log('Telegraf', ex.message))
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns the process type if any
|
62
|
+
def get_process_type
|
63
|
+
p_type = 'Unknown'
|
64
|
+
if ENV['HOSTNAME'] && ENV['DEIS_APP']
|
65
|
+
temp = ENV['HOSTNAME'].split(ENV['DEIS_APP'])[1]
|
66
|
+
temp = temp.split(/(-[0-9a-zA-Z]{5})$/)[0] # remove the 5 char hash
|
67
|
+
p_type = temp[1, temp.rindex("-")-1]
|
68
|
+
end
|
69
|
+
return p_type
|
70
|
+
end
|
71
|
+
|
72
|
+
def format_metric_log(message, dump = nil)
|
73
|
+
message_color, dump_color = "1;91", "0;1"
|
74
|
+
log_entry = " \e[#{message_color}m#{message}\e[0m "
|
75
|
+
log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
|
76
|
+
log_entry
|
77
|
+
end
|
78
|
+
end
|
79
|
+
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.
|
4
|
+
version: 1.7.03
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connect Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apartment
|
@@ -260,6 +260,7 @@ files:
|
|
260
260
|
- app/models/zuora_connect/app_instance.rb
|
261
261
|
- app/models/zuora_connect/app_instance_base.rb
|
262
262
|
- app/models/zuora_connect/login.rb
|
263
|
+
- app/models/zuora_connect/telegraf.rb
|
263
264
|
- app/views/layouts/zuora_connect/application.html.erb
|
264
265
|
- app/views/sql/refresh_aggregate_table.txt
|
265
266
|
- app/views/zuora_connect/static/invalid_app_instance_error.html.erb
|