-
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
Feature: TCP Input #6700
Feature: TCP Input #6700
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package tcp | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/elastic/beats/filebeat/channel" | ||
|
@@ -10,7 +11,6 @@ import ( | |
"github.com/elastic/beats/filebeat/util" | ||
"github.com/elastic/beats/libbeat/beat" | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/common/atomic" | ||
"github.com/elastic/beats/libbeat/common/cfgwarn" | ||
"github.com/elastic/beats/libbeat/logp" | ||
) | ||
|
@@ -24,8 +24,9 @@ func init() { | |
|
||
// Input for TCP connection | ||
type Input struct { | ||
sync.Mutex | ||
server *tcp.Server | ||
started atomic.Bool | ||
started bool | ||
outlet channel.Outleter | ||
config *config | ||
log *logp.Logger | ||
|
@@ -64,7 +65,7 @@ func NewInput( | |
|
||
return &Input{ | ||
server: server, | ||
started: atomic.MakeBool(false), | ||
started: false, | ||
outlet: out, | ||
config: &config, | ||
log: logp.NewLogger("tcp input").With(config.Config.Host), | ||
|
@@ -73,22 +74,28 @@ func NewInput( | |
|
||
// Run start a TCP input | ||
func (p *Input) Run() { | ||
if !p.started.Load() { | ||
p.Lock() | ||
defer p.Unlock() | ||
|
||
if !p.started { | ||
p.log.Info("Starting TCP input") | ||
err := p.server.Start() | ||
if err != nil { | ||
p.log.Errorw("Error starting the TCP server", "error", err) | ||
} | ||
p.started.Swap(true) | ||
p.started = true | ||
} | ||
} | ||
|
||
// Stop stops TCP server | ||
func (p *Input) Stop() { | ||
p.log.Info("Stopping TCP input") | ||
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. The logging is not congruent with the UDP input. In UDP the message is logged after acquiring the lock. IDK which order, but I would like the behavior to be the same. 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. Correct, done in the next commit. |
||
defer p.outlet.Close() | ||
defer p.started.Swap(false) | ||
p.Lock() | ||
defer p.Unlock() | ||
|
||
p.server.Stop() | ||
p.started = false | ||
} | ||
|
||
// Wait stop the current server | ||
|
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.
Shouldn't this return the error?
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.
This would require changes in the upstream interface, I can create a followup issue on that?
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.
In general the way we use
Run()
is if it's blocking and often returns an error. In contrast we useStart()
if it's not blocking. I would expect all three in the above interface to potentially return an error.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.
Agree on that point but I think changing that interface is out of scope for this PR, so do you agree the plan of action is to do a followup issue.
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.
Yes, if we follow up on this ;-)
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.
created #6771