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

gateway: fix the dns discovery method #7454

Merged
merged 1 commit into from
Mar 8, 2017

Conversation

bdudelsack
Copy link
Contributor

strip the scheme from the endpoints to have a clean hostname for TCP proxy

Fixes #7452

@@ -77,6 +78,23 @@ func newGatewayStartCommand() *cobra.Command {
return &cmd
}

func stripSchema(eps []string) []string {
Copy link
Member

@fanminshi fanminshi Mar 8, 2017

Choose a reason for hiding this comment

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

Can you add unit tests for this function? I would like to increase the etcd coverage.

Copy link
Contributor

Choose a reason for hiding this comment

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

the discovery stuff should eventually be covered by e2e tests; I don't think a unit test is necessary here

Copy link
Member

Choose a reason for hiding this comment

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

@bdudelsack heyitsanthony is right about not having the unit test. The test path should be covered in e2e test where the correct behavior gateway should be verified. Sorry for the wrong suggestion.

Copy link
Contributor

@heyitsanthony heyitsanthony left a comment

Choose a reason for hiding this comment

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

looks OK in general


for _, ep := range eps {

if strings.HasPrefix(ep, "https://") {
Copy link
Contributor

Choose a reason for hiding this comment

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

use the url library instead?

if u, err := url.Parse(ep); err != nil {
    ep = u.Host
}
endpoints = append(endpoints, ep)

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 wanted it to be general and parse the endpoints passed by "--endpoints" param too. I think it could be a common mistake to add "http://" or "https://" to that parameter.

I could use the url library, but then parse only the endpoints which come from the dns discovery, or use this method for both. I don't think url method would work with correct hostnames like "etcd-node:2379" without further checks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, sorry. I meant:

if u, err := url.Parse(ep); err == nil {
    ep = u.Host
}
endpoints = append(endpoints, ep)

It'll strip the schema off a valid url and leave anything else (e.g., etcd-node:2379) alone.

Copy link
Contributor Author

@bdudelsack bdudelsack Mar 8, 2017

Choose a reason for hiding this comment

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

url.Parse seems to treat it like a relative path, so my tests are failing:

func stripSchema(eps []string) []string {
	var endpoints []string

	for _, ep := range eps {

		if u, err := url.Parse(ep); err == nil {
			ep = u.Host
		}
		endpoints = append(endpoints, ep)
	}

	return endpoints
}
--- FAIL: TestStripSchema (0.00s)
        gateway_test.go:24: Expected stripSchema to return 'etcd-node:2379' from 'etcd-node:2379' but got ''
        gateway_test.go:24: Expected stripSchema to return 'etcd-node' from 'etcd-node' but got ''

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, so if u, err := url.Parse(ep); err == nil && u.Host != ""?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would work 👌

@@ -24,6 +24,7 @@ import (
"github.com/coreos/etcd/pkg/transport"
"github.com/coreos/etcd/proxy/tcpproxy"
"github.com/spf13/cobra"
"strings"
Copy link
Contributor

Choose a reason for hiding this comment

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

standard library packages (e.g., net, os, strings) should be group together at the beginning of the import

@@ -0,0 +1,27 @@
package etcdmain
Copy link
Contributor

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

@bdudelsack bdudelsack force-pushed the gateway-dns-discovery branch 2 times, most recently from d05dca3 to 4ec1a42 Compare March 8, 2017 18:00
@bdudelsack
Copy link
Contributor Author

Build failed couse of

$WORK/github.com/coreos/etcd/integration/_test/integration.test: no space left on device

strip the scheme from the endpoints to have a clean hostname for TCP proxy

Fixes etcd-io#7452
@fanminshi
Copy link
Member

lgtm Thanks!

@heyitsanthony heyitsanthony merged commit 9713b1f into etcd-io:master Mar 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants