Skip to content

Commit

Permalink
Merge pull request #9206 from dvonthenen/feature/issue9163
Browse files Browse the repository at this point in the history
Exposes alarm/health information in "etcdctl endpoint status"
  • Loading branch information
gyuho authored Jan 25, 2018
2 parents 8ee3f5a + db822ed commit 3fdaf4e
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 235 deletions.
9 changes: 8 additions & 1 deletion Documentation/dev-guide/apispec/swagger/rpc.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,13 @@
"type": "string",
"format": "int64"
},
"errors": {
"type": "array",
"title": "errors contains alarm/health information and status",
"items": {
"type": "string"
}
},
"header": {
"$ref": "#/definitions/etcdserverpbResponseHeader"
},
Expand Down Expand Up @@ -2410,4 +2417,4 @@
"ApiKey": []
}
]
}
}
3 changes: 2 additions & 1 deletion etcdctl/ctlv3/command/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func makeMemberListTable(r v3.MemberListResponse) (hdr []string, rows [][]string
}

func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]string) {
hdr = []string{"endpoint", "ID", "version", "db size", "is leader", "raft term", "raft index", "raft applied index"}
hdr = []string{"endpoint", "ID", "version", "db size", "is leader", "raft term", "raft index", "raft applied index", "errors"}
for _, status := range statusList {
rows = append(rows, []string{
status.Ep,
Expand All @@ -185,6 +185,7 @@ func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]stri
fmt.Sprint(status.Resp.RaftTerm),
fmt.Sprint(status.Resp.RaftIndex),
fmt.Sprint(status.Resp.RaftAppliedIndex),
fmt.Sprint(strings.Join(status.Resp.Errors, ", ")),
})
}
return hdr, rows
Expand Down
1 change: 1 addition & 0 deletions etcdctl/ctlv3/command/printer_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (p *fieldsPrinter) EndpointStatus(eps []epStatus) {
fmt.Println(`"RaftIndex" :`, ep.Resp.RaftIndex)
fmt.Println(`"RaftTerm" :`, ep.Resp.RaftTerm)
fmt.Println(`"RaftAppliedIndex" :`, ep.Resp.RaftAppliedIndex)
fmt.Println(`"Errors" :`, ep.Resp.Errors)
fmt.Printf("\"Endpoint\" : %q\n", ep.Ep)
fmt.Println()
}
Expand Down
13 changes: 13 additions & 0 deletions etcdserver/api/v3rpc/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/coreos/etcd/mvcc"
"github.com/coreos/etcd/mvcc/backend"
"github.com/coreos/etcd/pkg/types"
"github.com/coreos/etcd/raft"
"github.com/coreos/etcd/version"
)

Expand All @@ -38,6 +39,9 @@ type BackendGetter interface {
}

type Alarmer interface {
// Alarms is implemented in Server interface located in etcdserver/server.go
// It returns a list of alarms present in the AlarmStore
Alarms() []*pb.AlarmMember
Alarm(ctx context.Context, ar *pb.AlarmRequest) (*pb.AlarmResponse, error)
}

Expand Down Expand Up @@ -161,6 +165,15 @@ func (ms *maintenanceServer) Status(ctx context.Context, ar *pb.StatusRequest) (
RaftTerm: ms.rg.Term(),
RaftAppliedIndex: ms.rg.AppliedIndex(),
}
if uint64(ms.rg.Leader()) == raft.None {
resp.Errors = append(resp.Errors, etcdserver.ErrNoLeader.Error())
}
alarms := ms.a.Alarms()
if len(alarms) > 0 {
for _, alarm := range alarms {
resp.Errors = append(resp.Errors, alarm.String())
}
}
ms.hdr.fill(resp.Header)
return resp, nil
}
Expand Down
Loading

0 comments on commit 3fdaf4e

Please sign in to comment.