Skip to content

Commit

Permalink
Merge pull request #12775 from ptabor/20210314-zip
Browse files Browse the repository at this point in the history
etcd-raft-zap logger fixes.
  • Loading branch information
gyuho authored Mar 14, 2021
2 parents 527c765 + 1e7c180 commit e599f4a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 91 deletions.
14 changes: 7 additions & 7 deletions server/etcdserver/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ func (a *applierV3backend) Apply(r *pb.InternalRaftRequest) *applyResult {
defer func(start time.Time) {
success := ar.err == nil || ar.err == mvcc.ErrCompacted
applySec.WithLabelValues(v3Version, op, strconv.FormatBool(success)).Observe(time.Since(start).Seconds())
warnOfExpensiveRequest(a.s.getLogger(), a.s.Cfg.WarningApplyDuration, start, &pb.InternalRaftStringer{Request: r}, ar.resp, ar.err)
warnOfExpensiveRequest(a.s.Logger(), a.s.Cfg.WarningApplyDuration, start, &pb.InternalRaftStringer{Request: r}, ar.resp, ar.err)
if !success {
warnOfFailedRequest(a.s.getLogger(), start, &pb.InternalRaftStringer{Request: r}, ar.resp, ar.err)
warnOfFailedRequest(a.s.Logger(), start, &pb.InternalRaftStringer{Request: r}, ar.resp, ar.err)
}
}(time.Now())

Expand Down Expand Up @@ -243,7 +243,7 @@ func (a *applierV3backend) Put(ctx context.Context, txn mvcc.TxnWrite, p *pb.Put
// create put tracing if the trace in context is empty
if trace.IsEmpty() {
trace = traceutil.New("put",
a.s.getLogger(),
a.s.Logger(),
traceutil.Field{Key: "key", Value: string(p.Key)},
traceutil.Field{Key: "req_size", Value: proto.Size(p)},
)
Expand Down Expand Up @@ -420,7 +420,7 @@ func (a *applierV3backend) Range(ctx context.Context, txn mvcc.TxnRead, r *pb.Ra
func (a *applierV3backend) Txn(ctx context.Context, rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
trace := traceutil.Get(ctx)
if trace.IsEmpty() {
trace = traceutil.New("transaction", a.s.getLogger())
trace = traceutil.New("transaction", a.s.Logger())
ctx = context.WithValue(ctx, traceutil.TraceKey, trace)
}
isWrite := !isTxnReadonly(rt)
Expand Down Expand Up @@ -606,7 +606,7 @@ func (a *applierV3backend) applyTxn(ctx context.Context, txn mvcc.TxnWrite, rt *
reqs = rt.Failure
}

lg := a.s.getLogger()
lg := a.s.Logger()
for i, req := range reqs {
respi := tresp.Responses[i].Response
switch tv := req.Request.(type) {
Expand Down Expand Up @@ -654,7 +654,7 @@ func (a *applierV3backend) Compaction(compaction *pb.CompactionRequest) (*pb.Com
resp := &pb.CompactionResponse{}
resp.Header = &pb.ResponseHeader{}
trace := traceutil.New("compact",
a.s.getLogger(),
a.s.Logger(),
traceutil.Field{Key: "revision", Value: compaction.Revision},
)

Expand Down Expand Up @@ -698,7 +698,7 @@ func (a *applierV3backend) Alarm(ar *pb.AlarmRequest) (*pb.AlarmResponse, error)
resp := &pb.AlarmResponse{}
oldCount := len(a.s.alarmStore.Get(ar.Alarm))

lg := a.s.getLogger()
lg := a.s.Logger()
switch ar.Action {
case pb.AlarmRequest_GET:
resp.Alarms = a.s.alarmStore.Get(ar.Alarm)
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/apply_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (s *EtcdServer) applyV2Request(r *RequestV2) (resp Response) {
defer func(start time.Time) {
success := resp.Err == nil
applySec.WithLabelValues(v2Version, r.Method, strconv.FormatBool(success)).Observe(time.Since(start).Seconds())
warnOfExpensiveRequest(s.getLogger(), s.Cfg.WarningApplyDuration, start, stringer, nil, nil)
warnOfExpensiveRequest(s.Logger(), s.Cfg.WarningApplyDuration, start, stringer, nil, nil)
}(time.Now())

switch r.Method {
Expand Down
10 changes: 5 additions & 5 deletions server/etcdserver/corrupt.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *EtcdServer) CheckInitialHashKV() error {
return nil
}

lg := s.getLogger()
lg := s.Logger()

lg.Info(
"starting initial corruption check",
Expand Down Expand Up @@ -126,7 +126,7 @@ func (s *EtcdServer) monitorKVHash() {
return
}

lg := s.getLogger()
lg := s.Logger()
lg.Info(
"enabled corruption checking",
zap.String("local-member-id", s.ID().String()),
Expand All @@ -149,7 +149,7 @@ func (s *EtcdServer) monitorKVHash() {
}

func (s *EtcdServer) checkHashKV() error {
lg := s.getLogger()
lg := s.Logger()

h, rev, crev, err := s.kv.HashByRev(0)
if err != nil {
Expand Down Expand Up @@ -268,7 +268,7 @@ func (s *EtcdServer) getPeerHashKVs(rev int64) []*peerHashKVResp {
peers = append(peers, peerInfo{id: m.ID, eps: m.PeerURLs})
}

lg := s.getLogger()
lg := s.Logger()

var resps []*peerHashKVResp
for _, p := range peers {
Expand Down Expand Up @@ -345,7 +345,7 @@ type hashKVHandler struct {
}

func (s *EtcdServer) HashKVHandler() http.Handler {
return &hashKVHandler{lg: s.getLogger(), server: s}
return &hashKVHandler{lg: s.Logger(), server: s}
}

func (h *hashKVHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var (

// NewBackendQuota creates a quota layer with the given storage limit.
func NewBackendQuota(s *EtcdServer, name string) Quota {
lg := s.getLogger()
lg := s.Logger()
quotaBackendBytes.Set(float64(s.Cfg.QuotaBackendBytes))

if s.Cfg.QuotaBackendBytes < 0 {
Expand Down
53 changes: 22 additions & 31 deletions server/etcdserver/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,17 +461,7 @@ func startNode(cfg config.ServerConfig, cl *membership.RaftCluster, ids []types.
CheckQuorum: true,
PreVote: cfg.PreVote,
}
if cfg.Logger != nil {
// called after capnslog setting in "init" function
if cfg.LoggerConfig != nil {
c.Logger, err = NewRaftLogger(cfg.LoggerConfig)
if err != nil {
log.Fatalf("cannot create raft logger %v", err)
}
} else if cfg.LoggerCore != nil && cfg.LoggerWriteSyncer != nil {
c.Logger = NewRaftLoggerFromZapCore(cfg.LoggerCore, cfg.LoggerWriteSyncer)
}
}
c.Logger, err = getRaftLogger(cfg)

if len(peers) == 0 {
n = raft.RestartNode(c)
Expand Down Expand Up @@ -515,17 +505,10 @@ func restartNode(cfg config.ServerConfig, snapshot *raftpb.Snapshot) (types.ID,
CheckQuorum: true,
PreVote: cfg.PreVote,
}
if cfg.Logger != nil {
// called after capnslog setting in "init" function
var err error
if cfg.LoggerConfig != nil {
c.Logger, err = NewRaftLogger(cfg.LoggerConfig)
if err != nil {
log.Fatalf("cannot create raft logger %v", err)
}
} else if cfg.LoggerCore != nil && cfg.LoggerWriteSyncer != nil {
c.Logger = NewRaftLoggerFromZapCore(cfg.LoggerCore, cfg.LoggerWriteSyncer)
}
var err error
c.Logger, err = getRaftLogger(cfg)
if err != nil {
log.Fatalf("cannot create raft logger %v", err)
}

n := raft.RestartNode(c)
Expand Down Expand Up @@ -600,21 +583,29 @@ func restartAsStandaloneNode(cfg config.ServerConfig, snapshot *raftpb.Snapshot)
CheckQuorum: true,
PreVote: cfg.PreVote,
}

c.Logger, err = getRaftLogger(cfg)
if err != nil {
log.Fatalf("cannot create raft logger %v", err)
}

n := raft.RestartNode(c)
raftStatus = n.Status
return id, cl, n, s, w
}

func getRaftLogger(cfg config.ServerConfig) (raft.Logger, error) {
if cfg.Logger != nil {
// called after capnslog setting in "init" function
if cfg.LoggerConfig != nil {
c.Logger, err = NewRaftLogger(cfg.LoggerConfig)
if err != nil {
log.Fatalf("cannot create raft logger %v", err)
}
return NewRaftLogger(cfg.LoggerConfig)
} else if cfg.LoggerCore != nil && cfg.LoggerWriteSyncer != nil {
c.Logger = NewRaftLoggerFromZapCore(cfg.LoggerCore, cfg.LoggerWriteSyncer)
return NewRaftLoggerFromZapCore(cfg.LoggerCore, cfg.LoggerWriteSyncer), nil
} else {
return NewRaftLoggerZap(cfg.Logger), nil
}
}

n := raft.RestartNode(c)
raftStatus = n.Status
return id, cl, n, s, w
return nil, nil
}

// getIDs returns an ordered set of IDs included in the given snapshot and
Expand Down
Loading

0 comments on commit e599f4a

Please sign in to comment.