class Fluent::Plugin::LabelRouterOutput::Route
Public Class Methods
new(rule, router, registry)
click to toggle source
# 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? 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 router for the flow", labels: [:flow, :id]) end end end
Public Instance Methods
emit(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_label_router.rb, line 123 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)
click to toggle source
# File lib/fluent/plugin/out_label_router.rb, line 132 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)
click to toggle source
Returns true if filter passes (filter match)
# File lib/fluent/plugin/out_label_router.rb, line 106 def filter_select(match, metadata) # Break on container_name mismatch unless match.hosts.empty? || match.hosts.include?(metadata[:host]) return false end # Break on host mismatch unless match.container_names.empty? || match.container_names.include?(metadata[: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?(metadata[:namespace]) return false end match_labels(metadata[:labels], match.labels) end
get_labels()
click to toggle source
# File lib/fluent/plugin/out_label_router.rb, line 80 def get_labels default = { 'flow': @label } labels = default.merge(@metrics_labels) labels end
match?(metadata)
click to toggle source
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
# File lib/fluent/plugin/out_label_router.rb, line 93 def match?(metadata) @matches.each do |match| if filter_select(match, metadata) and !match.negate return true end if filter_select(match, metadata) and match.negate return false end end false end
match_labels(input, match)
click to toggle source
# File lib/fluent/plugin/out_label_router.rb, line 142 def match_labels(input, match) (match.to_a - input.to_a).empty? end