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

*: remove "errors" field in /health endpoint #9162

Merged
merged 4 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions Documentation/upgrades/upgrade_3_3.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,17 @@ cfg.SetupLogging()

Set `embed.Config.Debug` field to `true` to enable gRPC server logs.

#### Change in `/health` endpoint response value
#### Change in `/health` endpoint response

Previously, `[endpoint]:[client-port]/health` returned manually marshaled JSON value. 3.3 now defines [`etcdhttp.Health`](https://godoc.org/github.com/coreos/etcd/etcdserver/api/etcdhttp#Health) struct and includes errors, if any. Note that `"health"` field in `etcdhttp.Health` is `string` type (was boolean in v3.3.0-rc.0,1,2 but reverted to `string` for backward compatibilities).
Previously, `[endpoint]:[client-port]/health` returned manually marshaled JSON value. 3.3 now defines [`etcdhttp.Health`](https://godoc.org/github.com/coreos/etcd/etcdserver/api/etcdhttp#Health) struct.

Before
Note that in v3.3.0-rc.0, v3.3.0-rc.1, and v3.3.0-rc.2, `etcdhttp.Health` has boolean type `"health"` and `"errors"` fields. For backward compatibilities, we reverted `"health"` field to `string` type and removed `"errors"` field. Further health information will be provided in separate APIs.

```bash
$ curl http://localhost:2379/health
{"health":"true"}
```

After

```bash
$ curl http://localhost:2379/health
{"health":"true"}

# Or
{"health":"false","errors":["NOSPACE"]}
```

#### Change in gRPC gateway HTTP endpoints (replaced `/v3alpha` with `/v3beta`)

Before
Expand Down
2 changes: 1 addition & 1 deletion e2e/ctl_v3_alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func alarmTest(cx ctlCtx) {
}

// '/health' handler should return 'false'
if err := cURLGet(cx.epc, cURLReq{endpoint: "/health", expected: `{"health":"false","errors":["NOSPACE"]}`}); err != nil {
if err := cURLGet(cx.epc, cURLReq{endpoint: "/health", expected: `{"health":"false"}`}); err != nil {
cx.t.Fatalf("failed get with curl (%v)", err)
}

Expand Down
34 changes: 16 additions & 18 deletions etcdserver/api/etcdhttp/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,32 @@ func NewHealthHandler(hfunc func() Health) http.HandlerFunc {
// Health defines etcd server health status.
// TODO: remove manual parsing in etcdctl cluster-health
type Health struct {
Health string `json:"health"`
Errors []string `json:"errors,omitempty"`
Health string `json:"health"`
}

// TODO: server NOSPACE, etcdserver.ErrNoLeader in health API

func checkHealth(srv etcdserver.ServerV2) Health {
h := Health{Health: "false"}
h := Health{Health: "true"}

as := srv.Alarms()
if len(as) > 0 {
for _, v := range as {
h.Errors = append(h.Errors, v.Alarm.String())
}
return h
h.Health = "false"
}

if uint64(srv.Leader()) == raft.None {
h.Errors = append(h.Errors, etcdserver.ErrNoLeader.Error())
return h
if h.Health == "true" {
if uint64(srv.Leader()) == raft.None {
h.Health = "false"
}
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
_, err := srv.Do(ctx, etcdserverpb.Request{Method: "QGET"})
cancel()
if err != nil {
h.Errors = append(h.Errors, err.Error())
}
if err == nil {
h.Health = "true"
if h.Health == "true" {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
_, err := srv.Do(ctx, etcdserverpb.Request{Method: "QGET"})
cancel()
if err != nil {
h.Health = "false"
}
}
return h
}
3 changes: 0 additions & 3 deletions proxy/grpcproxy/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,5 @@ func checkHealth(c *clientv3.Client) etcdhttp.Health {
if err == nil || err == rpctypes.ErrPermissionDenied {
h.Health = "true"
}
if h.Health != "true" {
h.Errors = append(h.Errors, err.Error())
}
return h
}