Skip to content
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

Merged
merged 2 commits into from
Jul 30, 2018

Conversation

vjsamuel
Copy link
Contributor

This PR makes it a responsibility of the consumer of TCP inputsource to create the bufio.SplitFunc. Hence, there line_delimiter parameter is removed from inputsource and is moved to the input itself.

This allows input implementations to define more custom splitters.

@elasticmachine
Copy link
Collaborator

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?

@@ -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 {

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

@vjsamuel vjsamuel force-pushed the make_inputsource_generic branch 2 times, most recently from 3b644ea to f48c821 Compare July 25, 2018 21:36
@ph ph self-assigned this Jul 25, 2018
if splitFunc != nil {
return nil, fmt.Errorf("error creating splitFunc from delimiter %s", dConfig.LineDelimiter)
}
return tcp.New(&config, splitFunc, cb)
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vjsamuel

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 {

@ph
Copy link
Contributor

ph commented Jul 26, 2018

Jenkins test this please

Copy link
Contributor

@ph ph left a 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.

@vjsamuel vjsamuel force-pushed the make_inputsource_generic branch 3 times, most recently from 5100965 to 97c3230 Compare July 27, 2018 17:11
*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]
Copy link
Contributor

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?

Copy link
Contributor

@ph ph left a 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

@vjsamuel vjsamuel force-pushed the make_inputsource_generic branch 2 times, most recently from 99e0372 to 8fa8dba Compare July 27, 2018 17:37
@ph
Copy link
Contributor

ph commented Jul 27, 2018

Jenkins test this please

Copy link
Contributor

@ph ph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WFG

@ph
Copy link
Contributor

ph commented Jul 27, 2018

@vjsamuel There is some system test failing for the syslog tcp can you take a look?

@vjsamuel vjsamuel force-pushed the make_inputsource_generic branch from 8fa8dba to 2c887a8 Compare July 27, 2018 19:24
@vjsamuel
Copy link
Contributor Author

done

@ph
Copy link
Contributor

ph commented Jul 30, 2018

Jenkins test this please

@ph ph merged commit dba0f7c into elastic:master Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants