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

Remove string trimming from grok parser #5608

Merged
merged 1 commit into from
Mar 22, 2019
Merged
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
2 changes: 1 addition & 1 deletion plugins/parsers/grok/influx_patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ COMMON_LOG_FORMAT %{CLIENT:client_ip} %{NOTSPACE:ident} %{NOTSPACE:auth} \[%{HTT
# Combined log format is the same as the common log format but with the addition
# of two quoted strings at the end for "referrer" and "agent"
# See Examples at http://httpd.apache.org/docs/current/mod/mod_log_config.html
COMBINED_LOG_FORMAT %{COMMON_LOG_FORMAT} %{QS:referrer} %{QS:agent}
COMBINED_LOG_FORMAT %{COMMON_LOG_FORMAT} "%{DATA:referrer}" "%{DATA:agent}"

# HTTPD log formats
HTTPD20_ERRORLOG \[%{HTTPDERROR_DATE:timestamp}\] \[%{LOGLEVEL:loglevel:tag}\] (?:\[client %{IPORHOST:clientip}\] ){0,1}%{GREEDYDATA:errormsg}
Expand Down
2 changes: 1 addition & 1 deletion plugins/parsers/grok/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) {
case TAG:
tags[k] = v
case STRING:
fields[k] = strings.Trim(v, `"`)
fields[k] = v
case EPOCH:
parts := strings.SplitN(v, ".", 2)
if len(parts) == 0 {
Expand Down
21 changes: 21 additions & 0 deletions plugins/parsers/grok/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,3 +1047,24 @@ func TestEmptyYearInTimestamp(t *testing.T) {
require.NotNil(t, m)
require.Equal(t, time.Now().Year(), m.Time().Year())
}

func TestTrimRegression(t *testing.T) {
// https://github.com/influxdata/telegraf/issues/4998
p := &Parser{
Patterns: []string{`%{GREEDYDATA:message:string}`},
}
require.NoError(t, p.Compile())

actual, err := p.ParseLine(`level=info msg="ok"`)
require.NoError(t, err)

expected := testutil.MustMetric(
"",
map[string]string{},
map[string]interface{}{
"message": `level=info msg="ok"`,
},
actual.Time(),
)
require.Equal(t, expected, actual)
}