moesif_rack 1.4.13 → 1.4.17
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/README.md +1 -1
- data/lib/moesif_rack/app_config.rb +36 -22
- data/lib/moesif_rack/{helpers.rb → moesif_helpers.rb} +1 -1
- data/lib/moesif_rack/moesif_middleware.rb +38 -36
- data/lib/moesif_rack/regex_config_helper.rb +119 -0
- data/moesif_capture_outgoing/httplog/http_log.rb +1 -1
- data/test/moesif_rack_test.rb +2 -1
- metadata +16 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b73acd14bb1af6f2d4ee8225fdd39ee19c6d1d9cf937ad37a9b10a7278842272
|
|
4
|
+
data.tar.gz: c1e74c3f4afdbdbfe0cef5fc75dca534f8d289c0f0befdac9085b9f48d4575bf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 186263e17ebe464783f65297d205c6fea8dcde346ecf979bc1c79c0fd2468e31f474ab278ca94ff2664f6ebd5b9b5a8bc991f00c7f82532ccf709091d6db543e
|
|
7
|
+
data.tar.gz: e7c29d009f3dc63464181025aa2679f45ee1b3972c72402934e43fa4fef0e778da300084d03b524f689c1b2dda81f3d16a351deb234c68d06cd01f21bd847111
|
data/README.md
CHANGED
|
@@ -529,7 +529,7 @@ response = MoesifRack::MoesifMiddleware.new(@app, @options).update_companies_bat
|
|
|
529
529
|
1. Manually clone the git repo
|
|
530
530
|
2. From terminal/cmd navigate to the root directory of the middleware.
|
|
531
531
|
3. Invoke 'gem install moesif_rack'
|
|
532
|
-
4. Add your own application id to 'test/moesif_rack_test.rb'. You can find your Application Id from [_Moesif Dashboard_](https://www.moesif.com/) ->
|
|
532
|
+
4. Add your own application id to 'test/moesif_rack_test.rb'. You can find your Application Id from [_Moesif Dashboard_](https://www.moesif.com/) -> _Bottom Left Menu_ -> _Installation_
|
|
533
533
|
5. Invoke 'ruby test/moesif_rack_test.rb'
|
|
534
534
|
6. Invoke 'ruby -I test test/moesif_rack_test.rb -n test_capture_outgoing' to test capturing outgoing API calls from your app to third parties like Stripe, Github or to your own dependencies.
|
|
535
535
|
|
|
@@ -3,30 +3,32 @@ require 'json'
|
|
|
3
3
|
require 'time'
|
|
4
4
|
require 'zlib'
|
|
5
5
|
require 'stringio'
|
|
6
|
-
require_relative './
|
|
6
|
+
require_relative './moesif_helpers.rb'
|
|
7
|
+
require_relative './regex_config_helper.rb'
|
|
7
8
|
|
|
8
9
|
class AppConfig
|
|
9
10
|
|
|
10
11
|
def initialize debug
|
|
11
12
|
@debug = debug
|
|
12
|
-
@
|
|
13
|
+
@moesif_helpers = MoesifHelpers.new(debug)
|
|
14
|
+
@regex_config_helper = RegexConfigHelper.new(debug)
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def get_config(api_controller)
|
|
16
18
|
# Get Application Config
|
|
17
19
|
begin
|
|
18
20
|
config_api_response = api_controller.get_app_config()
|
|
19
|
-
@
|
|
20
|
-
@
|
|
21
|
+
@moesif_helpers.log_debug("new config downloaded")
|
|
22
|
+
@moesif_helpers.log_debug(config_api_response.to_s)
|
|
21
23
|
return config_api_response
|
|
22
24
|
rescue MoesifApi::APIException => e
|
|
23
25
|
if e.response_code.between?(401, 403)
|
|
24
|
-
@
|
|
26
|
+
@moesif_helpers.log_debug 'Unauthorized access getting application configuration. Please check your Appplication Id.'
|
|
25
27
|
end
|
|
26
|
-
@
|
|
27
|
-
@
|
|
28
|
+
@moesif_helpers.log_debug 'Error getting application configuration, with status code:'
|
|
29
|
+
@moesif_helpers.log_debug e.response_code
|
|
28
30
|
rescue => e
|
|
29
|
-
@
|
|
31
|
+
@moesif_helpers.log_debug e.to_s
|
|
30
32
|
end
|
|
31
33
|
rescue
|
|
32
34
|
end
|
|
@@ -36,32 +38,43 @@ class AppConfig
|
|
|
36
38
|
begin
|
|
37
39
|
# Rails return gzipped compressed response body, so decompressing it and getting JSON response body
|
|
38
40
|
response_body = decompress_gzip_body(config_api_response)
|
|
39
|
-
@
|
|
41
|
+
@moesif_helpers.log_debug(response_body.to_s)
|
|
40
42
|
|
|
41
43
|
# Check if response body is not nil
|
|
42
44
|
if !response_body.nil? then
|
|
43
45
|
# Return Etag, sample rate and last updated time
|
|
44
46
|
return response_body, config_api_response.headers[:x_moesif_config_etag], Time.now.utc
|
|
45
47
|
else
|
|
46
|
-
@
|
|
48
|
+
@moesif_helpers.log_debug 'Response body is nil, assuming default behavior'
|
|
47
49
|
# Response body is nil, so assuming default behavior
|
|
48
|
-
return nil,
|
|
50
|
+
return nil, nil, Time.now.utc
|
|
49
51
|
end
|
|
50
52
|
rescue => exception
|
|
51
|
-
@
|
|
52
|
-
@
|
|
53
|
+
@moesif_helpers.log_debug 'Error while parsing the configuration object, assuming default behavior'
|
|
54
|
+
@moesif_helpers.log_debug exception.to_s
|
|
53
55
|
# Assuming default behavior
|
|
54
|
-
return nil,
|
|
56
|
+
return nil, nil, Time.now.utc
|
|
55
57
|
end
|
|
56
58
|
end
|
|
57
59
|
|
|
58
|
-
def get_sampling_percentage(config_api_response, user_id, company_id)
|
|
60
|
+
def get_sampling_percentage(event_model, config_api_response, user_id, company_id)
|
|
59
61
|
# Get sampling percentage
|
|
60
62
|
begin
|
|
61
63
|
# Check if response body is not nil
|
|
62
64
|
if !config_api_response.nil? then
|
|
63
|
-
@
|
|
64
|
-
@
|
|
65
|
+
@moesif_helpers.log_debug("Getting sample rate for user #{user_id} company #{company_id}")
|
|
66
|
+
@moesif_helpers.log_debug(config_api_response.to_s)
|
|
67
|
+
|
|
68
|
+
# Get Regex Sampling rate
|
|
69
|
+
regex_config = config_api_response.fetch('regex_config', nil)
|
|
70
|
+
|
|
71
|
+
if !regex_config.nil? and !event_model.nil?
|
|
72
|
+
config_mapping = @regex_config_helper.prepare_config_mapping(event_model)
|
|
73
|
+
regex_sample_rate = @regex_config_helper.fetch_sample_rate_on_regex_match(regex_config, config_mapping)
|
|
74
|
+
if !regex_sample_rate.nil?
|
|
75
|
+
return regex_sample_rate
|
|
76
|
+
end
|
|
77
|
+
end
|
|
65
78
|
|
|
66
79
|
# Get user sample rate object
|
|
67
80
|
user_sample_rate = config_api_response.fetch('user_sample_rate', nil)
|
|
@@ -82,11 +95,12 @@ class AppConfig
|
|
|
82
95
|
# Return sample rate
|
|
83
96
|
return config_api_response.fetch('sample_rate', 100)
|
|
84
97
|
else
|
|
85
|
-
@
|
|
98
|
+
@moesif_helpers.log_debug 'Assuming default behavior as response body is nil - '
|
|
86
99
|
return 100
|
|
87
100
|
end
|
|
88
101
|
rescue => exception
|
|
89
|
-
@
|
|
102
|
+
@moesif_helpers.log_debug 'Error while geting sampling percentage, assuming default behavior'
|
|
103
|
+
@moesif_helpers.log_debug exception.to_s
|
|
90
104
|
return 100
|
|
91
105
|
end
|
|
92
106
|
end
|
|
@@ -106,12 +120,12 @@ class AppConfig
|
|
|
106
120
|
# Return the parsed body
|
|
107
121
|
return JSON.parse( uncompressed_string )
|
|
108
122
|
else
|
|
109
|
-
@
|
|
123
|
+
@moesif_helpers.log_debug 'Content Encoding is of type other than gzip, returning nil'
|
|
110
124
|
return nil
|
|
111
125
|
end
|
|
112
126
|
rescue => exception
|
|
113
|
-
@
|
|
114
|
-
@
|
|
127
|
+
@moesif_helpers.log_debug 'Error while decompressing the response body'
|
|
128
|
+
@moesif_helpers.log_debug exception.to_s
|
|
115
129
|
return nil
|
|
116
130
|
end
|
|
117
131
|
end
|
|
@@ -2,13 +2,13 @@ require 'moesif_api'
|
|
|
2
2
|
require 'json'
|
|
3
3
|
require 'time'
|
|
4
4
|
require 'base64'
|
|
5
|
+
require 'zlib'
|
|
6
|
+
require 'stringio'
|
|
5
7
|
require_relative './client_ip.rb'
|
|
6
8
|
require_relative './app_config.rb'
|
|
7
9
|
require_relative './update_user.rb'
|
|
8
10
|
require_relative './update_company.rb'
|
|
9
|
-
require_relative './
|
|
10
|
-
require 'zlib'
|
|
11
|
-
require 'stringio'
|
|
11
|
+
require_relative './moesif_helpers.rb'
|
|
12
12
|
|
|
13
13
|
module MoesifRack
|
|
14
14
|
|
|
@@ -30,7 +30,7 @@ module MoesifRack
|
|
|
30
30
|
@skip = options['skip']
|
|
31
31
|
@debug = options['debug']
|
|
32
32
|
@app_config = AppConfig.new(@debug)
|
|
33
|
-
@
|
|
33
|
+
@moesif_helpers = MoesifHelpers.new(@debug)
|
|
34
34
|
@config = @app_config.get_config(@api_controller)
|
|
35
35
|
@config_etag = nil
|
|
36
36
|
@last_config_download_time = Time.now.utc
|
|
@@ -50,13 +50,13 @@ module MoesifRack
|
|
|
50
50
|
@config, @config_etag, @last_config_download_time = @app_config.parse_configuration(new_config)
|
|
51
51
|
end
|
|
52
52
|
rescue => exception
|
|
53
|
-
@
|
|
54
|
-
@
|
|
53
|
+
@moesif_helpers.log_debug 'Error while parsing application configuration on initialization'
|
|
54
|
+
@moesif_helpers.log_debug exception.to_s
|
|
55
55
|
end
|
|
56
56
|
@capture_outoing_requests = options['capture_outoing_requests']
|
|
57
57
|
@capture_outgoing_requests = options['capture_outgoing_requests']
|
|
58
58
|
if @capture_outoing_requests || @capture_outgoing_requests
|
|
59
|
-
@
|
|
59
|
+
@moesif_helpers.log_debug 'Start Capturing outgoing requests'
|
|
60
60
|
require_relative '../../moesif_capture_outgoing/httplog.rb'
|
|
61
61
|
MoesifCaptureOutgoing.start_capture_outgoing(options)
|
|
62
62
|
end
|
|
@@ -94,7 +94,7 @@ module MoesifRack
|
|
|
94
94
|
return Base64.encode64(body), 'base64'
|
|
95
95
|
end
|
|
96
96
|
|
|
97
|
-
def @
|
|
97
|
+
def @moesif_helpers.log_debug(message)
|
|
98
98
|
if @debug
|
|
99
99
|
puts("#{Time.now.to_s} [Moesif Middleware] PID #{Process.pid} TID #{Thread.current.object_id} #{message}")
|
|
100
100
|
end
|
|
@@ -130,26 +130,26 @@ module MoesifRack
|
|
|
130
130
|
until batch_events.size == @batch_size || @events_queue.empty? do
|
|
131
131
|
batch_events << @events_queue.pop
|
|
132
132
|
end
|
|
133
|
-
@
|
|
133
|
+
@moesif_helpers.log_debug("Sending #{batch_events.size.to_s} events to Moesif")
|
|
134
134
|
event_api_response = @api_controller.create_events_batch(batch_events)
|
|
135
135
|
@event_response_config_etag = event_api_response[:x_moesif_config_etag]
|
|
136
|
-
@
|
|
137
|
-
@
|
|
136
|
+
@moesif_helpers.log_debug(event_api_response.to_s)
|
|
137
|
+
@moesif_helpers.log_debug("Events successfully sent to Moesif")
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
if @events_queue.empty?
|
|
141
|
-
@
|
|
141
|
+
@moesif_helpers.log_debug("No events to read from the queue")
|
|
142
142
|
end
|
|
143
143
|
|
|
144
144
|
sleep @batch_max_time
|
|
145
145
|
rescue MoesifApi::APIException => e
|
|
146
146
|
if e.response_code.between?(401, 403)
|
|
147
147
|
puts "Unathorized accesss sending event to Moesif. Please verify your Application Id."
|
|
148
|
-
@
|
|
148
|
+
@moesif_helpers.log_debug(e.to_s)
|
|
149
149
|
end
|
|
150
|
-
@
|
|
150
|
+
@moesif_helpers.log_debug("Error sending event to Moesif, with status code #{e.response_code.to_s}")
|
|
151
151
|
rescue => e
|
|
152
|
-
@
|
|
152
|
+
@moesif_helpers.log_debug(e.to_s)
|
|
153
153
|
end
|
|
154
154
|
end
|
|
155
155
|
end
|
|
@@ -158,7 +158,7 @@ module MoesifRack
|
|
|
158
158
|
def call env
|
|
159
159
|
start_time = Time.now.utc.iso8601(3)
|
|
160
160
|
|
|
161
|
-
@
|
|
161
|
+
@moesif_helpers.log_debug('Calling Moesif middleware')
|
|
162
162
|
|
|
163
163
|
status, headers, body = @app.call env
|
|
164
164
|
end_time = Time.now.utc.iso8601(3)
|
|
@@ -256,41 +256,41 @@ module MoesifRack
|
|
|
256
256
|
event_model.direction = "Incoming"
|
|
257
257
|
|
|
258
258
|
if @identify_user
|
|
259
|
-
@
|
|
259
|
+
@moesif_helpers.log_debug "calling identify user proc"
|
|
260
260
|
event_model.user_id = @identify_user.call(env, headers, body)
|
|
261
261
|
end
|
|
262
262
|
|
|
263
263
|
if @identify_company
|
|
264
|
-
@
|
|
264
|
+
@moesif_helpers.log_debug "calling identify company proc"
|
|
265
265
|
event_model.company_id = @identify_company.call(env, headers, body)
|
|
266
266
|
end
|
|
267
267
|
|
|
268
268
|
if @get_metadata
|
|
269
|
-
@
|
|
269
|
+
@moesif_helpers.log_debug "calling get_metadata proc"
|
|
270
270
|
event_model.metadata = @get_metadata.call(env, headers, body)
|
|
271
271
|
end
|
|
272
272
|
|
|
273
273
|
if @identify_session
|
|
274
|
-
@
|
|
274
|
+
@moesif_helpers.log_debug "calling identify session proc"
|
|
275
275
|
event_model.session_token = @identify_session.call(env, headers, body)
|
|
276
276
|
end
|
|
277
277
|
if @mask_data
|
|
278
|
-
@
|
|
278
|
+
@moesif_helpers.log_debug "calling mask_data proc"
|
|
279
279
|
event_model = @mask_data.call(event_model)
|
|
280
280
|
end
|
|
281
281
|
|
|
282
|
-
@
|
|
283
|
-
@
|
|
282
|
+
@moesif_helpers.log_debug "sending data to moesif"
|
|
283
|
+
@moesif_helpers.log_debug event_model.to_json
|
|
284
284
|
# Perform the API call through the SDK function
|
|
285
285
|
begin
|
|
286
286
|
random_percentage = Random.rand(0.00..100.00)
|
|
287
287
|
|
|
288
288
|
begin
|
|
289
|
-
sampling_percentage = @app_config.get_sampling_percentage(@config, event_model.user_id, event_model.company_id)
|
|
290
|
-
@
|
|
289
|
+
sampling_percentage = @app_config.get_sampling_percentage(event_model, @config, event_model.user_id, event_model.company_id)
|
|
290
|
+
@moesif_helpers.log_debug "Using sample rate #{sampling_percentage}"
|
|
291
291
|
rescue => exception
|
|
292
|
-
@
|
|
293
|
-
@
|
|
292
|
+
@moesif_helpers.log_debug 'Error while getting sampling percentage, assuming default behavior'
|
|
293
|
+
@moesif_helpers.log_debug exception.to_s
|
|
294
294
|
sampling_percentage = 100
|
|
295
295
|
end
|
|
296
296
|
|
|
@@ -298,7 +298,7 @@ module MoesifRack
|
|
|
298
298
|
event_model.weight = @app_config.calculate_weight(sampling_percentage)
|
|
299
299
|
# Add Event to the queue
|
|
300
300
|
@events_queue << event_model
|
|
301
|
-
@
|
|
301
|
+
@moesif_helpers.log_debug("Event added to the queue ")
|
|
302
302
|
if Time.now.utc > (@last_worker_run + 60)
|
|
303
303
|
start_worker()
|
|
304
304
|
end
|
|
@@ -311,16 +311,16 @@ module MoesifRack
|
|
|
311
311
|
end
|
|
312
312
|
|
|
313
313
|
rescue => exception
|
|
314
|
-
@
|
|
315
|
-
@
|
|
314
|
+
@moesif_helpers.log_debug 'Error while updating the application configuration'
|
|
315
|
+
@moesif_helpers.log_debug exception.to_s
|
|
316
316
|
end
|
|
317
317
|
end
|
|
318
318
|
else
|
|
319
|
-
@
|
|
319
|
+
@moesif_helpers.log_debug("Skipped Event due to sampling percentage: " + sampling_percentage.to_s + " and random percentage: " + random_percentage.to_s)
|
|
320
320
|
end
|
|
321
321
|
rescue => exception
|
|
322
|
-
@
|
|
323
|
-
@
|
|
322
|
+
@moesif_helpers.log_debug "Error adding event to the queue "
|
|
323
|
+
@moesif_helpers.log_debug exception.to_s
|
|
324
324
|
end
|
|
325
325
|
|
|
326
326
|
end
|
|
@@ -337,10 +337,12 @@ module MoesifRack
|
|
|
337
337
|
begin
|
|
338
338
|
process_send.call
|
|
339
339
|
rescue => exception
|
|
340
|
-
@
|
|
341
|
-
@
|
|
342
|
-
@
|
|
340
|
+
@moesif_helpers.log_debug 'Error while logging event - '
|
|
341
|
+
@moesif_helpers.log_debug exception.to_s
|
|
342
|
+
@moesif_helpers.log_debug exception.backtrace
|
|
343
343
|
end
|
|
344
|
+
else
|
|
345
|
+
@moesif_helpers.log_debug "Skipped Event using should_skip configuration option."
|
|
344
346
|
end
|
|
345
347
|
|
|
346
348
|
[status, headers, body]
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
require 'moesif_api'
|
|
2
|
+
|
|
3
|
+
require_relative './moesif_helpers.rb'
|
|
4
|
+
|
|
5
|
+
class RegexConfigHelper
|
|
6
|
+
|
|
7
|
+
def initialize debug
|
|
8
|
+
@debug = debug
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def prepare_config_mapping(event)
|
|
12
|
+
# Function to prepare config mapping
|
|
13
|
+
# Params:
|
|
14
|
+
# - event: Event to be logged
|
|
15
|
+
# Return:
|
|
16
|
+
# - regex_config: Regex config mapping
|
|
17
|
+
regex_config = {}
|
|
18
|
+
|
|
19
|
+
# Config mapping for request.verb
|
|
20
|
+
if defined? event.request.verb
|
|
21
|
+
regex_config["request.verb"] = event.request.verb
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Config mapping for request.uri
|
|
25
|
+
if defined? event.request.uri
|
|
26
|
+
extracted = /http[s]*:\/\/[^\/]+(\/[^?]+)/.match(event.request.uri)
|
|
27
|
+
if !extracted.nil?
|
|
28
|
+
route_mapping = extracted.captures[0]
|
|
29
|
+
else
|
|
30
|
+
route_mapping = '/'
|
|
31
|
+
end
|
|
32
|
+
regex_config["request.route"] = route_mapping
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Config mapping for request.ip_address
|
|
36
|
+
if defined? event.request.ip_address
|
|
37
|
+
regex_config["request.ip_address"] = event.request.ip_address
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Config mapping for response.status
|
|
41
|
+
if defined? event.response.status
|
|
42
|
+
regex_config["response.status"] = event.response.status
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
return regex_config
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def regex_match(event_value, condition_value)
|
|
50
|
+
# Function to perform the regex matching with event value and condition value
|
|
51
|
+
# Params:
|
|
52
|
+
# - event_value: Value associated with event (request)
|
|
53
|
+
# - condition_value: Value associated with the regex config condition
|
|
54
|
+
# Return:
|
|
55
|
+
# - regex_matched: Regex matched value to determine if the regex match was successful
|
|
56
|
+
|
|
57
|
+
extracted = Regexp.new(condition_value).match(event_value)
|
|
58
|
+
if !extracted.nil?
|
|
59
|
+
return extracted.to_s
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def fetch_sample_rate_on_regex_match(regex_configs, config_mapping)
|
|
64
|
+
# Function to fetch the sample rate and determine if request needs to be block or not
|
|
65
|
+
# Args:
|
|
66
|
+
# - regex_configs: Regex configs
|
|
67
|
+
# - config_mapping: Config associated with the request
|
|
68
|
+
# Return:
|
|
69
|
+
# - sample_rate: Sample rate
|
|
70
|
+
|
|
71
|
+
# Iterate through the list of regex configs
|
|
72
|
+
regex_configs.each { |regex_rule|
|
|
73
|
+
# Fetch the sample rate
|
|
74
|
+
sample_rate = regex_rule["sample_rate"]
|
|
75
|
+
# Fetch the conditions
|
|
76
|
+
conditions = regex_rule["conditions"]
|
|
77
|
+
# Bool flag to determine if the regex conditions are matched
|
|
78
|
+
regex_matched = false
|
|
79
|
+
# Create a table to hold the conditions mapping (path and value)
|
|
80
|
+
condition_table = {}
|
|
81
|
+
|
|
82
|
+
# Iterate through the regex rule conditions and map the path and value
|
|
83
|
+
conditions.each { |condition|
|
|
84
|
+
# Add condition path -> value to the condition table
|
|
85
|
+
condition_table[condition["path"]] = condition["value"]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
# Iterate through conditions table and perform `and` operation between each conditions
|
|
89
|
+
condition_table.each do |path, values|
|
|
90
|
+
|
|
91
|
+
# Check if the path exists in the request config mapping
|
|
92
|
+
if !config_mapping[path].nil?
|
|
93
|
+
# Fetch the value of the path in request config mapping
|
|
94
|
+
event_data = config_mapping[path]
|
|
95
|
+
|
|
96
|
+
# Perform regex matching with event value
|
|
97
|
+
regex_matched = regex_match(event_data, values)
|
|
98
|
+
else
|
|
99
|
+
# Path does not exists in request config mapping, so no need to match regex condition rule
|
|
100
|
+
regex_matched = false
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# If one of the rule does not match, skip the condition & avoid matching other rules for the same condition
|
|
104
|
+
if !regex_matched
|
|
105
|
+
break
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# If regex conditions matched, return sample rate
|
|
110
|
+
if regex_matched
|
|
111
|
+
return sample_rate
|
|
112
|
+
end
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
# If regex conditions are not matched, return sample rate as None and will use default sample rate
|
|
116
|
+
return nil
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end
|
|
@@ -176,7 +176,7 @@ module MoesifCaptureOutgoing
|
|
|
176
176
|
begin
|
|
177
177
|
@random_percentage = Random.rand(0.00..100.00)
|
|
178
178
|
begin
|
|
179
|
-
@sampling_percentage = @app_config.get_sampling_percentage(@config, event_model.user_id, event_model.company_id)
|
|
179
|
+
@sampling_percentage = @app_config.get_sampling_percentage(event_model, @config, event_model.user_id, event_model.company_id)
|
|
180
180
|
rescue => exception
|
|
181
181
|
if @debug
|
|
182
182
|
puts 'Error while getting sampling percentage, assuming default behavior'
|
data/test/moesif_rack_test.rb
CHANGED
|
@@ -117,7 +117,8 @@ class MoesifRackTest < Test::Unit::TestCase
|
|
|
117
117
|
@api_client = MoesifApi::MoesifAPIClient.new(@options['application_id'])
|
|
118
118
|
@api_controller = @api_client.api
|
|
119
119
|
@config = @app_config.get_config(@api_controller)
|
|
120
|
-
@
|
|
120
|
+
@config_body, @config_etag, @last_updated_time = @app_config.parse_configuration(@config)
|
|
121
|
+
@sampling_percentage = @app_config.get_sampling_percentage(nil, @config_body, nil, nil)
|
|
121
122
|
assert_operator 100, :>=, @sampling_percentage
|
|
122
123
|
end
|
|
123
124
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moesif_rack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.4.
|
|
4
|
+
version: 1.4.17
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Moesif, Inc
|
|
@@ -9,48 +9,42 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2022-08-23 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: test-unit
|
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
|
16
17
|
requirements:
|
|
17
18
|
- - "~>"
|
|
18
19
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '3.
|
|
20
|
+
version: '3.5'
|
|
20
21
|
- - ">="
|
|
21
22
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: 3.
|
|
23
|
-
name: test-unit
|
|
24
|
-
prerelease: false
|
|
23
|
+
version: 3.5.0
|
|
25
24
|
type: :development
|
|
25
|
+
prerelease: false
|
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
|
27
27
|
requirements:
|
|
28
28
|
- - "~>"
|
|
29
29
|
- !ruby/object:Gem::Version
|
|
30
|
-
version: '3.
|
|
30
|
+
version: '3.5'
|
|
31
31
|
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 3.
|
|
33
|
+
version: 3.5.0
|
|
34
34
|
- !ruby/object:Gem::Dependency
|
|
35
|
+
name: moesif_api
|
|
35
36
|
requirement: !ruby/object:Gem::Requirement
|
|
36
37
|
requirements:
|
|
37
38
|
- - "~>"
|
|
38
39
|
- !ruby/object:Gem::Version
|
|
39
|
-
version:
|
|
40
|
-
- - ">="
|
|
41
|
-
- !ruby/object:Gem::Version
|
|
42
|
-
version: 1.2.12
|
|
43
|
-
name: moesif_api
|
|
44
|
-
prerelease: false
|
|
40
|
+
version: 1.2.14
|
|
45
41
|
type: :runtime
|
|
42
|
+
prerelease: false
|
|
46
43
|
version_requirements: !ruby/object:Gem::Requirement
|
|
47
44
|
requirements:
|
|
48
45
|
- - "~>"
|
|
49
46
|
- !ruby/object:Gem::Version
|
|
50
|
-
version:
|
|
51
|
-
- - ">="
|
|
52
|
-
- !ruby/object:Gem::Version
|
|
53
|
-
version: 1.2.12
|
|
47
|
+
version: 1.2.14
|
|
54
48
|
description: Rack/Rails middleware to log API calls to Moesif API analytics and monitoring
|
|
55
49
|
email: xing@moesif.com
|
|
56
50
|
executables: []
|
|
@@ -62,8 +56,9 @@ files:
|
|
|
62
56
|
- lib/moesif_rack.rb
|
|
63
57
|
- lib/moesif_rack/app_config.rb
|
|
64
58
|
- lib/moesif_rack/client_ip.rb
|
|
65
|
-
- lib/moesif_rack/
|
|
59
|
+
- lib/moesif_rack/moesif_helpers.rb
|
|
66
60
|
- lib/moesif_rack/moesif_middleware.rb
|
|
61
|
+
- lib/moesif_rack/regex_config_helper.rb
|
|
67
62
|
- lib/moesif_rack/update_company.rb
|
|
68
63
|
- lib/moesif_rack/update_user.rb
|
|
69
64
|
- moesif_capture_outgoing/httplog.rb
|
|
@@ -87,7 +82,7 @@ require_paths:
|
|
|
87
82
|
- lib
|
|
88
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
84
|
requirements:
|
|
90
|
-
- - "
|
|
85
|
+
- - ">="
|
|
91
86
|
- !ruby/object:Gem::Version
|
|
92
87
|
version: '2.0'
|
|
93
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
@@ -96,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
96
91
|
- !ruby/object:Gem::Version
|
|
97
92
|
version: '0'
|
|
98
93
|
requirements: []
|
|
99
|
-
|
|
100
|
-
rubygems_version: 2.7.10
|
|
94
|
+
rubygems_version: 3.3.3
|
|
101
95
|
signing_key:
|
|
102
96
|
specification_version: 4
|
|
103
97
|
summary: moesif_rack
|