rafthttp: move server stats in raftHandler to etcdserver

This commit is contained in:
Yicheng Qin 2014-11-17 14:40:21 -08:00
parent 5dc5f8145c
commit f24e214ee5
3 changed files with 5 additions and 17 deletions

View File

@ -32,7 +32,7 @@ const (
// NewPeerHandler generates an http.Handler to handle etcd peer (raft) requests.
func NewPeerHandler(server *etcdserver.EtcdServer) http.Handler {
rh := rafthttp.NewHandler(server, server.Cluster.ID(), server)
rh := rafthttp.NewHandler(server, server.Cluster.ID())
mh := &peerMembersHandler{
clusterInfo: server.Cluster,
}

View File

@ -145,8 +145,6 @@ type Stats interface {
LeaderStats() []byte
// StoreStats returns statistics of the store backing this EtcdServer
StoreStats() []byte
// UpdateRecvApp updates the underlying statistics in response to a receiving an Append request
UpdateRecvApp(from types.ID, length int64)
}
type RaftTimer interface {
@ -321,6 +319,9 @@ func (s *EtcdServer) Process(ctx context.Context, m raftpb.Message) error {
log.Printf("etcdserver: reject message from removed member %s", types.ID(m.From).String())
return httptypes.NewHTTPError(http.StatusForbidden, "cannot process message from removed member")
}
if m.Type == raftpb.MsgApp {
s.stats.RecvAppendReq(types.ID(m.From).String(), m.Size())
}
return s.node.Step(ctx, m)
}
@ -486,10 +487,6 @@ func (s *EtcdServer) LeaderStats() []byte {
func (s *EtcdServer) StoreStats() []byte { return s.store.JsonStats() }
func (s *EtcdServer) UpdateRecvApp(from types.ID, length int64) {
s.stats.RecvAppendReq(from.String(), int(length))
}
func (s *EtcdServer) AddMember(ctx context.Context, memb Member) error {
// TODO: move Member to protobuf type
b, err := json.Marshal(memb)

View File

@ -31,22 +31,16 @@ type Processor interface {
Process(ctx context.Context, m raftpb.Message) error
}
type Stats interface {
UpdateRecvApp(from types.ID, length int64)
}
func NewHandler(p Processor, cid types.ID, ss Stats) http.Handler {
func NewHandler(p Processor, cid types.ID) http.Handler {
return &handler{
p: p,
cid: cid,
ss: ss,
}
}
type handler struct {
p Processor
cid types.ID
ss Stats
}
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -88,9 +82,6 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
return
}
if m.Type == raftpb.MsgApp {
h.ss.UpdateRecvApp(types.ID(m.From), r.ContentLength)
}
w.WriteHeader(http.StatusNoContent)
}