From 4c2906e89d3067bd01f36a5b80f3f78da58cd5a6 Mon Sep 17 00:00:00 2001 From: cmeng Date: Fri, 2 Jun 2023 10:36:14 +1200 Subject: [PATCH] fix(edge) inconsistent heartbeat EE-5533 (#9011) --- api/http/handler/endpoints/endpoint_list.go | 9 +++------ api/internal/endpointutils/endpointutils.go | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/api/http/handler/endpoints/endpoint_list.go b/api/http/handler/endpoints/endpoint_list.go index fd3cf804b..502c3cc31 100644 --- a/api/http/handler/endpoints/endpoint_list.go +++ b/api/http/handler/endpoints/endpoint_list.go @@ -1,15 +1,13 @@ package endpoints import ( - "net/http" - "sort" - "strconv" - "time" - "github.com/portainer/libhttp/request" portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/http/security" "github.com/portainer/portainer/api/internal/endpointutils" + "net/http" + "sort" + "strconv" httperror "github.com/portainer/libhttp/error" "github.com/portainer/libhttp/response" @@ -104,7 +102,6 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht if paginatedEndpoints[idx].EdgeCheckinInterval == 0 { paginatedEndpoints[idx].EdgeCheckinInterval = settings.EdgeAgentCheckinInterval } - paginatedEndpoints[idx].QueryDate = time.Now().Unix() endpointutils.UpdateEdgeEndpointHeartbeat(&paginatedEndpoints[idx], settings) if !query.excludeSnapshots { err = handler.SnapshotService.FillSnapshotData(&paginatedEndpoints[idx]) diff --git a/api/internal/endpointutils/endpointutils.go b/api/internal/endpointutils/endpointutils.go index d2b9b98d8..c9a181b00 100644 --- a/api/internal/endpointutils/endpointutils.go +++ b/api/internal/endpointutils/endpointutils.go @@ -200,6 +200,7 @@ func InitialStorageDetection(endpoint *portainer.Endpoint, endpointService datas func UpdateEdgeEndpointHeartbeat(endpoint *portainer.Endpoint, settings *portainer.Settings) { if IsEdgeEndpoint(endpoint) { + endpoint.QueryDate = time.Now().Unix() checkInInterval := getEndpointCheckinInterval(endpoint, settings) endpoint.Heartbeat = endpoint.QueryDate-endpoint.LastCheckInDate <= int64(checkInInterval*2+20) }