Allow grok pattern to contain newlines (#4005)

This commit is contained in:
Daniel Nelson 2018-04-10 18:16:21 -07:00 committed by GitHub
parent 7b8f12b377
commit 55cfc383f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -132,6 +132,7 @@ func (p *Parser) Compile() error {
// "custom patterns"
p.namedPatterns = make([]string, 0, len(p.Patterns))
for i, pattern := range p.Patterns {
pattern = strings.TrimSpace(pattern)
if pattern == "" {
continue
}

View File

@ -958,3 +958,15 @@ func TestTimezoneLocalCompileFileAndParse(t *testing.T) {
assert.Equal(t, map[string]string{}, metricB.Tags())
assert.Equal(t, time.Date(2016, time.June, 4, 12, 41, 45, 0, time.Local).UnixNano(), metricB.Time().UnixNano())
}
func TestNewlineInPatterns(t *testing.T) {
p := &Parser{
Patterns: []string{`
%{SYSLOGTIMESTAMP:timestamp}
`},
}
require.NoError(t, p.Compile())
m, err := p.ParseLine("Apr 10 05:11:57")
require.NoError(t, err)
require.NotNil(t, m)
}