-
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
Move TCP UDP start up into server.Start()
#4903
Conversation
Can one of the admins verify this patch? |
server.Start()
server.Start()
8636fe8
to
a958b7f
Compare
metricbeat/helper/server/tcp/tcp.go
Outdated
return &TcpServer{ | ||
listener: listener, | ||
tcpAddr: addr, | ||
receiveBufferSize: config.ReceiveBufferSize, | ||
done: make(chan struct{}), | ||
eventQueue: make(chan server.Event), | ||
}, nil | ||
} | ||
|
||
func (g *TcpServer) Start() { |
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.
I think this should return the error to the caller if Start()
fails. Then the caller can at least know that it's not really listening and do something (like log and stop).
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.
@andrewkroh, addressed the review comment.
a958b7f
to
2409b2b
Compare
@vjsamuel please check the test output. It seems there is a panic in netpoll after this change. |
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.
I took a second look and had a few more thoughts. 😄
metricbeat/helper/server/tcp/tcp.go
Outdated
go g.WatchMetrics() | ||
return nil | ||
|
||
} | ||
|
||
func (g *TcpServer) WatchMetrics() { |
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.
Should this be unexported? I assumer users must call NewX
, Start
, GetEvents
, and lastly Stop
.
m.server.Start() | ||
err := m.server.Start() | ||
if err != nil { | ||
logp.Err("%v", err) |
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.
Do you want to add some context to the error message like "graphite server failed to start: %v"?
metricbeat/helper/server/udp/udp.go
Outdated
func (g *UdpServer) Start() error { | ||
listener, err := net.ListenUDP("udp", g.udpaddr) | ||
if err != nil { | ||
return fmt.Errorf("Failed to start UDP server with error: %v", err) |
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.
I would prefer errors.Wrap(err, "failed to start UDP server")
over fmt.Errorf
(with errors
being github.com/pkg/errors
). It retains the original error and also adds stack trace information that can be logged with %+v
.
@@ -61,7 +62,11 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | |||
// Run method provides the Graphite server with a reporter with which events can be reported. | |||
func (m *MetricSet) Run(reporter mb.PushReporter) { | |||
// Start event watcher | |||
m.server.Start() | |||
err := m.server.Start() | |||
if err != nil { |
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.
You could tighten this up if err := m.server.Start(); err != nil {...
m.server.Start() | ||
err := m.server.Start() | ||
if err != nil { | ||
logp.Err("%v", err) |
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.
You might find it useful to report the error to the output (e.g. reporter.Error(err)
). Then you will the info that one of the graphite listeners failed sent to your output.
err = errors.Wrap(err, "failed to start graphite server")
logp.Err("%v, err)
reporter.Error(err)
return
2409b2b
to
652d6d0
Compare
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.
LGTM. But I think you need to run make fmt
to re-order the imports.
metricbeat/helper/server/udp/udp.go
Outdated
func (g *UdpServer) Start() error { | ||
listener, err := net.ListenUDP("udp", g.udpaddr) | ||
if err != nil { | ||
return errors.Wrap(err, "Failed to start UDP 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.
Error strings should not be capitalized. https://github.com/golang/go/wiki/CodeReviewComments#error-strings
652d6d0
to
b0b5197
Compare
588d528
to
2fff7b9
Compare
2fff7b9
to
8bad167
Compare
Making this change since
NewTcpServer
andNewUdpServer
open the port which is not the ideal scenario.