Debian Codegraph @

vendor/github.com/coreos/etcd/rafthttp/probing_status.go

raw
1 // Copyright 2015 The etcd Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package rafthttp
16
17 import (
18 "time"
19
20 "github.com/xiang90/probing"
21 )
22
23 var (
24 // proberInterval must be shorter than read timeout.
25 // Or the connection will time-out.
26 proberInterval = ConnReadTimeout - time.Second
27 statusMonitoringInterval = 30 * time.Second
28 statusErrorInterval = 5 * time.Second
29 )
30
31 func addPeerToProber(p probing.Prober, id string, us []string) {
32 hus := make([]string, len(us))
33 for i := range us {
34 hus[i] = us[i] + ProbingPrefix
35 }
36
37 p.AddHTTP(id, proberInterval, hus)
38
39 s, err := p.Status(id)
40 if err != nil {
41 plog.Errorf("failed to add peer %s into prober", id)
42 } else {
43 go monitorProbingStatus(s, id)
44 }
45 }
46
47 func monitorProbingStatus(s probing.Status, id string) {
48 // set the first interval short to log error early.
49 interval := statusErrorInterval
50 for {
51 select {
52 case <-time.After(interval):
53 if !s.Health() {
54 plog.Warningf("health check for peer %s could not connect: %v", id, s.Err())
55 interval = statusErrorInterval
56 } else {
57 interval = statusMonitoringInterval
58 }
59 if s.ClockDiff() > time.Second {
60 plog.Warningf("the clock difference against peer %s is too high [%v > %v]", id, s.ClockDiff(), time.Second)
61 }
62 rtts.WithLabelValues(id).Observe(s.SRTT().Seconds())
63 case <-s.StopNotify():
64 return
65 }
66 }
67 }