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

Move TCP UDP start up into server.Start() #4903

Merged
merged 1 commit into from
Aug 18, 2017

Conversation

vjsamuel
Copy link
Contributor

Making this change since NewTcpServer and NewUdpServer open the port which is not the ideal scenario.

@elasticmachine
Copy link
Collaborator

Can one of the admins verify this patch?

@vjsamuel vjsamuel changed the title Move TCP UDP start up out to server.Start() Move TCP UDP start up into server.Start() Aug 15, 2017
return &TcpServer{
listener: listener,
tcpAddr: addr,
receiveBufferSize: config.ReceiveBufferSize,
done: make(chan struct{}),
eventQueue: make(chan server.Event),
}, nil
}

func (g *TcpServer) Start() {
Copy link
Member

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).

Copy link
Contributor Author

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.

@urso
Copy link

urso commented Aug 15, 2017

@vjsamuel please check the test output. It seems there is a panic in netpoll after this change.

Copy link
Member

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

go g.WatchMetrics()
return nil

}

func (g *TcpServer) WatchMetrics() {
Copy link
Member

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)
Copy link
Member

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"?

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)
Copy link
Member

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 {
Copy link
Member

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)
Copy link
Member

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

Copy link
Member

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

func (g *UdpServer) Start() error {
listener, err := net.ListenUDP("udp", g.udpaddr)
if err != nil {
return errors.Wrap(err, "Failed to start UDP server")
Copy link
Member

Choose a reason for hiding this comment

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

@andrewkroh
Copy link
Member

@vjsamuel According to travis-ci this still needs to have make fmt run on it.

@vjsamuel vjsamuel force-pushed the move_tcp_udp_startup branch 2 times, most recently from 588d528 to 2fff7b9 Compare August 18, 2017 14:44
@andrewkroh andrewkroh merged commit d20e58a into elastic:master Aug 18, 2017
@vjsamuel vjsamuel deleted the move_tcp_udp_startup branch March 5, 2018 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants