-
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
Add support for dropwizard format #2846
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f2fb569
Add support for dropwizard format
faab7a3
Move the metric type into a tag in Dropwizard parser
atzoum 46412c2
Extract templating system from graphite and allow arbitrary split sep…
atzoum 8f7c01e
Opt-in support for measurement and tag templates in Dropwizard parser
atzoum afebe89
remove .vscode from .gitignore
atzoum 1f9135c
More precise error messages
atzoum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package templating | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
) | ||
|
||
const ( | ||
// DefaultSeparator is the default separation character to use when separating template parts. | ||
DefaultSeparator = "." | ||
) | ||
|
||
// Engine uses a Matcher to retrieve the appropriate template and applies the template | ||
// to the input string | ||
type Engine struct { | ||
joiner string | ||
matcher *matcher | ||
} | ||
|
||
// Apply extracts the template fields from the given line and returns the measurement | ||
// name, tags and field name | ||
func (e *Engine) Apply(line string) (string, map[string]string, string, error) { | ||
return e.matcher.match(line).Apply(line, e.joiner) | ||
} | ||
|
||
// NewEngine creates a new templating engine | ||
func NewEngine(joiner string, defaultTemplate *Template, templates []string) (*Engine, error) { | ||
engine := Engine{ | ||
joiner: joiner, | ||
matcher: newMatcher(defaultTemplate), | ||
} | ||
templateSpecs := parseTemplateSpecs(templates) | ||
|
||
for _, templateSpec := range templateSpecs { | ||
if err := engine.matcher.addSpec(templateSpec); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return &engine, nil | ||
} | ||
|
||
func parseTemplateSpecs(templates []string) templateSpecs { | ||
tmplts := templateSpecs{} | ||
for _, pattern := range templates { | ||
tmplt := templateSpec{ | ||
separator: DefaultSeparator, | ||
} | ||
|
||
// Format is [separator] [filter] <template> [tag1=value1,tag2=value2] | ||
parts := strings.Fields(pattern) | ||
partsLength := len(parts) | ||
if partsLength < 1 { | ||
// ignore | ||
continue | ||
} | ||
if partsLength == 1 { | ||
tmplt.template = pattern | ||
} else if partsLength == 4 { | ||
tmplt.separator = parts[0] | ||
tmplt.filter = parts[1] | ||
tmplt.template = parts[2] | ||
tmplt.tagstring = parts[3] | ||
} else { | ||
hasTagstring := strings.Contains(parts[partsLength-1], "=") | ||
if hasTagstring { | ||
tmplt.tagstring = parts[partsLength-1] | ||
tmplt.template = parts[partsLength-2] | ||
if partsLength == 3 { | ||
tmplt.filter = parts[0] | ||
} | ||
} else { | ||
tmplt.template = parts[partsLength-1] | ||
if partsLength == 2 { | ||
tmplt.filter = parts[0] | ||
} else { // length == 3 | ||
tmplt.separator = parts[0] | ||
tmplt.filter = parts[1] | ||
} | ||
} | ||
} | ||
tmplts = append(tmplts, tmplt) | ||
} | ||
sort.Sort(tmplts) | ||
return tmplts | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it common for tags to be distributed throughout the document? We may want to remove this functionality and use the measurement filtering options (taginclude/tagexclude) if all we need to filter the tags.
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.
No, this is not about filtering tags. The purpose of this optional configuration option is to allow the user to add tags which are not included in the measurement name but are contained in another property within the same json file.
I have an example in test case
TestParseValidEmbeddedCounterJSON
where the following json contains both arbitraty tags and a dropwizard metric registry like belowWe are already using this functionality in our prod environment and it is necessary for our use cases. I don't expect it to be frequently used by other users, however it is a nice addition and I don't see any harm in keeping it.
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.
This example could be done with
dropwizard_tags_path = "tags"
, do you have an example where you needdropwizard_tag_paths
?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.
Lets say we want the value inside
tag1
but want to rename the tag tomytag
:The above config would add a tag
mytag=green
in all measurementsThere 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.
Do you see it being used outside of renaming? Is this something you are using right now?
As an aside, we will probably want to have a general purpose renaming method in the future, probably as a processor plugin, but no ETA on that.
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.
Given that filtering can be done already through
taginclude
andtagexclude
, renaming is the only use case for it. Yes we are using this on two occasions to consolidate metrics from different sources (produced by different teams).Indeed, tag renaming is a cross-cutting concern.