-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
embed: make v2 endpoint optional #7170
Conversation
Current coverage is 64.13% (diff: 47.82%)
|
} 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) |
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.
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"` |
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.
probably just EnableV2
?
Handler: v2http.NewClientHandler(e.Server, e.Server.Cfg.ReqTimeout()), | ||
Info: e.cfg.CorsInfo, | ||
}) | ||
v2h := func() http.Handler { |
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.
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.
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.
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,
})
}
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.
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.
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.
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.") |
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.
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 |
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.
--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. |
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.
Accept etcd V2 client requests.
?
79c4918
to
179de1b
Compare
@heyitsanthony , please have a look. |
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. |
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.
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 { |
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.
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 { |
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.
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
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.
ok
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 i lazily went through below urls, to look for a ready made thing like for peer urls :) |
@vimalk78 check the e2e tests that have "TLS" in them. There's stuff like configClientTLS, configPeerTLS, etc, for that. |
179de1b
to
f80914f
Compare
lgtm |
LGTM |
enable-v2
with default valuetrue