1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-09 15:55:23 +02:00

fix(home): fix homepage edge heartbeat judgement [EE-2041] (#6624)

* fix(home): judge LastCheckInDate with QueryDate for heartbeat

* refactor(environments): remove deprecated variable homepageLoadTime

* style(environments): run yarn format

Co-authored-by: sam@gemibook <huapox@126.com>
This commit is contained in:
Oscar Zhou 2022-03-14 14:53:23 +13:00 committed by GitHub
parent f1ea2b5c02
commit 5188ead870
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 15 additions and 41 deletions

View file

@ -63,6 +63,7 @@ export type Environment = {
GroupId: EnvironmentGroupId;
EdgeID?: string;
EdgeCheckinInterval?: number;
QueryDate?: number;
LastCheckInDate?: number;
Name: string;
Status: EnvironmentStatus;

View file

@ -21,14 +21,14 @@ function renderComponent(
edgeId = '',
lastCheckInDate = 0,
checkInInterval = 0,
homepageLoadTime = 0
queryDate = 0
) {
return render(
<EdgeIndicator
edgeId={edgeId}
lastCheckInDate={lastCheckInDate}
checkInInterval={checkInInterval}
homepageLoadTime={homepageLoadTime}
queryDate={queryDate}
/>
);
}

View file

@ -5,7 +5,7 @@ import { isoDateFromTimestamp } from '@/portainer/filters/filters';
interface Props {
checkInInterval?: number;
edgeId?: string;
homepageLoadTime?: number;
queryDate?: number;
lastCheckInDate?: number;
}
@ -13,7 +13,7 @@ export function EdgeIndicator({
edgeId,
lastCheckInDate,
checkInInterval,
homepageLoadTime,
queryDate,
}: Props) {
if (!edgeId) {
return (
@ -25,9 +25,8 @@ export function EdgeIndicator({
// give checkIn some wiggle room
let isCheckValid = false;
if (checkInInterval && homepageLoadTime && lastCheckInDate) {
isCheckValid =
homepageLoadTime - lastCheckInDate <= checkInInterval * 2 + 20;
if (checkInInterval && queryDate && lastCheckInDate) {
isCheckValid = queryDate - lastCheckInDate <= checkInInterval * 2 + 20;
}
return (

View file

@ -15,17 +15,10 @@ export default {
interface Args {
environment: Environment;
homepageLoadTime: number;
}
function Template({ environment, homepageLoadTime = 1 }: Args) {
return (
<EnvironmentItem
environment={environment}
homepageLoadTime={homepageLoadTime}
onClick={() => {}}
/>
);
function Template({ environment }: Args) {
return <EnvironmentItem environment={environment} onClick={() => {}} />;
}
export const DockerEnvironment: Story<Args> = Template.bind({});

View file

@ -67,7 +67,6 @@ function renderComponent(
onClick={() => {}}
environment={env}
groupName={group.Name}
homepageLoadTime={0}
/>
</UserContext.Provider>
);

View file

@ -25,18 +25,12 @@ import styles from './EnvironmentItem.module.css';
import { EnvironmentStatusBadge } from './EnvironmentStatusBadge';
interface Props {
homepageLoadTime?: number;
environment: Environment;
groupName?: string;
onClick(environment: Environment): void;
}
export function EnvironmentItem({
environment,
onClick,
homepageLoadTime,
groupName,
}: Props) {
export function EnvironmentItem({ environment, onClick, groupName }: Props) {
const isAdmin = useIsAdmin();
const isEdge = isEdgeEnvironment(environment.Type);
@ -77,7 +71,7 @@ export function EnvironmentItem({
edgeId={environment.EdgeID}
checkInInterval={environment.EdgeCheckinInterval}
lastCheckInDate={environment.LastCheckInDate}
homepageLoadTime={homepageLoadTime}
queryDate={environment.QueryDate}
/>
) : (
<>

View file

@ -31,8 +31,6 @@ interface Props {
}
export function EnvironmentList({ onClickItem, onRefresh }: Props) {
const homepageLoadTime = usePageLoadingTime();
const isAdmin = useIsAdmin();
const storageKey = 'home_endpoints';
@ -98,7 +96,6 @@ export function EnvironmentList({ onClickItem, onRefresh }: Props) {
groupsQuery.data?.find((g) => g.Id === env.GroupId)?.Name
}
onClick={onClickItem}
homepageLoadTime={homepageLoadTime}
/>
))
)}
@ -145,15 +142,3 @@ function renderItems(
return items;
}
function usePageLoadingTime() {
const [homepageLoadTime, setHomepageLoadTime] = useState<
number | undefined
>();
useEffect(() => {
setHomepageLoadTime(Math.floor(Date.now() / 1000));
}, []);
return homepageLoadTime;
}

View file

@ -8,6 +8,5 @@ export const EnvironmentListAngular = react2angular(EnvironmentList, [
'tags',
'onClickItem',
'onRefresh',
'homepageLoadTime',
'groups',
]);