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

embed: make v2 endpoint optional #7170

Merged
merged 1 commit into from
Jan 20, 2017

Conversation

vimalk78
Copy link
Contributor

@vimalk78 vimalk78 commented Jan 16, 2017

  • added a config flag enable-v2 with default value true
  • if this flag is set to false, v2 handler is not created

@codecov-io
Copy link

codecov-io commented Jan 16, 2017

Current coverage is 64.13% (diff: 47.82%)

No coverage report found for master at b2d5c91.

Powered by Codecov. Last update b2d5c91...79c4918

} else {
plog.Infof("etcd v2 endpoints not enabled.")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "etcd v2 endpoints not enabled", http.StatusNotFound)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should the http error be changed ?

@@ -102,6 +102,7 @@ type Config struct {
InitialCluster string `json:"initial-cluster"`
InitialClusterToken string `json:"initial-cluster-token"`
StrictReconfigCheck bool `json:"strict-reconfig-check"`
EnableV2Endpoints bool `json:"enable-v2-endpoints"`
Copy link
Contributor

Choose a reason for hiding this comment

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

probably just EnableV2?

Handler: v2http.NewClientHandler(e.Server, e.Server.Cfg.ReqTimeout()),
Info: e.cfg.CorsInfo,
})
v2h := func() http.Handler {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please nil this out if v2 is disabled, instead of having a handler that returns an error, and build a v3-only handler in grpcHandlerFunc in serve.go if it's nil like I suggested? The reasoning is that if the v2 endpoint is disabled, having a v2 handler only to respond with an error only adds extra overhead to request processing.

Copy link
Contributor

Choose a reason for hiding this comment

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

This still needs to be nil'd out if v2 is disabled, otherwise there's still additional overhead in the grpc handler:

var v2h http.Handler
if e.Config().EnableV2 {
    v2h = http.Handler(&cors.CORSHandler{
        Handler: v2http.NewClientHandler(e.Server, e.Server.Cfg.ReqTimeout()),
        Info:    e.cfg.CorsInfo,
    })
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

v2h is nil if e.Config().EnableV2 == false , the function returns nil and sets v2h to nil.

but i agree it unnecessarily complicated, will change to the way you suggested.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, yeah. Definitely confusing.

@@ -155,6 +155,7 @@ func newConfig() *config {
plog.Panicf("unexpected error setting up clusterStateFlag: %v", err)
}
fs.BoolVar(&cfg.StrictReconfigCheck, "strict-reconfig-check", cfg.StrictReconfigCheck, "Reject reconfiguration requests that would cause quorum loss.")
fs.BoolVar(&cfg.EnableV2Endpoints, "enable-v2-endpoints", true, "etcd will start the v2 endpoints for the clients.")
Copy link
Contributor

Choose a reason for hiding this comment

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

s/enable-v2-endpoints/enable-v2/
s/etcd will start the v2 endpoints for the clients/Accept etcd V2 client requests.
?

@@ -88,6 +88,8 @@ clustering flags:
reject reconfiguration requests that would cause quorum loss.
--auto-compaction-retention '0'
auto compaction retention in hour. 0 means disable auto compaction.
--enable-v2-endpoints
Copy link
Contributor

Choose a reason for hiding this comment

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

--enable-v2?

@@ -88,6 +88,8 @@ clustering flags:
reject reconfiguration requests that would cause quorum loss.
--auto-compaction-retention '0'
auto compaction retention in hour. 0 means disable auto compaction.
--enable-v2-endpoints
etcd will start the v2 endpoints for the clients.
Copy link
Contributor

Choose a reason for hiding this comment

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

Accept etcd V2 client requests.?

@vimalk78 vimalk78 force-pushed the make-v2-endpoint-optional-#7100 branch 2 times, most recently from 79c4918 to 179de1b Compare January 19, 2017 11:49
@vimalk78
Copy link
Contributor Author

@heyitsanthony , please have a look.

@xiang90
Copy link
Contributor

xiang90 commented Jan 19, 2017

@gyuho @heyitsanthony

We probably need a release note for this. 1yr after 3.2 release, we will probably change the default flag of enable-v2 to false. (and we might use a simulated v2). later on, we will completely remove v2.

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.

two last changes and this should be ready

Handler: v2http.NewClientHandler(e.Server, e.Server.Cfg.ReqTimeout()),
Info: e.cfg.CorsInfo,
})
v2h := func() http.Handler {
Copy link
Contributor

Choose a reason for hiding this comment

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

This still needs to be nil'd out if v2 is disabled, otherwise there's still additional overhead in the grpc handler:

var v2h http.Handler
if e.Config().EnableV2 {
    v2h = http.Handler(&cors.CORSHandler{
        Handler: v2http.NewClientHandler(e.Server, e.Server.Cfg.ReqTimeout()),
        Info:    e.cfg.CorsInfo,
    })
}

@@ -122,13 +122,19 @@ func (sctx *serveCtx) serve(s *etcdserver.EtcdServer, tlscfg *tls.Config, handle
// grpcHandlerFunc returns an http.Handler that delegates to grpcServer on incoming gRPC
// connections or otherHandler otherwise. Copied from cockroachdb.
func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
if otherHandler != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

probably just have:

if otherHandler == nil {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        grpcServer.ServeHTTP(w, r)
    })
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
...

to avoid the extra indent level and keep the diff smaller

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@vimalk78
Copy link
Contributor Author

any suggestions for integration/e2e test cases based on this flag? i am still in the process of understanding the test framework, will send the test cases in another commit/PR.

since this PR touches the method grpcHandlerFunc which is used in sctx.secure case, i wanted to test this path. But i couldn't find how to configure for client URLs. the hack/tls-setup generates for peer URLs and the Procfile also uses the same.
is there any such cert/key files and Procfile for client urls?

i lazily went through below urls, to look for a ready made thing like for peer urls :)
https://coreos.com/etcd/docs/latest/op-guide/security.html
https://coreos.com/os/docs/latest/generate-self-signed-certificates.html

@heyitsanthony
Copy link
Contributor

@vimalk78 check the e2e tests that have "TLS" in them. There's stuff like configClientTLS, configPeerTLS, etc, for that.

@heyitsanthony
Copy link
Contributor

lgtm

@xiang90
Copy link
Contributor

xiang90 commented Jan 20, 2017

LGTM

@xiang90 xiang90 merged commit a630735 into etcd-io:master Jan 20, 2017
@gyuho gyuho changed the title embed/etcd.go: make v2 endpoint optional. fixes #7100 embed: make v2 endpoint optional May 2, 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.

5 participants