Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for additional placeholders from record_transform filter #87

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,10 @@ Reserved placeholders are:

- `${hostname}`: hostname
- `${worker_id}`: fluent worker id
- `${tag}`: tag name
- only available in Prometheus output/filter plugin

- `${tag}`: tag name, only available in Prometheus output/filter plugin
- `${tag_parts[N]}`: refers to the Nth part of the tag, only available in Prometheus output/filter plugin
- `${tag_suffix}`: refers to the [N..] part of the tag, only available in Prometheus output/filter plugin
- `${tag_prefix}`: refers to the [0..N] part of the tag, only available in Prometheus output/filter plugin

### top-level labels and labels inside metric

Expand Down
26 changes: 26 additions & 0 deletions lib/fluent/plugin/prometheus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,35 @@ def configure(conf)
@hostname = Socket.gethostname
end

def tag_prefix(tag_parts)
return [] if tag_parts.empty?
tag_prefix = [tag_parts.first]
1.upto(tag_parts.size-1).each do |i|
tag_prefix[i] = "#{tag_prefix[i-1]}.#{tag_parts[i]}"
end
tag_prefix
end

def tag_suffix(tag_parts)
return [] if tag_parts.empty?
rev_tag_parts = tag_parts.reverse
rev_tag_suffix = [rev_tag_parts.first]
1.upto(tag_parts.size-1).each do |i|
rev_tag_suffix[i] = "#{rev_tag_parts[i]}.#{rev_tag_suffix[i-1]}"
end
rev_tag_suffix.reverse!
end

def instrument(tag, es, metrics)
tag_parts = tag.split('.')
tag_prefix = tag_prefix(tag_parts)
tag_suffix = tag_suffix(tag_parts)

placeholder_values = {
'tag' => tag,
'tag_parts' => tag_parts,
'tag_prefix' => tag_prefix,
'tag_suffix' => tag_suffix,
'hostname' => @hostname,
'worker_id' => fluentd_worker_id,
}
Expand Down