-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add tag "truncated" to "log.flags" if incoming line is longer than configured limit #7991
Changes from 1 commit
5aaadff
e13ab92
a81626a
af7c81d
f8eb9c7
b16cff8
84584c5
03ee796
496ebe4
a01440c
b9aa508
cd0561e
43b8c57
da33c4d
2870f20
5d8cb05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// +build !integration | ||
|
||
package readfile | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/elastic/beats/filebeat/reader" | ||
) | ||
|
||
type mockReader struct { | ||
line []byte | ||
} | ||
|
||
func (m *mockReader) Next() (reader.Message, error) { | ||
return reader.Message{ | ||
Content: m.line, | ||
}, nil | ||
} | ||
|
||
var limitTests = []struct { | ||
line string | ||
maxBytes int | ||
}{ | ||
{"long-long-line", 5}, | ||
{"long-long-line", 3}, | ||
} | ||
|
||
func TestLimitReader(t *testing.T) { | ||
for _, test := range limitTests { | ||
r := NewLimitReader(&mockReader{[]byte(test.line)}, test.maxBytes) | ||
|
||
msg, err := r.Next() | ||
if err != nil { | ||
t.Fatalf("Error reading from mock reader: %v", err) | ||
} | ||
|
||
assert.Equal(t, test.maxBytes, len(msg.Content)) | ||
|
||
statusFlags, err := msg.Fields.GetValue("log.status") | ||
if err != nil { | ||
t.Fatalf("Error getting truncated value: %v", err) | ||
} | ||
|
||
found := false | ||
switch flags := statusFlags.(type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can it be both types? Same question for the other test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added it to mimic the testing of the old |
||
case []string: | ||
for _, f := range flags { | ||
if f == "truncated" { | ||
found = true | ||
} | ||
} | ||
case []interface{}: | ||
for _, f := range flags { | ||
if f == "truncated" { | ||
found = true | ||
} | ||
} | ||
default: | ||
t.Fatalf("incorrect type for log.status") | ||
} | ||
|
||
assert.True(t, found) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a third param here
truncated: bool
and then add also a test that is not truncated and checks that the flag does not exist?