ctlv3: consider permission denied error to be healthy for endpoints

Relaxes the permission expectations for endpoint health by noting:
* permission denial on linearized reads is always through consensus
* endpoint health means consensus with the cluster through the endpoint

So, there's no need to require permission on a health check key in order
to know whether the endpoint is healthy.

Fixes #7057
This commit is contained in:
Anthony Romano 2016-12-27 14:40:29 -08:00
parent 407afc69ed
commit 00e00f16bb

View File

@ -21,12 +21,10 @@ import (
"time" "time"
v3 "github.com/coreos/etcd/clientv3" v3 "github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes"
"github.com/coreos/etcd/pkg/flags" "github.com/coreos/etcd/pkg/flags"
"github.com/spf13/cobra"
)
var ( "github.com/spf13/cobra"
healthCheckKey string
) )
// NewEndpointCommand returns the cobra command for "endpoint". // NewEndpointCommand returns the cobra command for "endpoint".
@ -49,8 +47,6 @@ func newEpHealthCommand() *cobra.Command {
Run: epHealthCommandFunc, Run: epHealthCommandFunc,
} }
cmd.Flags().StringVar(&healthCheckKey, "health-check-key", "health", "The key used to perform the health check. Makes sure the user can access the key.")
return cmd return cmd
} }
@ -101,12 +97,13 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) {
// get a random key. As long as we can get the response without an error, the // get a random key. As long as we can get the response without an error, the
// endpoint is health. // endpoint is health.
ctx, cancel := commandCtx(cmd) ctx, cancel := commandCtx(cmd)
_, err = cli.Get(ctx, healthCheckKey) _, err = cli.Get(ctx, "health")
cancel() cancel()
if err != nil { // permission denied is OK since proposal goes through consensus to get it
fmt.Printf("%s is unhealthy: failed to commit proposal: %v\n", ep, err) if err == nil || err == rpctypes.ErrPermissionDenied {
} else {
fmt.Printf("%s is healthy: successfully committed proposal: took = %v\n", ep, time.Since(st)) fmt.Printf("%s is healthy: successfully committed proposal: took = %v\n", ep, time.Since(st))
} else {
fmt.Printf("%s is unhealthy: failed to commit proposal: %v\n", ep, err)
} }
}(cfg) }(cfg)
} }