Add server upgrade status on admin panel (#20107)
## Summary Adds an admin upgrade-status panel that surfaces per-instance and per-workspace migration health, backed by a Redis-cached aggregate to keep the page snappy on large fleets. <img width="827" height="880" alt="Screenshot 2026-04-28 at 10 21 03" src="https://github.com/user-attachments/assets/8f88baa9-7268-4eff-bf6a-906a7f06ca91" /> <img width="804" height="892" alt="Screenshot 2026-04-28 at 10 21 11" src="https://github.com/user-attachments/assets/1e6decf8-766a-4d0e-96b1-03a9962bba3c" /> ## Computed metrics **Instance** (`InstanceUpgradeStatus`) - `inferredVersion` — version derived from the latest non-initial instance command name - `health` — `upToDate` | `behind` | `failed`, derived from the latest attempt vs. the last expected instance step in the upgrade sequence - `latestCommand` — `{ name, status, executedByVersion, errorMessage, createdAt }` from the most recent attempt **Per-workspace** (`WorkspaceUpgradeStatus`) - `workspaceId`, `displayName` - `inferredVersion`, `health`, `latestCommand` (same shape as instance), computed against the latest expected step in the sequence **Aggregate** (`AllWorkspacesUpgradeStatus`, only across `ACTIVE` / `SUSPENDED` workspaces) - `instanceUpgradeStatus` - `totalCount`, `upToDateCount`, `behindCount`, `failedCount` - `workspacesBehindIds[]`, `workspacesFailedIds[]` - `computedAt` ## Fetching strategy All reads go through `UpgradeStatusCacheService` (cache namespace: `EngineHealth`). - **Aggregate read** (`getAllWorkspacesStatus` → `getAllWorkspacesUpgradeStatus` query): reads summary + behind-ids + failed-ids in parallel; if any of the three keys is missing, full recompute (`recomputeAllWorkspaces`) is triggered, which also primes per-workspace entries. - **Per-workspace read** (`getWorkspacesStatus(ids)` → `getUpgradeStatus(ids)` query): `mget` on workspace keys; misses are recomputed individually (`recomputeWorkspace`), and aggregates are reconciled in place (count + id list deltas) without a full recompute. - **Recompute on demand**: `refreshUpgradeStatus` mutation calls `recomputeAllWorkspaces` to bypass cache and rewrite all keys. - **Auto-invalidation**: `InstanceCommandRunnerService` (fast + slow paths) and `WorkspaceCommandRunnerService` invalidate after every run via `safeInvalidateUpgradeStatusCache()` (`flushByPattern('upgrade-status:*')`). Failures in cache invalidation are swallowed and logged so they never break the migration runner. - **TTL**: `60 * 60 * 1000` ms (1 hour) on every key — protects against stale data even if a runner crashes before invalidating. ## Introduced cache keys All under the `EngineHealth` cache-storage namespace: | Key | Type | Purpose | | --- | --- | --- | | `upgrade-status:all-workspaces:summary` | `CachedAllWorkspacesStatusSummary` | Counts + instance status + `computedAt` | | `upgrade-status:all-workspaces:behind-ids` | `string[]` | Workspace ids in `behind` state | | `upgrade-status:all-workspaces:failed-ids` | `string[]` | Workspace ids in `failed` state | | `upgrade-status:workspace:<workspaceId>` | `CachedWorkspaceUpgradeStatus` | Per-workspace status (one key per workspace) | Full invalidation uses the pattern `upgrade-status:*`. ## Index added on `upgradeMigration` (already added on prod) Migration `2-2-instance-command-fast-1777308014234-addUpgradeMigrationWorkspaceIdIndex.ts`: ```sql CREATE INDEX "IDX_upgradeMigration_workspaceId_name_attempt" ON "core"."upgradeMigration" ("workspaceId", "name", "attempt") WHERE "workspaceId" IS NOT NULL;
This commit is contained in:
+96
-1
@@ -1,16 +1,22 @@
|
||||
import { SettingsTableCard } from '@/settings/components/SettingsTableCard';
|
||||
import { type WorkspaceInfo } from '@/settings/admin-panel/types/WorkspaceInfo';
|
||||
import { getUpgradeHealthStatusBadge } from '@/settings/admin-panel/utils/getUpgradeHealthStatusBadge';
|
||||
import { getWorkspaceSchemaName } from '@/settings/admin-panel/utils/getWorkspaceSchemaName';
|
||||
import { SettingsTableCard } from '@/settings/components/SettingsTableCard';
|
||||
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
|
||||
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
||||
import { UserContext } from '@/users/contexts/UserContext';
|
||||
import { styled } from '@linaria/react';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { useContext } from 'react';
|
||||
import { SettingsPath } from 'twenty-shared/types';
|
||||
import {
|
||||
formatUpgradeCommandName,
|
||||
getImageAbsoluteURI,
|
||||
getSettingsPath,
|
||||
isDefined,
|
||||
} from 'twenty-shared/utils';
|
||||
import { type GetUpgradeStatusQuery } from '~/generated-admin/graphql';
|
||||
import { AvatarOrIcon, LinkChip } from 'twenty-ui/components';
|
||||
import {
|
||||
H2Title,
|
||||
@@ -20,13 +26,18 @@ import {
|
||||
IconLink,
|
||||
IconStatusChange,
|
||||
IconUser,
|
||||
OverflowingTextWithTooltip,
|
||||
Status,
|
||||
} from 'twenty-ui/display';
|
||||
import { Section } from 'twenty-ui/layout';
|
||||
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
||||
import { dateLocaleState } from '~/localization/states/dateLocaleState';
|
||||
import { formatDateTimeString } from '~/utils/string/formatDateTimeString';
|
||||
|
||||
type SettingsAdminWorkspaceContentProps = {
|
||||
activeWorkspace: WorkspaceInfo | undefined;
|
||||
workspaceUpgradeStatus?: GetUpgradeStatusQuery['getUpgradeStatus'][number];
|
||||
};
|
||||
|
||||
const StyledContainer = styled.div`
|
||||
@@ -38,13 +49,28 @@ const StyledContainer = styled.div`
|
||||
|
||||
export const SettingsAdminWorkspaceContent = ({
|
||||
activeWorkspace,
|
||||
workspaceUpgradeStatus,
|
||||
}: SettingsAdminWorkspaceContentProps) => {
|
||||
const { t } = useLingui();
|
||||
const { dateFormat, timeFormat, timeZone } = useContext(UserContext);
|
||||
const { localeCatalog } = useAtomStateValue(dateLocaleState);
|
||||
|
||||
const formattedLastUpdated = formatDateTimeString({
|
||||
value: workspaceUpgradeStatus?.latestCommand?.createdAt,
|
||||
timeZone,
|
||||
dateFormat,
|
||||
timeFormat,
|
||||
localeCatalog: localeCatalog,
|
||||
});
|
||||
|
||||
const getWorkspaceUrl = (workspaceUrls: WorkspaceInfo['workspaceUrls']) => {
|
||||
return workspaceUrls.customUrl ?? workspaceUrls.subdomainUrl;
|
||||
};
|
||||
|
||||
const upgradeHealthStatusBadge = getUpgradeHealthStatusBadge(
|
||||
workspaceUpgradeStatus?.health,
|
||||
);
|
||||
|
||||
const workspaceInfoItems = [
|
||||
{
|
||||
Icon: IconHome,
|
||||
@@ -125,6 +151,75 @@ export const SettingsAdminWorkspaceContent = ({
|
||||
gridAutoColumns="1fr 4fr"
|
||||
/>
|
||||
</Section>
|
||||
{workspaceUpgradeStatus && (
|
||||
<Section>
|
||||
<H2Title
|
||||
title={t`Upgrade Status`}
|
||||
description={t`Workspace upgrade health`}
|
||||
/>
|
||||
<SettingsTableCard
|
||||
items={[
|
||||
{
|
||||
Icon: IconStatusChange,
|
||||
label: t`Status`,
|
||||
value: (
|
||||
<Status
|
||||
color={upgradeHealthStatusBadge.color}
|
||||
text={upgradeHealthStatusBadge.label}
|
||||
weight="medium"
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
Icon: IconId,
|
||||
label: t`Inferred version`,
|
||||
value: workspaceUpgradeStatus.inferredVersion ?? t`Unknown`,
|
||||
},
|
||||
{
|
||||
Icon: IconCalendar,
|
||||
label: t`Last command`,
|
||||
value: (
|
||||
<OverflowingTextWithTooltip
|
||||
text={
|
||||
workspaceUpgradeStatus.latestCommand?.name
|
||||
? formatUpgradeCommandName(
|
||||
workspaceUpgradeStatus.latestCommand.name,
|
||||
)
|
||||
: t`None`
|
||||
}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
Icon: IconCalendar,
|
||||
label: t`Last updated`,
|
||||
value: isNonEmptyString(formattedLastUpdated)
|
||||
? formattedLastUpdated
|
||||
: t`N/A`,
|
||||
},
|
||||
{
|
||||
Icon: IconStatusChange,
|
||||
label: t`Last command result`,
|
||||
value: workspaceUpgradeStatus.latestCommand?.status
|
||||
? workspaceUpgradeStatus.latestCommand.status === 'completed'
|
||||
? t`Completed`
|
||||
: t`Failed`
|
||||
: t`N/A`,
|
||||
},
|
||||
...(workspaceUpgradeStatus.latestCommand?.errorMessage
|
||||
? [
|
||||
{
|
||||
Icon: IconStatusChange,
|
||||
label: t`Last error`,
|
||||
value: workspaceUpgradeStatus.latestCommand.errorMessage,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
]}
|
||||
gridAutoColumns="2fr 3fr"
|
||||
/>
|
||||
</Section>
|
||||
)}
|
||||
</StyledContainer>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user