etcd/etcdserver/api/rafthttp/probing_status.go

92 lines
2.5 KiB
Go
Raw Normal View History

2016-05-13 06:49:28 +03:00
// Copyright 2015 The etcd Authors
2015-08-03 04:07:16 +03:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rafthttp
import (
"time"
2016-03-23 03:10:28 +03:00
"github.com/xiang90/probing"
"go.uber.org/zap"
2015-08-03 04:07:16 +03:00
)
var (
// proberInterval must be shorter than read timeout.
// Or the connection will time-out.
proberInterval = ConnReadTimeout - time.Second
statusMonitoringInterval = 30 * time.Second
statusErrorInterval = 5 * time.Second
2015-08-03 04:07:16 +03:00
)
func addPeerToProber(lg *zap.Logger, p probing.Prober, id string, us []string) {
2015-08-03 04:07:16 +03:00
hus := make([]string, len(us))
for i := range us {
hus[i] = us[i] + ProbingPrefix
}
p.AddHTTP(id, proberInterval, hus)
s, err := p.Status(id)
if err != nil {
if lg != nil {
lg.Warn("failed to add peer into prober", zap.String("remote-peer-id", id))
} else {
plog.Errorf("failed to add peer %s into prober", id)
}
2015-08-03 04:07:16 +03:00
} else {
go monitorProbingStatus(lg, s, id)
2015-08-03 04:07:16 +03:00
}
}
func monitorProbingStatus(lg *zap.Logger, s probing.Status, id string) {
// set the first interval short to log error early.
interval := statusErrorInterval
2015-08-03 04:07:16 +03:00
for {
select {
case <-time.After(interval):
2015-08-03 04:07:16 +03:00
if !s.Health() {
if lg != nil {
lg.Warn(
"prober detected unhealthy status",
zap.String("remote-peer-id", id),
zap.Duration("rtt", s.SRTT()),
zap.Error(s.Err()),
)
} else {
plog.Warningf("health check for peer %s could not connect: %v", id, s.Err())
}
interval = statusErrorInterval
} else {
interval = statusMonitoringInterval
2015-08-03 04:07:16 +03:00
}
if s.ClockDiff() > time.Second {
if lg != nil {
lg.Warn(
"prober found high clock drift",
zap.String("remote-peer-id", id),
zap.Duration("clock-drift", s.SRTT()),
zap.Duration("rtt", s.ClockDiff()),
zap.Error(s.Err()),
)
} else {
plog.Warningf("the clock difference against peer %s is too high [%v > %v]", id, s.ClockDiff(), time.Second)
}
2015-08-03 04:07:16 +03:00
}
2016-05-07 04:02:55 +03:00
rtts.WithLabelValues(id).Observe(s.SRTT().Seconds())
2015-08-03 04:07:16 +03:00
case <-s.StopNotify():
return
}
}
}