Remove string trimming from grok parser (#5608)
This commit is contained in:
parent
68b8db4a64
commit
72d4f00082
|
@ -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
|
# 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"
|
# 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
|
# 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
|
# HTTPD log formats
|
||||||
HTTPD20_ERRORLOG \[%{HTTPDERROR_DATE:timestamp}\] \[%{LOGLEVEL:loglevel:tag}\] (?:\[client %{IPORHOST:clientip}\] ){0,1}%{GREEDYDATA:errormsg}
|
HTTPD20_ERRORLOG \[%{HTTPDERROR_DATE:timestamp}\] \[%{LOGLEVEL:loglevel:tag}\] (?:\[client %{IPORHOST:clientip}\] ){0,1}%{GREEDYDATA:errormsg}
|
||||||
|
|
|
@ -271,7 +271,7 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) {
|
||||||
case TAG:
|
case TAG:
|
||||||
tags[k] = v
|
tags[k] = v
|
||||||
case STRING:
|
case STRING:
|
||||||
fields[k] = strings.Trim(v, `"`)
|
fields[k] = v
|
||||||
case EPOCH:
|
case EPOCH:
|
||||||
parts := strings.SplitN(v, ".", 2)
|
parts := strings.SplitN(v, ".", 2)
|
||||||
if len(parts) == 0 {
|
if len(parts) == 0 {
|
||||||
|
|
|
@ -1047,3 +1047,24 @@ func TestEmptyYearInTimestamp(t *testing.T) {
|
||||||
require.NotNil(t, m)
|
require.NotNil(t, m)
|
||||||
require.Equal(t, time.Now().Year(), m.Time().Year())
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue