diff --git a/api/http/handler/endpoints/filter.go b/api/http/handler/endpoints/filter.go index bde2f1740..2bfcae43c 100644 --- a/api/http/handler/endpoints/filter.go +++ b/api/http/handler/endpoints/filter.go @@ -334,11 +334,16 @@ func filterEndpointsByStatuses(endpoints []portainer.Endpoint, statuses []portai status := endpoint.Status if endpointutils.IsEdgeEndpoint(&endpoint) { isCheckValid := false + edgeCheckinInterval := endpoint.EdgeCheckinInterval - if endpoint.EdgeCheckinInterval == 0 { + if edgeCheckinInterval == 0 { edgeCheckinInterval = settings.EdgeAgentCheckinInterval } + if endpoint.Edge.AsyncMode { + edgeCheckinInterval = getShortestAsyncInterval(&endpoint, settings) + } + if edgeCheckinInterval != 0 && endpoint.LastCheckInDate != 0 { isCheckValid = time.Now().Unix()-endpoint.LastCheckInDate <= int64(edgeCheckinInterval*EdgeDeviceIntervalMultiplier+EdgeDeviceIntervalAdd) } @@ -628,3 +633,29 @@ func getEdgeStackStatusParam(r *http.Request) (*portainer.EdgeStackStatusType, e return &edgeStackStatus, nil } + +func getShortestAsyncInterval(endpoint *portainer.Endpoint, settings *portainer.Settings) int { + var edgeIntervalUseDefault int = -1 + pingInterval := endpoint.Edge.PingInterval + if pingInterval == edgeIntervalUseDefault { + pingInterval = settings.Edge.PingInterval + } + shortestAsyncInterval := pingInterval + + snapshotInterval := endpoint.Edge.SnapshotInterval + if snapshotInterval == edgeIntervalUseDefault { + snapshotInterval = settings.Edge.SnapshotInterval + } + if shortestAsyncInterval > snapshotInterval { + shortestAsyncInterval = snapshotInterval + } + + commandInterval := endpoint.Edge.CommandInterval + if commandInterval == edgeIntervalUseDefault { + commandInterval = settings.Edge.CommandInterval + } + if shortestAsyncInterval > commandInterval { + shortestAsyncInterval = commandInterval + } + return shortestAsyncInterval +}