-
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
Make inputsource generic taking bufio.SplitFunc as input #7746
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
filebeat/inputsource/tcp/server.go
Outdated
@@ -190,7 +189,7 @@ func (s *Server) clientsCount() int { | |||
return len(s.clients) | |||
} | |||
|
|||
func splitFunc(lineDelimiter []byte) bufio.SplitFunc { | |||
func SplitFunc(lineDelimiter []byte) bufio.SplitFunc { |
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.
exported function SplitFunc should have comment or be unexported
3b644ea
to
f48c821
Compare
filebeat/input/syslog/config.go
Outdated
if splitFunc != nil { | ||
return nil, fmt.Errorf("error creating splitFunc from delimiter %s", dConfig.LineDelimiter) | ||
} | ||
return tcp.New(&config, splitFunc, cb) |
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.
@vjsamuel Instead of having two Config and two unpack can we use the same strategy as the TCP input and use [type embedding](https://github.com/elastic/beats/pull/7746/files#diff-8dbe6c5e5fa8f03003f5226255a1d1e8L31?
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.
The following will work and will be backward compatible with the existing configuration.
The struct structure can be different from the YML structure when you are using ucfg 'inline' option, also I've removed the check for the tcp.SplitFunc
because we have a nonzero validation the factory cannot return NIL.
diff --git a/filebeat/input/syslog/config.go b/filebeat/input/syslog/config.go
index 4b90223f4..dd9f99b88 100644
--- a/filebeat/input/syslog/config.go
+++ b/filebeat/input/syslog/config.go
@@ -41,9 +41,17 @@ var defaultConfig = config{
},
}
-var defaultTCP = tcp.Config{
- Timeout: time.Minute * 5,
- MaxMessageSize: 20 * humanize.MiByte,
+type syslogTCP struct {
+ tcp.Config `config:",inline"`
+ LineDelimiter string `config:"line_delimiter" validate:"nonzero"`
+}
+
+var defaultTCP = syslogTCP{
+ Config: tcp.Config{
+ Timeout: time.Minute * 5,
+ MaxMessageSize: 20 * humanize.MiByte,
+ },
+ LineDelimiter: "\n",
}
var defaultUDP = udp.Config{
@@ -51,14 +59,6 @@ var defaultUDP = udp.Config{
Timeout: time.Minute * 5,
}
-type delimiterConf struct {
- LineDelimiter string `config:"line_delimiter" validate:"nonzero"`
-}
-
-var defaultDelimiter = delimiterConf{
- LineDelimiter: "\n",
-}
-
func factory(
cb inputsource.NetworkFunc,
config common.ConfigNamespace,
@@ -72,16 +72,9 @@ func factory(
return nil, err
}
- dConfig := defaultDelimiter
- if err := cfg.Unpack(&dConfig); err != nil {
- return nil, err
- }
+ splitFunc := tcp.SplitFunc([]byte(config.LineDelimiter))
- splitFunc := tcp.SplitFunc([]byte(dConfig.LineDelimiter))
- if splitFunc != nil {
- return nil, fmt.Errorf("error creating splitFunc from delimiter %s", dConfig.LineDelimiter)
- }
- return tcp.New(&config, splitFunc, cb)
+ return tcp.New(&config.Config, splitFunc, cb)
case udp.Name:
config := defaultUDP
if err := cfg.Unpack(&config); err != nil {
diff --git a/filebeat/input/tcp/input.go b/filebeat/input/tcp/input.go
index 1688af3c4..38eafb4ce 100644
--- a/filebeat/input/tcp/input.go
+++ b/filebeat/input/tcp/input.go
@@ -18,7 +18,6 @@
package tcp
import (
- "fmt"
"sync"
"time"
@@ -78,9 +77,6 @@ func NewInput(
}
splitFunc := tcp.SplitFunc([]byte(config.LineDelimiter))
- if splitFunc == nil {
- return nil, fmt.Errorf("unable to create splitFunc for delimiter %s", config.LineDelimiter)
- }
server, err := tcp.New(&config.Config, splitFunc, cb)
if err != nil {
Jenkins test this please |
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.
Only minor comment concerning type embedding.
5100965
to
97c3230
Compare
CHANGELOG.asciidoc
Outdated
*Packetbeat* | ||
|
||
- Fix an out of bounds access in HTTP parser caused by malformed request. {pull}6997[6997] | ||
- Fix missing type for `http.response.body` field. {pull}7169[7169] |
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.
@vjsamuel I think something went wrong with the rebase?
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.
Small problem with the changelog.asciidoc
99e0372
to
8fa8dba
Compare
Jenkins test this please |
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.
WFG
@vjsamuel There is some system test failing for the syslog tcp can you take a look? |
8fa8dba
to
2c887a8
Compare
done |
Jenkins test this please |
This PR makes it a responsibility of the consumer of TCP
inputsource
to create thebufio.SplitFunc
. Hence, thereline_delimiter
parameter is removed frominputsource
and is moved to theinput
itself.This allows
input
implementations to define more custom splitters.