aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Macko <lmacko@cisco.com>2017-09-12 10:28:40 +0200
committerLukas Macko <lmacko@cisco.com>2017-09-12 10:49:30 +0200
commit03bc1c23595e998e8fa75a65e23bedfbec115643 (patch)
tree05a1c38070e75a9366402f480721a55fa8595f1c
parent217383b613248c79b542623ec6c571591de113ce (diff)
Make healthCheck parameters configurable
Change-Id: Idfb6945e13522867ced96a1ed7db85e725f42d1e Signed-off-by: Lukas Macko <lmacko@cisco.com>
-rw-r--r--core/core.go34
1 files changed, 32 insertions, 2 deletions
diff --git a/core/core.go b/core/core.go
index 3eea332..a045e60 100644
--- a/core/core.go
+++ b/core/core.go
@@ -37,9 +37,10 @@ const (
notificationChannelBufSize = 100 // default size of the notification channel buffers
)
-const (
+var (
healthCheckProbeInterval = time.Second * 1 // default health check probe interval
healthCheckReplyTimeout = time.Millisecond * 100 // timeout for reply to a health check probe
+ healthCheckThreshold = 1 // number of failed healthProbe until the error is reported
)
// ConnectionState holds the current state of the connection to VPP.
@@ -115,6 +116,28 @@ func SetLogger(l *logger.Logger) {
log = l
}
+// SetHealthCheckProbeInterval sets health check probe interval.
+// Beware: Function is not thread-safe. It is recommended to setup this parameter
+// before connecting to vpp.
+func SetHealthCheckProbeInterval(interval time.Duration) {
+ healthCheckProbeInterval = interval
+}
+
+// SetHealthCheckReplyTimeout sets timeout for reply to a health check probe.
+// If reply arrives after the timeout, check is considered as failed.
+// Beware: Function is not thread-safe. It is recommended to setup this parameter
+// before connecting to vpp.
+func SetHealthCheckReplyTimeout(timeout time.Duration) {
+ healthCheckReplyTimeout = timeout
+}
+
+// SetHealthCheckThreshold sets the number of failed healthProbe checks until the error is reported.
+// Beware: Function is not thread-safe. It is recommended to setup this parameter
+// before connecting to vpp.
+func SetHealthCheckThreshold(threshold int) {
+ healthCheckThreshold = threshold
+}
+
// Connect connects to VPP using specified VPP adapter and returns the connection handle.
// This call blocks until VPP is connected, or an error occurs. Only one connection attempt will be performed.
func Connect(vppAdapter adapter.VppAdapter) (*Connection, error) {
@@ -276,6 +299,7 @@ func (c *Connection) healthCheckLoop(connChan chan ConnectionEvent) {
return
}
+ failedChecks := 0
// send health check probes until an error occurs
for {
// wait for healthCheckProbeInterval
@@ -298,8 +322,14 @@ func (c *Connection) healthCheckLoop(connChan chan ConnectionEvent) {
err = errors.New("probe reply not received within the timeout period")
}
- // in case of error, break & disconnect
if err != nil {
+ failedChecks++
+ } else {
+ failedChecks = 0
+ }
+
+ if failedChecks >= healthCheckThreshold {
+ // in case of error, break & disconnect
log.Errorf("VPP health check failed: %v", err)
// signal disconnected event via channel
connChan <- ConnectionEvent{Timestamp: time.Now(), State: Disconnected}