Class: XRay::SamplingRule
- Inherits:
-
Object
- Object
- XRay::SamplingRule
- Defined in:
- lib/aws-xray-sdk/sampling/sampling_rule.rb
Overview
Service sampling rule data model
Instance Attribute Summary collapse
-
#borrow_count ⇒ Object
readonly
Returns the value of attribute borrow_count.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#rate ⇒ Object
Returns the value of attribute rate.
-
#request_count ⇒ Object
readonly
Returns the value of attribute request_count.
-
#reservoir ⇒ Object
Returns the value of attribute reservoir.
-
#sampled_count ⇒ Object
readonly
Returns the value of attribute sampled_count.
Instance Method Summary collapse
-
#applies?(sampling_req) ⇒ Boolean
Determines whether or not this sampling rule applies to the incoming request based on some of the request’s parameters.
- #borrowable? ⇒ Boolean
-
#default? ⇒ Boolean
Return ‘true` if this rule is the default rule.
- #ever_matched? ⇒ Boolean
- #increment_borrow_count ⇒ Object
- #increment_request_count ⇒ Object
- #increment_sampled_count ⇒ Object
-
#initialize(record) ⇒ SamplingRule
constructor
A new instance of SamplingRule.
- #merge(rule) ⇒ Object
- #snapshot_statistics ⇒ Object
- #time_to_report? ⇒ Boolean
Constructor Details
#initialize(record) ⇒ SamplingRule
Returns a new instance of SamplingRule.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 13 def initialize(record) @name = record.rule_name @priority = record.priority @rate = record.fixed_rate @host = record.host @method = record.http_method @path = record.url_path @service = record.service_name @service_type = record.service_type @reservoir_size = record.reservoir_size @reservoir = Reservoir.new reset_statistics @lock = Mutex.new end |
Instance Attribute Details
#borrow_count ⇒ Object (readonly)
Returns the value of attribute borrow_count.
8 9 10 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 8 def borrow_count @borrow_count end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 8 def name @name end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
8 9 10 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 8 def priority @priority end |
#rate ⇒ Object
Returns the value of attribute rate.
10 11 12 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 10 def rate @rate end |
#request_count ⇒ Object (readonly)
Returns the value of attribute request_count.
8 9 10 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 8 def request_count @request_count end |
#reservoir ⇒ Object
Returns the value of attribute reservoir.
10 11 12 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 10 def reservoir @reservoir end |
#sampled_count ⇒ Object (readonly)
Returns the value of attribute sampled_count.
8 9 10 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 8 def sampled_count @sampled_count end |
Instance Method Details
#applies?(sampling_req) ⇒ Boolean
Determines whether or not this sampling rule applies to the incoming request based on some of the request’s parameters. Any Nil parameters provided will be considered as implicit matches as the rule matching is a best effort.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 35 def applies?(sampling_req) return false if sampling_req.nil? || sampling_req.empty? host = sampling_req[:host] http_method = sampling_req[:http_method] url_path = sampling_req[:url_path] service = sampling_req[:service] host_match = !host || SearchPattern.wildcard_match?(pattern: @host, text: host) path_match = !url_path || SearchPattern.wildcard_match?(pattern: @path, text: url_path) method_match = !http_method || SearchPattern.wildcard_match?(pattern: @method, text: http_method) service_match = !service || SearchPattern.wildcard_match?(pattern: @service, text: service) # if sampling request contains service type we assmue # the origin (a.k.a AWS plugins are set and effective) if sampling_req.key?(:service_type) service_type = sampling_req[:service_type] service_type_match = SearchPattern.wildcard_match?(pattern: @service_type, text: service_type) else service_type_match = @service_type == '*' end host_match && path_match && method_match && service_match && service_type_match end |
#borrowable? ⇒ Boolean
81 82 83 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 81 def borrowable? @reservoir_size != 0 end |
#default? ⇒ Boolean
Return ‘true` if this rule is the default rule.
86 87 88 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 86 def default? @name == 'Default' end |
#ever_matched? ⇒ Boolean
90 91 92 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 90 def ever_matched? @request_count > 0 end |
#increment_borrow_count ⇒ Object
104 105 106 107 108 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 104 def increment_borrow_count @lock.synchronize do @borrow_count += 1 end end |
#increment_request_count ⇒ Object
98 99 100 101 102 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 98 def increment_request_count @lock.synchronize do @request_count += 1 end end |
#increment_sampled_count ⇒ Object
110 111 112 113 114 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 110 def increment_sampled_count @lock.synchronize do @sampled_count += 1 end end |
#merge(rule) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 71 def merge(rule) @lock.synchronize do @request_count = rule.request_count @borrow_count = rule.borrow_count @sampled_count = rule.sampled_count @reservoir = rule.reservoir rule.reservoir = nil end end |
#snapshot_statistics ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 59 def snapshot_statistics @lock.synchronize do report = { request_count: @request_count, borrow_count: @borrow_count, sampled_count: @sampled_count } reset_statistics report end end |
#time_to_report? ⇒ Boolean
94 95 96 |
# File 'lib/aws-xray-sdk/sampling/sampling_rule.rb', line 94 def time_to_report? @reservoir.time_to_report? end |