-
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
Feature/3484 - set metric name with 'measurement' modifier for grok parser #4433
Conversation
docs/DATA_FORMATS_INPUT.md
Outdated
Each pattern should only have one 'measurement' modifier applied to it. The modifier should only apply to fields | ||
of a single value type, not to another grok pattern. The name of the field with the measurement modifier applied | ||
will be ignored, so these formats are the same: `custom_patterns = {"TEST %{WORD:ignored_name:measurement}"}` | ||
`custom_patterns = {"TEST %{WORD::measurement}"}` |
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.
I think the patterns should behave the same regardless of if it is in the pattern
or custom_pattern
. Can we just say %{WORD::measurement}
will use the matched text and %{TEST:test_name:measurement}
will use the static value test_name
?
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.
Yea I think that should be made clear. The issue with that would be if people use the dynamic name on an entire pattern, ie not a single field, it would add the text of the whole pattern as a metric name.
plugins/parsers/grok/parser.go
Outdated
@@ -57,7 +58,7 @@ var ( | |||
// %{IPORHOST:clientip:tag} | |||
// %{HTTPDATE:ts1:ts-http} | |||
// %{HTTPDATE:ts2:ts-"02 Jan 06 15:04"} | |||
modifierRe = regexp.MustCompile(`%{\w+:(\w+):(ts-".+"|t?s?-?\w+)}`) | |||
modifierRe = regexp.MustCompile(`%{\w+:(\w+|):(ts-".+"|t?s?-?\w+)}`) |
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.
Let's just require a name that isn't used, similar to how timestamp works. This will make the code even simpler and we won't need to explain the new form.
docs/DATA_FORMATS_INPUT.md
Outdated
apply the 'measurement' modifier to a specific field in a pattern. | ||
The configuration: `custom_patterns = {"TEST %{WORD::measurement}"}` is treated the same as `custom_patterns = {"TEST %{WORD:ignored_name:measurement}"}`, as semantic names are ignored. If the pattern is matched, the measurement name will be set to the value of the field it was applied to. Each pattern should only have one 'measurement' modifier applied to it. The modifier should only apply to fields of a single value type, not to another grok pattern. | ||
|
||
The best way to get acquainted with grok patterns is to read the logstash docs, |
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.
There are some merge issues here, most of this is already in master.
Patterns []string | ||
NamedPatterns []string | ||
CustomPatterns string | ||
CustomPatternFiles []string | ||
TimeZone string | ||
MeasurementName string `toml:"measurement"` |
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.
Revert change so there is less churn in the git history and to keep the real changes clear.
Patterns: []string{"%{TEST_LOG_A}", "%{TEST_LOG_B}"}, | ||
CustomPatternFiles: []string{thisdir + "grok/testdata/test-patterns"}, | ||
MeasurementName: "logparser_grok", |
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.
Revert change
plugins/parsers/grok/parser.go
Outdated
@@ -214,7 +215,8 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) { | |||
|
|||
timestamp := time.Now() | |||
for k, v := range values { | |||
if k == "" || v == "" { | |||
if (k == "" || v == "") && p.typeMap[patternName][k] != "measurement" { |
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.
remove
plugins/parsers/grok/parser.go
Outdated
@@ -456,6 +460,12 @@ func (p *Parser) parseTypedCaptures(name, pattern string) (string, error) { | |||
} | |||
hasTimestamp = true | |||
} else { | |||
//for handling measurement tag with no name |
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.
remove
plugins/parsers/grok/parser.go
Outdated
@@ -214,10 +215,6 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) { | |||
|
|||
timestamp := time.Now() | |||
for k, v := range values { | |||
if k == "" || v == "" { |
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.
still want this
closes: #3484
Required for all PRs: