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 d4733f28bb
commit e8a3178b4a
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)
}