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 4 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
7 changes: 5 additions & 2 deletions filebeat/_meta/common.reference.inputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ filebeat.inputs:
# Network type to be used for redis connection. Default: tcp
#network: tcp

# Max number of concurrent connections. Default: 10
#maxconn: 10
# Max number of concurrent connections. By default it is not limited.
#maxconn: 0
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like "maxconn" doesn't exist in the configuration, was this supposed to be removed?

Also make the documentation more explicit (after moving it below), e.g. "Max number of concurrent connections, or 0 for no limit. Default: 0"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️


# Redis AUTH password. Empty by default.
#password: foobared
Expand Down Expand Up @@ -263,6 +263,9 @@ filebeat.inputs:
# Maximum size in bytes of the message received over TCP
#max_message_size: 20MiB

# Maximum number of connections
#max_connections: 10

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

Expand Down
7 changes: 5 additions & 2 deletions filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ filebeat.inputs:
# Network type to be used for redis connection. Default: tcp
#network: tcp

# Max number of concurrent connections. Default: 10
#maxconn: 10
# Max number of concurrent connections. By default it is not limited.
#maxconn: 0

# Redis AUTH password. Empty by default.
#password: foobared
Expand Down Expand Up @@ -640,6 +640,9 @@ filebeat.inputs:
# Maximum size in bytes of the message received over TCP
#max_message_size: 20MiB

# Maximum number of connections
#max_connections: 10

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

Expand Down
1 change: 1 addition & 0 deletions filebeat/input/tcp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var defaultConfig = config{
Config: tcp.Config{
Timeout: time.Minute * 5,
MaxMessageSize: 20 * humanize.MiByte,
MaxConnections: 0,
kvch marked this conversation as resolved.
Show resolved Hide resolved
},
LineDelimiter: "\n",
}
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
7 changes: 5 additions & 2 deletions x-pack/filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ filebeat.inputs:
# Network type to be used for redis connection. Default: tcp
#network: tcp

# Max number of concurrent connections. Default: 10
#maxconn: 10
# Max number of concurrent connections. By default it is not limited.
#maxconn: 0

# Redis AUTH password. Empty by default.
#password: foobared
Expand Down Expand Up @@ -759,6 +759,9 @@ filebeat.inputs:
# Maximum size in bytes of the message received over TCP
#max_message_size: 20MiB

# Maximum number of connections
#max_connections: 10

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

Expand Down