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

Add max_connections to TCP input #12691

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions filebeat/_meta/common.reference.inputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ filebeat.inputs:
# Maximum size in bytes of the message received over TCP
#max_message_size: 20MiB

# Max number of concurrent connections, or 0 for no limit. Default: 0
#max_connections: 0

# The number of seconds of inactivity before a remote connection is closed.
#timeout: 300s

Expand Down
3 changes: 3 additions & 0 deletions filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@ filebeat.inputs:
# Maximum size in bytes of the message received over TCP
#max_message_size: 20MiB

# Max number of concurrent connections, or 0 for no limit. Default: 0
#max_connections: 0

# The number of seconds of inactivity before a remote connection is closed.
#timeout: 300s

Expand Down
1 change: 1 addition & 0 deletions filebeat/inputsource/tcp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Config struct {
Host string `config:"host"`
Timeout time.Duration `config:"timeout" validate:"nonzero,positive"`
MaxMessageSize cfgtype.ByteSize `config:"max_message_size" validate:"nonzero,positive"`
MaxConnections int `config:"max_connections"`
TLS *tlscommon.ServerConfig `config:"ssl"`
}

Expand Down
20 changes: 18 additions & 2 deletions filebeat/inputsource/tcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"net"
"sync"

"golang.org/x/net/netutil"

"github.com/elastic/beats/filebeat/inputsource"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/logp"
Expand Down Expand Up @@ -175,12 +177,26 @@ func (s *Server) allClients() []*client {
}

func (s *Server) createServer() (net.Listener, error) {
var l net.Listener
var err error
if s.tlsConfig != nil {
t := s.tlsConfig.BuildModuleConfig(s.config.Host)
s.log.Info("Listening over TLS")
return tls.Listen("tcp", s.config.Host, t)
l, err = tls.Listen("tcp", s.config.Host, t)
if err != nil {
return nil, err
}
} else {
l, err = net.Listen("tcp", s.config.Host)
if err != nil {
return nil, err
}
}

if s.config.MaxConnections > 0 {
return netutil.LimitListener(l, s.config.MaxConnections), nil
}
return net.Listen("tcp", s.config.Host)
return l, nil
}

func (s *Server) clientsCount() int {
Expand Down
74 changes: 74 additions & 0 deletions vendor/golang.org/x/net/netutil/listen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,12 @@
"version": "release-branch.go1.9",
"versionExact": "release-branch.go1.9"
},
{
"checksumSHA1": "CkkyCjLPBm0OGzfMuTfaDsd45X4=",
"path": "golang.org/x/net/netutil",
"revision": "3b0461eec859c4b73bb64fdc8285971fd33e3938",
"revisionTime": "2019-06-20T19:42:36Z"
},
{
"checksumSHA1": "QEm/dePZ0lOnyOs+m22KjXfJ/IU=",
"path": "golang.org/x/net/proxy",
Expand Down
3 changes: 3 additions & 0 deletions x-pack/filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,9 @@ filebeat.inputs:
# Maximum size in bytes of the message received over TCP
#max_message_size: 20MiB

# Max number of concurrent connections, or 0 for no limit. Default: 0
#max_connections: 0

# The number of seconds of inactivity before a remote connection is closed.
#timeout: 300s

Expand Down