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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fluent/plugin/out_label_router.rb', line 69 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? if registry.exist?(:fluentd_router_records_total) @counter = registry.get(:fluentd_router_records_total) else @counter = registry.counter(:fluentd_router_records_total, docstring: "Total number of events routed for the flow", labels: [:flow, :id]) end end end |
Instance Method Details
#emit(tag, time, record) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/fluent/plugin/out_label_router.rb', line 128 def emit(tag, time, record) if @tag.empty? @router.emit(tag, time, record) else @router.emit(@tag, time, record) end @counter&.increment(by: 1, labels: get_labels) end |
#emit_es(tag, es) ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'lib/fluent/plugin/out_label_router.rb', line 137 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)
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/fluent/plugin/out_label_router.rb', line 107 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 # Break if list of namespace_labels is not empty and does not match actual namespace labels if !match.namespace_labels.empty? && !match_labels([:namespace_labels], match.namespace_labels) return false end match_labels([:labels], match.labels) end |
#get_labels ⇒ Object
85 86 87 88 |
# File 'lib/fluent/plugin/out_label_router.rb', line 85 def get_labels labels = { 'flow': @label, 'id': "default" } !@metrics_labels.nil? ? labels.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
97 98 99 100 101 102 103 104 |
# File 'lib/fluent/plugin/out_label_router.rb', line 97 def match?() @matches.each do |match| if filter_select(match, ) return !match.negate end end false end |
#match_labels(input, match) ⇒ Object
147 148 149 |
# File 'lib/fluent/plugin/out_label_router.rb', line 147 def match_labels(input, match) (match.to_a - input.to_a).empty? end |