-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Admin/Query: Log the real port instead of the provided one to enable the use of port 0 #2002
Admin/Query: Log the real port instead of the provided one to enable the use of port 0 #2002
Conversation
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.
nvm
cmd/query/app/server_test.go
Outdated
onlyEntry := message.All()[0] | ||
port := onlyEntry.ContextMap()["port"].(int) | ||
assert.True(t, port > 0, | ||
"Expected a non-zero port in the logs, got instead: %d", port) |
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.
strictly speaking, it is possible that NewServer() function replaces 0 port with the default value, in which case this test will not catch it.
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.
one way to guarantee that it does is by starting two servers and validating that they both use different ports.
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 fix 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.
strictly speaking, it is possible that NewServer() function replaces 0 port with the default value, in which case this test will not catch it.
one way to guarantee that it does is by starting two servers and validating that they both use different ports.
Sure, I will add that test. However, what this PR targets is printing the real port in the log file instead of 0 and not the fact of using port 0 itself.
Using 0 works even before this PR :-)
btw, I also have a gap for testing the admin port log output. In the current state, I do not have a way to set the logger on the AdminServer
. What I can do is to expose setLogger()
and use it, then call Serve()
and check the log in that case. Would that be ok?
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.
Logger can be passed via InitFromViper. Look for Viperize helper function somewhere in the repo.
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 added tests for launching two instances in parallel. I used a cyclicbarrier to make sure that both servers are synchronized after the Start(), because without it, each goroutine can run on its own and the test behavior will be random. Let me know if you are ok with the thirdparty, or if you have other suggestions. :-)
Codecov Report
@@ Coverage Diff @@
## master #2002 +/- ##
========================================
Coverage ? 97.4%
========================================
Files ? 206
Lines ? 10136
Branches ? 0
========================================
Hits ? 9873
Misses ? 221
Partials ? 42
Continue to review full report at Codecov.
|
cmd/query/app/server_test.go
Outdated
onlyEntry := message.All()[0] | ||
port := onlyEntry.ContextMap()["port"].(int) | ||
assert.True(t, port > 0, | ||
"Expected a non-zero port in the logs, got instead: %d", port) |
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 fix this?
…the use of port 0. Signed-off-by: Chadi El Masri <celmasri@murex.com>
Signed-off-by: Chadi El Masri <celmasri@murex.com>
Signed-off-by: Chadi El Masri <celmasri@murex.com>
Signed-off-by: Chadi El Masri <celmasri@murex.com>
Signed-off-by: Chadi El Masri <celmasri@murex.com>
Signed-off-by: Chadi El Masri <celmasri@murex.com>
Signed-off-by: Chadi El Masri <celmasri@murex.com>
Signed-off-by: Chadi El Masri <celmasri@murex.com>
For consistency, I could also apply this change to the agent code (although it uses a different method to get the port with an equivalent result). |
Is the codecov/patch failure due to the lack of coverage of the error cases in the |
Signed-off-by: Yuri Shkuro <ys@uber.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
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.
to avoid another roundtrip I applied the changes
cmd/flags/admin_test.go
Outdated
assert.Greater(t, port, int64(0)) | ||
} | ||
|
||
func TestAdminServerHandlesSimultaneousStartupOnPortZero(t *testing.T) { |
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 don't think this test is necessary (two admin servers is not a real use case). In fact, my comment about two servers was not to test two servers themselves, but to test that when port 0 is passed as a parameter it's not overridden by some fixed default port number, since this is what was the reason for your PR (iirc).
cmd/flags/admin_test.go
Outdated
defer adminServer.Close() | ||
} | ||
|
||
require.NoError(t, barrier.Await(context.Background())) |
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.
what are trying to achieve with this?
Thanks for the PR! |
Thanks @yurishkuro! |
Which problem is this PR solving?
Short description of the changes
net.SplitHostPort
to get the actual port.