Class: Fluent::Plugin::LabelRouterOutput::Route
- Inherits:
-
Object
- Object
- Fluent::Plugin::LabelRouterOutput::Route
- Defined in:
- lib/fluent/plugin/out_label_router.rb
Instance Method Summary collapse
- #emit(tag, time, record) ⇒ Object
- #emit_es(tag, es) ⇒ Object
-
#filter_select(match, metadata) ⇒ Object
Returns true if filter passes (filter match).
- #get_labels ⇒ Object
-
#initialize(rule, router, registry) ⇒ Route
constructor
A new instance of Route.
-
#match?(metadata) ⇒ Boolean
Evaluate selectors We evaluate <match> statements in order: 1.
- #match_labels(input, match) ⇒ Object
Constructor Details
#initialize(rule, router, registry) ⇒ Route
Returns a new instance of Route.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fluent/plugin/out_label_router.rb', line 64 def initialize(rule, router, registry) @router = router @matches = rule['matches'] @tag = rule['tag'].to_s @label = rule['@label'] @metrics_labels = (rule['metrics_labels'].map { |k, v| [k.to_sym, v] }.to_h if rule['metrics_labels']) @counter = nil unless registry.nil? @counter = registry.counter(:fluentd_router_records_total, docstring: "Total number of events router for the flow", labels: [:flow]) end end |
Instance Method Details
#emit(tag, time, record) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/fluent/plugin/out_label_router.rb', line 119 def emit(tag, time, record) if @tag.empty? @router.emit(tag, time, record) else @router.emit(@tag, time, record) end end |
#emit_es(tag, es) ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/fluent/plugin/out_label_router.rb', line 127 def emit_es(tag, es) if @tag.empty? @router.emit_stream(tag, es) else @router.emit_stream(@tag, es) end # increment the counter for a given label set @counter&.increment(by: es.size, labels: get_labels) end |
#filter_select(match, metadata) ⇒ Object
Returns true if filter passes (filter match)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/fluent/plugin/out_label_router.rb', line 102 def filter_select(match, ) # Break on container_name mismatch unless match.hosts.empty? || match.hosts.include?([:host]) return false end # Break on host mismatch unless match.container_names.empty? || match.container_names.include?([:container]) return false end # Break if list of namespaces is not empty and does not include actual namespace unless match.namespaces.empty? || match.namespaces.include?([:namespace]) return false end match_labels([:labels], match.labels) end |
#get_labels ⇒ Object
76 77 78 79 80 |
# File 'lib/fluent/plugin/out_label_router.rb', line 76 def get_labels default = { 'flow': @label } labels = default.merge(@metrics_labels) labels end |
#match?(metadata) ⇒ Boolean
Evaluate selectors We evaluate <match> statements in order:
-
If match == true and negate == false -> return true
-
If match == true and negate == true -> return false
-
If match == false and negate == false -> continue
-
If match == false and negate == true -> continue
There is no match at all -> return false
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/fluent/plugin/out_label_router.rb', line 89 def match?() @matches.each do |match| if filter_select(match, ) and !match.negate return true end if filter_select(match, ) and match.negate return false end end false end |
#match_labels(input, match) ⇒ Object
137 138 139 |
# File 'lib/fluent/plugin/out_label_router.rb', line 137 def match_labels(input, match) (match.to_a - input.to_a).empty? end |