Class: Vivarium::DisplayFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/vivarium/display_filter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw = {}) ⇒ DisplayFilter

Returns a new instance of DisplayFilter.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vivarium/display_filter.rb', line 21

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))
  @max_span_depth = normalize_integer(fetch_key(:max_span_depth, :max_depth))

  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_eventsObject (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_eventsObject (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_pidsObject (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_severitiesObject (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_tidsObject (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

#max_span_depthObject (readonly)

Returns the value of attribute max_span_depth.



7
8
9
# File 'lib/vivarium/display_filter.rb', line 7

def max_span_depth
  @max_span_depth
end

Class Method Details

.compile(raw) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/vivarium/display_filter.rb', line 10

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

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vivarium/display_filter.rb', line 62

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

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
# File 'lib/vivarium/display_filter.rb', line 52

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

Returns:

  • (Boolean)


44
45
46
# File 'lib/vivarium/display_filter.rb', line 44

def enabled?
  !@raw.empty?
end

#needs_payload?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/vivarium/display_filter.rb', line 48

def needs_payload?
  !@payload_pattern.nil? || !@payload_patterns_by_event.empty?
end