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

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

Defined Under Namespace

Classes: PlaceholderExpander

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log:) ⇒ ExpandBuilder

Returns a new instance of ExpandBuilder.



9
10
11
# File 'lib/fluent/plugin/prometheus/placeholder_expander.rb', line 9

def initialize(log:)
  @log = log
end

Class Method Details

.build(placeholder, log:) ⇒ Object



5
6
7
# File 'lib/fluent/plugin/prometheus/placeholder_expander.rb', line 5

def self.build(placeholder, log:)
  new(log: log).build(placeholder)
end

Instance Method Details

#build(placeholder_values) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fluent/plugin/prometheus/placeholder_expander.rb', line 13

def build(placeholder_values)
  placeholders = {}
  placeholder_values.each do |key, value|
    case value
    when Array
      size = value.size
      value.each_with_index do |v, i|
        placeholders["${#{key}[#{i}]}"] = v
        placeholders["${#{key}[#{i - size}]}"] = v
      end
    when Hash
      value.each do |k, v|
        placeholders[%(${#{key}["#{k}"]})] = v
      end
    else
      if key == 'tag'
        placeholders.merge!(build_tag(value))
      else
        placeholders["${#{key}}"] = value
      end
    end
  end

  Fluent::Plugin::Prometheus::ExpandBuilder::PlaceholderExpander.new(@log, placeholders)
end