-
Notifications
You must be signed in to change notification settings - Fork 90
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
fail the snapshotter immediately if metrics server can't be bound #363
Conversation
pkg/metrics/listener.go
Outdated
} | ||
go func() { | ||
if err := http.ListenAndServe(addr, nil); err != nil { | ||
log.L.Errorf("error serve on %s: %v", addr, 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.
Can we make sure to exit snapshotter once http.ListenAndServe
fails?
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.
Better not to, we should try to maintain the snapshots service , I suppose.
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.
So the user can only determine if the metrics server is working by checking the error log? I think it's a not good design.
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.
Um. If we indeed need to ensure that the metrics server is successfully started, perhaps we can try to connect to the listener in the main goroutine
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 we just need to move the connection listen
out from ListenAndServe
. listen
is likely to fail when the port is already bound when serve can only fail when the connection is closed by accident
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. It is sufficient to quit snapshotter
if the port is already bound.
pkg/metrics/listener.go
Outdated
} | ||
go func() { | ||
if err := http.ListenAndServe(addr, nil); err != nil { | ||
log.L.Errorf("error serve on %s: %v", addr, 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.
Could we display information such as "Failed to serve metrics HTTP endpoint on %s: %v" as this error message is in a go routine.
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.
Good point. We'd better give more information about error context.
da14195
to
9f7ad26
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
} | ||
|
||
go func() { | ||
log.L.Infof("Start metrics HTTP server on %s", addr) | ||
if err := http.Serve(l, nil); trapClosedConnErr(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.
Perhaps err != nil && !errors.Is(err, net.ErrClosed)
will also work?
We'd better to exit from snapshotter's startup if the metrics server address can't be bound. Signed-off-by: Changwei Ge <gechangwei@bytedance.com>
9f7ad26
to
7354a06
Compare
We should fail snapshotter's startup if the metrics address weren't bound.