-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
ES output: allow to use tag values on index name #3470
Conversation
If a user has an environment variable set with the same name as the tag you might have problems, since we use the same ${var} syntax for these. We could use the Go template package https://golang.org/pkg/text/template/, it would look like |
Ops, yeah, completely forgot about that... I will have a look at the template package. |
Well, at the end it was much simpler to just change the notation to |
} else { | ||
|
||
tagName := indexName[startTag+2 : endTag] | ||
tagNameTrim := strings.TrimSpace(tagName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we trim the space here, then I think the tag may not match further down in the replacer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's why I kept the the tagName
variable to be used by the replacer instead of trimming on it directly
tagNameTrim := strings.TrimSpace(tagName) | ||
found := false | ||
|
||
for k := range metricTags { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this happens for each metric, I'm concerned about the performance. Perhaps this can be improved with by doing some of the work at Connect time.
I'll try to explain in more detail, this part needs only done once:
- Make an array of tagkeys:
["host"]
- Build a format string from the indexName template with the tags replaced with %s:
telegraf-%s-%Y.%m.%d
Then at Write time:
- Lookup the tag values and place them into an array.
- Use fmt.Sprintf with the format string and the array of tag values
- Use the existing replacer for the dates.
@danielnelson I tried to implement the changes you requested, let me know. |
Code looks perfect, can you rebase on master to fix the file conflict? |
Required for all PRs:
Should implement #3442
This should have some effect on performance but I haven't measured. I'm not go expert, there may be better ways of doing the same.
Let me know if this is ok, so I update the doc as well.