moesif_rack 1.3.10 → 1.4.0
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 -13
- data/lib/moesif_rack/app_config.rb +4 -0
- data/lib/moesif_rack/moesif_middleware.rb +1 -0
- data/moesif_capture_outgoing/httplog/http_log.rb +55 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 818bfecddcafd4b2b71a662e762cb5468b4bf54c7fc5397fb0812ad4274b82ac
|
4
|
+
data.tar.gz: 96385b853df74e5a7ca95d669244fc8e744079fcfd6d109c1c7855663bd61ea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb421c6472805827b2f7c23442c3047ba36c34172ef9af86d2c1266e3867c5aea201cb1900b9e11c16f6915773273a366d75e2b81a0bd02676f147f432de2988
|
7
|
+
data.tar.gz: 557bea2a4a9e8c223bde8d2242d47c23ff69adf591ee2f55101b74f9910e788ec584aaf7b5e61942f485a2aa43bd423b6a4196094586424c217de0ded3fe36b9
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ gem install moesif_rack
|
|
22
22
|
and if you have a `Gemfile` in your project, please add this line to
|
23
23
|
|
24
24
|
```
|
25
|
-
gem 'moesif_rack', '~> 1.
|
25
|
+
gem 'moesif_rack', '~> 1.4.0'
|
26
26
|
|
27
27
|
```
|
28
28
|
|
@@ -373,12 +373,6 @@ This method is a convenient helper that calls the Moesif API lib.
|
|
373
373
|
For details, visit the [Ruby API Reference](https://www.moesif.com/docs/api?ruby#update-users-in-batch).
|
374
374
|
|
375
375
|
```ruby
|
376
|
-
metadata = JSON.parse('{'\
|
377
|
-
'"email": "testrubyapi@user.com",'\
|
378
|
-
'"name": "ruby api user",'\
|
379
|
-
'"custom": "testdata"'\
|
380
|
-
'}')
|
381
|
-
|
382
376
|
users = []
|
383
377
|
|
384
378
|
metadata => {
|
@@ -463,12 +457,6 @@ This method is a convenient helper that calls the Moesif API lib.
|
|
463
457
|
For details, visit the [Ruby API Reference](https://www.moesif.com/docs/api?ruby#update-companies-in-batch).
|
464
458
|
|
465
459
|
```ruby
|
466
|
-
metadata = JSON.parse('{'\
|
467
|
-
'"email": "testrubyapi@user.com",'\
|
468
|
-
'"name": "ruby api user",'\
|
469
|
-
'"custom": "testdata"'\
|
470
|
-
'}')
|
471
|
-
|
472
460
|
companies = []
|
473
461
|
|
474
462
|
metadata => {
|
@@ -233,6 +233,7 @@ module MoesifRack
|
|
233
233
|
end
|
234
234
|
|
235
235
|
if @sampling_percentage > @random_percentage
|
236
|
+
event_model.weight = @app_config.calculate_weight(@sampling_percentage)
|
236
237
|
event_api_response = @api_controller.create_event(event_model)
|
237
238
|
event_response_config_etag = event_api_response[:x_moesif_config_etag]
|
238
239
|
|
@@ -3,6 +3,7 @@ require 'rack'
|
|
3
3
|
require 'moesif_api'
|
4
4
|
require 'json'
|
5
5
|
require 'base64'
|
6
|
+
require_relative '../../lib/moesif_rack/app_config.rb'
|
6
7
|
|
7
8
|
module MoesifCaptureOutgoing
|
8
9
|
|
@@ -23,6 +24,22 @@ module MoesifCaptureOutgoing
|
|
23
24
|
@skip_outgoing = options['skip_outgoing']
|
24
25
|
@mask_data_outgoing = options['mask_data_outgoing']
|
25
26
|
@log_body_outgoing = options.fetch('log_body_outgoing', true)
|
27
|
+
@app_config = AppConfig.new
|
28
|
+
@config = @app_config.get_config(@api_controller, @debug)
|
29
|
+
@config_etag = nil
|
30
|
+
@sampling_percentage = 100
|
31
|
+
@last_updated_time = Time.now.utc
|
32
|
+
@config_dict = Hash.new
|
33
|
+
begin
|
34
|
+
if !@config.nil?
|
35
|
+
@config_etag, @sampling_percentage, @last_updated_time = @app_config.parse_configuration(@config, @debug)
|
36
|
+
end
|
37
|
+
rescue => exception
|
38
|
+
if @debug
|
39
|
+
puts 'Error while parsing application configuration on initialization'
|
40
|
+
puts exception.to_s
|
41
|
+
end
|
42
|
+
end
|
26
43
|
end
|
27
44
|
|
28
45
|
def call (url, request, request_time, response, response_time)
|
@@ -157,11 +174,45 @@ module MoesifCaptureOutgoing
|
|
157
174
|
|
158
175
|
# Send Event to Moesif
|
159
176
|
begin
|
160
|
-
|
161
|
-
|
162
|
-
|
177
|
+
@random_percentage = Random.rand(0.00..100.00)
|
178
|
+
begin
|
179
|
+
@sampling_percentage = @app_config.get_sampling_percentage(@config, event_model.user_id, event_model.company_id, @debug)
|
180
|
+
rescue => exception
|
181
|
+
if @debug
|
182
|
+
puts 'Error while getting sampling percentage, assuming default behavior'
|
183
|
+
puts exception.to_s
|
184
|
+
end
|
185
|
+
@sampling_percentage = 100
|
186
|
+
end
|
187
|
+
|
188
|
+
if @sampling_percentage > @random_percentage
|
189
|
+
event_model.weight = @app_config.calculate_weight(@sampling_percentage)
|
190
|
+
if @debug
|
191
|
+
puts 'Sending Outgoing Request Data to Moesif'
|
192
|
+
puts event_model.to_json
|
193
|
+
end
|
194
|
+
event_api_response = @api_controller.create_event(event_model)
|
195
|
+
event_response_config_etag = event_api_response[:x_moesif_config_etag]
|
196
|
+
|
197
|
+
if !event_response_config_etag.nil? && !@config_etag.nil? && @config_etag != event_response_config_etag && Time.now.utc > @last_updated_time + 300
|
198
|
+
begin
|
199
|
+
@config = @app_config.get_config(@api_controller, @debug)
|
200
|
+
@config_etag, @sampling_percentage, @last_updated_time = @app_config.parse_configuration(@config, @debug)
|
201
|
+
rescue => exception
|
202
|
+
if @debug
|
203
|
+
puts 'Error while updating the application configuration'
|
204
|
+
puts exception.to_s
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
if @debug
|
209
|
+
puts("Event successfully sent to Moesif")
|
210
|
+
end
|
211
|
+
else
|
212
|
+
if @debug
|
213
|
+
puts("Skipped outgoing Event due to sampling percentage: " + @sampling_percentage.to_s + " and random percentage: " + @random_percentage.to_s)
|
214
|
+
end
|
163
215
|
end
|
164
|
-
@api_controller.create_event(event_model)
|
165
216
|
rescue MoesifApi::APIException => e
|
166
217
|
if e.response_code.between?(401, 403)
|
167
218
|
puts "Unathorized accesss sending event to Moesif. Please verify your Application Id."
|
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
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moesif, Inc
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-12-
|
12
|
+
date: 2019-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 1.2.
|
34
|
+
version: 1.2.11
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 1.2.
|
41
|
+
version: 1.2.11
|
42
42
|
description: Collection/Data Ingestion SDK for Rack (also Rails) Middleware / RoR
|
43
43
|
email: xing@moesif.com
|
44
44
|
executables: []
|