Skip to content

Commit

Permalink
Remove string trimming from grok parser (influxdata#5608)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and Jean-Louis Dupond committed Apr 22, 2019
1 parent 1c23fd6 commit 4c6c90b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
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)
}

0 comments on commit 4c6c90b

Please sign in to comment.