diff --git a/api/datastore/test_data/output_24_to_latest.json b/api/datastore/test_data/output_24_to_latest.json index 2b4e002a4..1a80f6209 100644 --- a/api/datastore/test_data/output_24_to_latest.json +++ b/api/datastore/test_data/output_24_to_latest.json @@ -83,7 +83,6 @@ "MigrateIngresses": true }, "PublicURL": "", - "QueryDate": 0, "SecuritySettings": { "allowBindMountsForRegularUsers": true, "allowContainerCapabilitiesForRegularUsers": true, diff --git a/api/internal/endpointutils/endpoint_test.go b/api/internal/endpointutils/endpoint_test.go index fd6a1e71b..0fe7b8fd1 100644 --- a/api/internal/endpointutils/endpoint_test.go +++ b/api/internal/endpointutils/endpoint_test.go @@ -2,10 +2,12 @@ package endpointutils import ( "testing" + "time" portainer "github.com/portainer/portainer/api" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type isEndpointTypeTest struct { @@ -120,3 +122,18 @@ func Test_FilterByExcludeIDs(t *testing.T) { }) } } + +func TestUpdateEdgeEndpointHeartbeat(t *testing.T) { + endpoint := &portainer.Endpoint{ + Type: portainer.EdgeAgentOnDockerEnvironment, + LastCheckInDate: time.Now().Unix(), + EdgeCheckinInterval: 5, + } + + UpdateEdgeEndpointHeartbeat(endpoint, &portainer.Settings{}) + require.True(t, endpoint.Heartbeat) + + endpoint.LastCheckInDate = time.Now().Add(-time.Minute).Unix() + UpdateEdgeEndpointHeartbeat(endpoint, &portainer.Settings{}) + require.False(t, endpoint.Heartbeat) +} diff --git a/api/internal/endpointutils/endpointutils.go b/api/internal/endpointutils/endpointutils.go index f596ae0d5..c3f5d3ba6 100644 --- a/api/internal/endpointutils/endpointutils.go +++ b/api/internal/endpointutils/endpointutils.go @@ -215,9 +215,8 @@ func UpdateEdgeEndpointHeartbeat(endpoint *portainer.Endpoint, settings *portain return } - endpoint.QueryDate = time.Now().Unix() checkInInterval := getEndpointCheckinInterval(endpoint, settings) - endpoint.Heartbeat = endpoint.QueryDate-endpoint.LastCheckInDate <= int64(checkInInterval*2+20) + endpoint.Heartbeat = time.Now().Unix()-endpoint.LastCheckInDate <= int64(checkInInterval*2+20) } func getEndpointCheckinInterval(endpoint *portainer.Endpoint, settings *portainer.Settings) int { diff --git a/api/portainer.go b/api/portainer.go index e0b370796..1c724f8a9 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -448,8 +448,6 @@ type ( AMTDeviceGUID string `json:"AMTDeviceGUID,omitempty" example:"4c4c4544-004b-3910-8037-b6c04f504633"` // LastCheckInDate mark last check-in date on checkin LastCheckInDate int64 - // QueryDate of each query with the endpoints list - QueryDate int64 // Heartbeat indicates the heartbeat status of an edge environment Heartbeat bool `json:"Heartbeat" example:"true"` diff --git a/app/react/components/EdgeIndicator.test.tsx b/app/react/components/EdgeIndicator.test.tsx index 7defe27d0..d39daae4a 100644 --- a/app/react/components/EdgeIndicator.test.tsx +++ b/app/react/components/EdgeIndicator.test.tsx @@ -24,15 +24,13 @@ test('given edge id and last checkin is set, should show heartbeat', async () => async function renderComponent( edgeId = '', lastCheckInDate = 0, - checkInInterval = 0, - queryDate = 0 + checkInInterval = 0 ) { const environment = createMockEnvironment(); environment.EdgeID = edgeId; environment.LastCheckInDate = lastCheckInDate; environment.EdgeCheckinInterval = checkInInterval; - environment.QueryDate = queryDate; const Wrapped = withTestQueryProvider(EdgeIndicator); diff --git a/app/react/portainer/environments/types.ts b/app/react/portainer/environments/types.ts index 4f3fff120..be4d22026 100644 --- a/app/react/portainer/environments/types.ts +++ b/app/react/portainer/environments/types.ts @@ -153,7 +153,6 @@ export type Environment = { EdgeID?: string; EdgeKey: string; EdgeCheckinInterval?: number; - QueryDate?: number; Heartbeat?: boolean; LastCheckInDate?: number; Name: string;