Class: Fluent::Plugin::Prometheus::ExpandBuilder::PlaceholderExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/prometheus/placeholder_expander.rb

Constant Summary collapse

PLACEHOLDER_REGEX =
/(\${[^\[}]+(\[[^\]]+\])?})/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log, placeholder) ⇒ PlaceholderExpander

Returns a new instance of PlaceholderExpander.



91
92
93
94
95
# File 'lib/fluent/plugin/prometheus/placeholder_expander.rb', line 91

def initialize(log, placeholder)
  @placeholder = placeholder
  @log = log
  @expander_cache = {}
end

Instance Attribute Details

#placeholderObject (readonly)

Returns the value of attribute placeholder.



89
90
91
# File 'lib/fluent/plugin/prometheus/placeholder_expander.rb', line 89

def placeholder
  @placeholder
end

Instance Method Details

#expand(str, dynamic_placeholders: nil) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/fluent/plugin/prometheus/placeholder_expander.rb', line 101

def expand(str, dynamic_placeholders: nil)
  expander = if dynamic_placeholders
               if @expander_cache[dynamic_placeholders]
                 @expander_cache[dynamic_placeholders]
               else
                 e = ExpandBuilder.build(dynamic_placeholders, log: @log)
                 e.merge_placeholder(@placeholder)
                 @expander_cache[dynamic_placeholders] = e
                 e
               end
             else
               self
             end

  expander.expand!(str)
end

#merge_placeholder(placeholder) ⇒ Object



97
98
99
# File 'lib/fluent/plugin/prometheus/placeholder_expander.rb', line 97

def merge_placeholder(placeholder)
  @placeholder.merge!(placeholder)
end