summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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}