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

Feature/3484 - set metric name with 'measurement' modifier for grok parser #4433

Merged
merged 56 commits into from
Aug 17, 2018

Conversation

maxunt
Copy link
Contributor

@maxunt maxunt commented Jul 17, 2018

closes: #3484

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

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}"}`
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -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+)}`)
Copy link
Contributor

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.

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,
Copy link
Contributor

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"`
Copy link
Contributor

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert change

@@ -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" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -456,6 +460,12 @@ func (p *Parser) parseTypedCaptures(name, pattern string) (string, error) {
}
hasTimestamp = true
} else {
//for handling measurement tag with no name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -214,10 +215,6 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) {

timestamp := time.Now()
for k, v := range values {
if k == "" || v == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still want this

@danielnelson danielnelson merged commit 9e0eb0c into master Aug 17, 2018
@danielnelson danielnelson deleted the feature/3484 branch August 17, 2018 20:45
@danielnelson danielnelson added feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin area/tail labels Aug 17, 2018
otherpirate pushed a commit to otherpirate/telegraf that referenced this pull request Mar 15, 2019
otherpirate pushed a commit to otherpirate/telegraf that referenced this pull request Mar 15, 2019
dupondje pushed a commit to dupondje/telegraf that referenced this pull request Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/tail feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set measurement name based on matched pattern in logparser
3 participants