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

Admin/Query: Log the real port instead of the provided one to enable the use of port 0 #2002

Merged
merged 10 commits into from
Jan 11, 2020
Merged

Admin/Query: Log the real port instead of the provided one to enable the use of port 0 #2002

merged 10 commits into from
Jan 11, 2020

Conversation

ChadiEM
Copy link
Contributor

@ChadiEM ChadiEM commented Jan 6, 2020

Which problem is this PR solving?

  • When using port 0 with the admin or query port, the Jaeger components print 0 instead of the port actually used. What this PR changes is to print the actual port.

Short description of the changes

Copy link
Member

@yurishkuro yurishkuro left a 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 Show resolved Hide resolved
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)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

can we fix this?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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

pkg/netutils/port.go Outdated Show resolved Hide resolved
pkg/netutils/port.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jan 7, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@162eee0). Click here to learn what that means.
The diff coverage is 93.75%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #2002   +/-   ##
========================================
  Coverage          ?   97.4%           
========================================
  Files             ?     206           
  Lines             ?   10136           
  Branches          ?       0           
========================================
  Hits              ?    9873           
  Misses            ?     221           
  Partials          ?      42
Impacted Files Coverage Δ
pkg/queue/bounded_queue.go 94.8% <100%> (ø)
pkg/discovery/grpcresolver/grpc_resolver.go 98.57% <50%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 162eee0...00b01f4. Read the comment docs.

pkg/netutils/port_test.go Outdated Show resolved Hide resolved
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)
Copy link
Member

Choose a reason for hiding this comment

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

can we fix this?

cmd/query/app/server_test.go Outdated Show resolved Hide resolved
Signed-off-by: Chadi El Masri <[email protected]>
Signed-off-by: Chadi El Masri <[email protected]>
Signed-off-by: Chadi El Masri <[email protected]>
Signed-off-by: Chadi El Masri <[email protected]>
Signed-off-by: Chadi El Masri <[email protected]>
Signed-off-by: Chadi El Masri <[email protected]>
@ChadiEM
Copy link
Contributor Author

ChadiEM commented Jan 9, 2020

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

@ChadiEM
Copy link
Contributor Author

ChadiEM commented Jan 10, 2020

Is the codecov/patch failure due to the lack of coverage of the error cases in the GetPort function?

Copy link
Member

@yurishkuro yurishkuro left a 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

assert.Greater(t, port, int64(0))
}

func TestAdminServerHandlesSimultaneousStartupOnPortZero(t *testing.T) {
Copy link
Member

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

defer adminServer.Close()
}

require.NoError(t, barrier.Await(context.Background()))
Copy link
Member

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?

@yurishkuro yurishkuro merged commit 3becf52 into jaegertracing:master Jan 11, 2020
@yurishkuro
Copy link
Member

Thanks for the PR!

@ChadiEM
Copy link
Contributor Author

ChadiEM commented Jan 12, 2020

Thanks @yurishkuro!

@ChadiEM ChadiEM deleted the print-real-port-number branch January 12, 2020 15:05
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.

2 participants