Class: Vivarium::DisplayFilter
- Inherits:
-
Object
- Object
- Vivarium::DisplayFilter
- Defined in:
- lib/vivarium/display_filter.rb
Instance Attribute Summary collapse
-
#exclude_events ⇒ Object
readonly
Returns the value of attribute exclude_events.
-
#include_events ⇒ Object
readonly
Returns the value of attribute include_events.
-
#include_pids ⇒ Object
readonly
Returns the value of attribute include_pids.
-
#include_severities ⇒ Object
readonly
Returns the value of attribute include_severities.
-
#include_tids ⇒ Object
readonly
Returns the value of attribute include_tids.
Class Method Summary collapse
Instance Method Summary collapse
- #allow_event?(event_name:, severity:, span_name:, payload: nil, pid: nil, tid: nil) ⇒ Boolean
- #allow_span_name?(span_name) ⇒ Boolean
- #enabled? ⇒ Boolean
-
#initialize(raw = {}) ⇒ DisplayFilter
constructor
A new instance of DisplayFilter.
- #needs_payload? ⇒ Boolean
Constructor Details
#initialize(raw = {}) ⇒ DisplayFilter
Returns a new instance of DisplayFilter.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vivarium/display_filter.rb', line 20 def initialize(raw = {}) @raw = symbolize_keys(raw || {}) @include_events = normalize_string_set(fetch_key(:include_events, :event_names, :events)) @exclude_events = normalize_string_set(fetch_key(:exclude_events)) @include_severities = normalize_string_set(fetch_key(:include_severities, :severities, :severity)) @include_pids = normalize_integer_set(fetch_key(:include_pids, :pids, :pid)) @include_tids = normalize_integer_set(fetch_key(:include_tids, :tids, :tid)) @include_span_names = normalize_string_set(fetch_key(:include_span_names, :span_names)) @span_pattern = normalize_pattern(fetch_key(:span, :span_pattern)) payload_value = fetch_key(:payload) @payload_pattern = normalize_pattern(fetch_key(:payload_pattern)) @payload_patterns_by_event = {} if payload_value.is_a?(Hash) @payload_patterns_by_event = normalize_payload_map(payload_value) else @payload_pattern ||= normalize_pattern(payload_value) end end |
Instance Attribute Details
#exclude_events ⇒ Object (readonly)
Returns the value of attribute exclude_events.
7 8 9 |
# File 'lib/vivarium/display_filter.rb', line 7 def exclude_events @exclude_events end |
#include_events ⇒ Object (readonly)
Returns the value of attribute include_events.
7 8 9 |
# File 'lib/vivarium/display_filter.rb', line 7 def include_events @include_events end |
#include_pids ⇒ Object (readonly)
Returns the value of attribute include_pids.
7 8 9 |
# File 'lib/vivarium/display_filter.rb', line 7 def include_pids @include_pids end |
#include_severities ⇒ Object (readonly)
Returns the value of attribute include_severities.
7 8 9 |
# File 'lib/vivarium/display_filter.rb', line 7 def include_severities @include_severities end |
#include_tids ⇒ Object (readonly)
Returns the value of attribute include_tids.
7 8 9 |
# File 'lib/vivarium/display_filter.rb', line 7 def include_tids @include_tids end |
Class Method Details
.compile(raw) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vivarium/display_filter.rb', line 9 def self.compile(raw) return new if raw.nil? return raw if raw.is_a?(self) unless raw.respond_to?(:to_h) raise ArgumentError, "filter must be a Hash-compatible object" end new(raw.to_h) end |
Instance Method Details
#allow_event?(event_name:, severity:, span_name:, payload: nil, pid: nil, tid: nil) ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vivarium/display_filter.rb', line 60 def allow_event?(event_name:, severity:, span_name:, payload: nil, pid: nil, tid: nil) return false unless allow_span_name?(span_name) name = event_name.to_s sev = severity.to_s return false if @exclude_events.include?(name) return false if !@include_events.empty? && !@include_events.include?(name) return false if !@include_severities.empty? && !@include_severities.include?(sev) return false if !@include_pids.empty? && !@include_pids.include?(pid.to_i) return false if !@include_tids.empty? && !@include_tids.include?(tid.to_i) payload_pattern = @payload_patterns_by_event[name] || @payload_pattern if payload_pattern return false if payload.nil? return false unless payload_pattern.match?(payload.to_s) end true end |
#allow_span_name?(span_name) ⇒ Boolean
50 51 52 53 54 55 56 57 58 |
# File 'lib/vivarium/display_filter.rb', line 50 def allow_span_name?(span_name) return true if @include_span_names.empty? && @span_pattern.nil? name = span_name.to_s return true if @include_span_names.include?(name) return true if @span_pattern && @span_pattern.match?(name) false end |
#enabled? ⇒ Boolean
42 43 44 |
# File 'lib/vivarium/display_filter.rb', line 42 def enabled? !@raw.empty? end |
#needs_payload? ⇒ Boolean
46 47 48 |
# File 'lib/vivarium/display_filter.rb', line 46 def needs_payload? !@payload_pattern.nil? || !@payload_patterns_by_event.empty? end |