moesif_rack 1.2.2 → 1.2.3

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
  SHA256:
3
- metadata.gz: 682e9bdbf0cc751bc8d06ee11d9a64a6fbb45b78437ee111c0566222c0834fa2
4
- data.tar.gz: 47f8ad3e4c54d03e33a5b65a8ce722795bef9cb5ba31db677f083f5efd493954
3
+ metadata.gz: 91356788d3cd249d677c97ec21eff14c426197114f927519a4b689828e4d07a2
4
+ data.tar.gz: 0e75eabec8e7906759e6ae981107adc91f77efe4053386c160929bcbb33780d4
5
5
  SHA512:
6
- metadata.gz: cd7f0277a90afc3bbf04dfafb3e0e0c3521aba394f0761bf08043c81ed845e01ff71dedd08416a1a5add1e07bb8f2ac5a835012600ebfa393bd9d43136037e69
7
- data.tar.gz: 3bd092a63b00b7a98f4f511bbe8449b8d3eacfc753b3edfe512d86dfd8909a937a304534c31f436cba59e139953add189cac9e776aa2b3a0d1a057e460475a64
6
+ metadata.gz: 1fa3a41c46b08090a34e36c682221c4153b85262f7eb00ecdf8c3462d0f2bf8bc1354cac171e80ded0f61106795d48420b511eb17a74e76dcaf0a2cfdf0a357e
7
+ data.tar.gz: 68889ee8704463d21913d7e61436c03db062555f164b5b3447d307d1fbff19a8439c046218bb10fcaf4c44ac31fe586c8b1a8be79374ad4f3bc6bd388829eff2
@@ -21,12 +21,42 @@ module MoesifRack
21
21
  @mask_data = options['mask_data']
22
22
  @skip = options['skip']
23
23
  @debug = options['debug']
24
- @sampling_percentage = options['sampling_percentage'] || 100
24
+ @config_dict = Hash.new
25
+ @sampling_percentage = get_config(nil)
25
26
  if not @sampling_percentage.is_a? Numeric
26
27
  raise "Sampling Percentage should be a number"
27
28
  end
28
29
  end
29
30
 
31
+ def get_config(cached_config_etag)
32
+ sample_rate = 100
33
+ begin
34
+ # Calling the api
35
+ config_api_response = @api_controller.get_app_config()
36
+ # Fetch the response ETag
37
+ response_config_etag = JSON.parse( config_api_response.to_json )["headers"]["x_moesif_config_etag"]
38
+ # Remove ETag from the global dict if exist
39
+ if !cached_config_etag.nil? && @config_dict.key?(cached_config_etag)
40
+ @config_dict.delete(cached_config_etag)
41
+ end
42
+ # Fetch the response body
43
+ @config_dict[response_config_etag] = JSON.parse(JSON.parse( config_api_response.to_json )["raw_body"])
44
+ #
45
+ app_config = @config_dict[response_config_etag]
46
+ # Fetch the sample rate
47
+ if !app_config.nil?
48
+ sample_rate = app_config.fetch("sample_rate", 100)
49
+ end
50
+ # Set the last updated time
51
+ @last_updated_time = Time.now.utc
52
+ rescue
53
+ # Set the last updated time
54
+ @last_updated_time = Time.now.utc
55
+ end
56
+ # Return the sample rate
57
+ return sample_rate
58
+ end
59
+
30
60
  def call env
31
61
  start_time = Time.now.utc.iso8601
32
62
 
@@ -134,7 +164,13 @@ module MoesifRack
134
164
  begin
135
165
  @random_percentage = Random.rand(0.00..100.00)
136
166
  if @sampling_percentage > @random_percentage
137
- @api_controller.create_event(event_model)
167
+ event_api_response = @api_controller.create_event(event_model)
168
+ cached_config_etag = @config_dict.keys[0]
169
+ event_response_config_etag = event_api_response[:x_moesif_config_etag]
170
+
171
+ if !event_response_config_etag.nil? && cached_config_etag != event_response_config_etag && Time.now.utc > @last_updated_time + 30
172
+ @sampling_percentage = get_config(cached_config_etag)
173
+ end
138
174
  if @debug
139
175
  puts("Event successfully sent to Moesif")
140
176
  end
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.2.2
4
+ version: 1.2.3
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-01-06 00:00:00.000000000 Z
12
+ date: 2019-02-14 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.3
34
+ version: 1.2.4
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.3
41
+ version: 1.2.4
42
42
  description: Collection/Data Ingestion SDK for Rack (also Rails) Middleware / RoR
43
43
  email: xing@moesif.com
44
44
  executables: []