Skip to content

Commit d344192

Browse files
author
Jesper Söderlund
committed
Added support for additional placeholders from record_transform filter
Signed-off-by: Jesper Söderlund <jesper.soderlund@klarna.com>
1 parent 9abc276 commit d344192

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,10 @@ Reserved placeholders are:
351351

352352
- `${hostname}`: hostname
353353
- `${worker_id}`: fluent worker id
354-
- `${tag}`: tag name
355-
- only available in Prometheus output/filter plugin
356-
354+
- `${tag}`: tag name, only available in Prometheus output/filter plugin
355+
- `${tag_parts[N]}`: refers to the Nth part of the tag, only available in Prometheus output/filter plugin
356+
- `${tag_suffix}`: refers to the [N..] part of the tag, only available in Prometheus output/filter plugin
357+
- `${tag_prefix}`: refers to the [0..N] part of the tag, only available in Prometheus output/filter plugin
357358

358359
### top-level labels and labels inside metric
359360

lib/fluent/plugin/prometheus.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,35 @@ def configure(conf)
6767
@hostname = Socket.gethostname
6868
end
6969

70+
def tag_prefix(tag_parts)
71+
return [] if tag_parts.empty?
72+
tag_prefix = [tag_parts.first]
73+
1.upto(tag_parts.size-1).each do |i|
74+
tag_prefix[i] = "#{tag_prefix[i-1]}.#{tag_parts[i]}"
75+
end
76+
tag_prefix
77+
end
78+
79+
def tag_suffix(tag_parts)
80+
return [] if tag_parts.empty?
81+
rev_tag_parts = tag_parts.reverse
82+
rev_tag_suffix = [rev_tag_parts.first]
83+
1.upto(tag_parts.size-1).each do |i|
84+
rev_tag_suffix[i] = "#{rev_tag_parts[i]}.#{rev_tag_suffix[i-1]}"
85+
end
86+
rev_tag_suffix.reverse!
87+
end
88+
7089
def instrument(tag, es, metrics)
90+
tag_parts = tag.split('.')
91+
tag_prefix = tag_prefix(tag_parts)
92+
tag_suffix = tag_suffix(tag_parts)
93+
7194
placeholder_values = {
7295
'tag' => tag,
96+
'tag_parts' => tag_parts,
97+
'tag_prefix' => tag_prefix,
98+
'tag_suffix' => tag_suffix,
7399
'hostname' => @hostname,
74100
'worker_id' => fluentd_worker_id,
75101
}

0 commit comments

Comments
 (0)