mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: remove the dep on metrics. first step towards removing metrics pkg from etcd.
This commit is contained in:
parent
feaabde125
commit
33afbfead6
@ -35,7 +35,6 @@ import (
|
||||
"github.com/coreos/etcd/etcdserver/etcdhttp/httptypes"
|
||||
"github.com/coreos/etcd/etcdserver/etcdserverpb"
|
||||
"github.com/coreos/etcd/etcdserver/stats"
|
||||
"github.com/coreos/etcd/pkg/metrics"
|
||||
"github.com/coreos/etcd/pkg/types"
|
||||
"github.com/coreos/etcd/raft"
|
||||
"github.com/coreos/etcd/store"
|
||||
@ -291,7 +290,7 @@ func serveStats(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO: getting one key or a prefix of keys based on path
|
||||
fmt.Fprintf(w, "{\n")
|
||||
first := true
|
||||
metrics.Do(func(kv expvar.KeyValue) {
|
||||
expvar.Do(func(kv expvar.KeyValue) {
|
||||
if !first {
|
||||
fmt.Fprintf(w, ",\n")
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ package etcdserver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"expvar"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
@ -31,6 +32,19 @@ import (
|
||||
"github.com/coreos/etcd/wal/walpb"
|
||||
)
|
||||
|
||||
var (
|
||||
// indirection for expvar func interface
|
||||
// expvar panics when publishing duplicate name
|
||||
// expvar does not support remove a registered name
|
||||
// so only register a func that calls raftStatus
|
||||
// and change raftStatus as we need.
|
||||
raftStatus func() raft.Status
|
||||
)
|
||||
|
||||
func init() {
|
||||
expvar.Publish("raft.status", expvar.Func(func() interface{} { return raftStatus() }))
|
||||
}
|
||||
|
||||
type RaftTimer interface {
|
||||
Index() uint64
|
||||
Term() uint64
|
||||
@ -96,6 +110,7 @@ func startNode(cfg *ServerConfig, ids []types.ID) (id types.ID, n raft.Node, s *
|
||||
log.Printf("etcdserver: start member %s in cluster %s", id, cfg.Cluster.ID())
|
||||
s = raft.NewMemoryStorage()
|
||||
n = raft.StartNode(uint64(id), peers, cfg.ElectionTicks, 1, s)
|
||||
raftStatus = n.Status
|
||||
return
|
||||
}
|
||||
|
||||
@ -115,6 +130,7 @@ func restartNode(cfg *ServerConfig, snapshot *raftpb.Snapshot) (types.ID, raft.N
|
||||
s.SetHardState(st)
|
||||
s.Append(ents)
|
||||
n := raft.RestartNode(uint64(id), cfg.ElectionTicks, 1, s, 0)
|
||||
raftStatus = n.Status
|
||||
return id, n, s, w
|
||||
}
|
||||
|
||||
@ -156,6 +172,7 @@ func restartAsStandaloneNode(cfg *ServerConfig, snapshot *raftpb.Snapshot) (type
|
||||
s.SetHardState(st)
|
||||
s.Append(ents)
|
||||
n := raft.RestartNode(uint64(id), cfg.ElectionTicks, 1, s, 0)
|
||||
raftStatus = n.Status
|
||||
return id, n, s, w
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ package etcdserver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"expvar"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
@ -32,7 +31,6 @@ import (
|
||||
"github.com/coreos/etcd/etcdserver/stats"
|
||||
"github.com/coreos/etcd/pkg/fileutil"
|
||||
"github.com/coreos/etcd/pkg/idutil"
|
||||
"github.com/coreos/etcd/pkg/metrics"
|
||||
"github.com/coreos/etcd/pkg/pbutil"
|
||||
"github.com/coreos/etcd/pkg/timeutil"
|
||||
"github.com/coreos/etcd/pkg/types"
|
||||
@ -277,7 +275,6 @@ func (s *EtcdServer) Start() {
|
||||
s.start()
|
||||
go s.publish(defaultPublishRetryInterval)
|
||||
go s.purgeFile()
|
||||
metrics.Publish("raft.status", expvar.Func(s.raftStatus))
|
||||
}
|
||||
|
||||
// start prepares and starts server in a new goroutine. It is no longer safe to
|
||||
@ -540,8 +537,6 @@ func (s *EtcdServer) LeaderStats() []byte {
|
||||
|
||||
func (s *EtcdServer) StoreStats() []byte { return s.store.JsonStats() }
|
||||
|
||||
func (s *EtcdServer) raftStatus() interface{} { return s.r.Status() }
|
||||
|
||||
func (s *EtcdServer) AddMember(ctx context.Context, memb Member) error {
|
||||
// TODO: move Member to protobuf type
|
||||
b, err := json.Marshal(memb)
|
||||
|
Loading…
x
Reference in New Issue
Block a user