mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #6619 from mitake/health-key
etcdctl, e2e: add --check-key option to endpoint health
This commit is contained in:
commit
d1660b5ba3
@ -40,6 +40,15 @@ func ctlV3EndpointHealth(cx ctlCtx) error {
|
|||||||
return spawnWithExpects(cmdArgs, lines...)
|
return spawnWithExpects(cmdArgs, lines...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ctlV3EndpointHealthWithKey(cx ctlCtx, key string) error {
|
||||||
|
cmdArgs := append(cx.PrefixArgs(), "endpoint", "health", "--health-check-key", key)
|
||||||
|
lines := make([]string, cx.epc.cfg.clusterSize)
|
||||||
|
for i := range lines {
|
||||||
|
lines[i] = "is healthy"
|
||||||
|
}
|
||||||
|
return spawnWithExpects(cmdArgs, lines...)
|
||||||
|
}
|
||||||
|
|
||||||
func endpointStatusTest(cx ctlCtx) {
|
func endpointStatusTest(cx ctlCtx) {
|
||||||
if err := ctlV3EndpointStatus(cx); err != nil {
|
if err := ctlV3EndpointStatus(cx); err != nil {
|
||||||
cx.t.Fatalf("endpointStatusTest ctlV3EndpointStatus error (%v)", err)
|
cx.t.Fatalf("endpointStatusTest ctlV3EndpointStatus error (%v)", err)
|
||||||
@ -82,4 +91,14 @@ func endpointHealthTestWithAuth(cx ctlCtx) {
|
|||||||
if err := ctlV3EndpointHealthFailPermissionDenied(cx); err != nil {
|
if err := ctlV3EndpointHealthFailPermissionDenied(cx); err != nil {
|
||||||
cx.t.Fatalf("endpointStatusTest ctlV3EndpointHealth error (%v)", err)
|
cx.t.Fatalf("endpointStatusTest ctlV3EndpointHealth error (%v)", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cx.user, cx.pass = "root", "root"
|
||||||
|
if err := ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "custom-key", "", false}); err != nil {
|
||||||
|
cx.t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.user, cx.pass = "test-user", "pass"
|
||||||
|
if err := ctlV3EndpointHealthWithKey(cx, "custom-key"); err != nil {
|
||||||
|
cx.t.Fatalf("endpointStatusTest ctlV3EndpointHealth error (%v)", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,10 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
healthCheckKey string
|
||||||
|
)
|
||||||
|
|
||||||
// NewEndpointCommand returns the cobra command for "endpoint".
|
// NewEndpointCommand returns the cobra command for "endpoint".
|
||||||
func NewEndpointCommand() *cobra.Command {
|
func NewEndpointCommand() *cobra.Command {
|
||||||
ec := &cobra.Command{
|
ec := &cobra.Command{
|
||||||
@ -44,6 +48,9 @@ func newEpHealthCommand() *cobra.Command {
|
|||||||
Short: "Checks the healthiness of endpoints specified in `--endpoints` flag",
|
Short: "Checks the healthiness of endpoints specified in `--endpoints` flag",
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +101,7 @@ 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, "health")
|
_, err = cli.Get(ctx, healthCheckKey)
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s is unhealthy: failed to commit proposal: %v\n", ep, err)
|
fmt.Printf("%s is unhealthy: failed to commit proposal: %v\n", ep, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user