Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployments Visualization #10

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions src/components/NodeList.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/ResourceChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ function ResourceChart({
},
limits: {
x: {
min: timestamps.at(-1),
max: timestamps.at(0),
min: timestamps.at(0),
max: timestamps.at(-1),
},
},
},
Expand Down
9 changes: 9 additions & 0 deletions src/components/SeedNodeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const NodeCard = React.forwardRef<
agentPort: number;
clientHost: string;
clientPort: number;
versionMetadata: {
cliAgentCommitHash: string;
}
};
}
// Complains about props not being validated
Expand Down Expand Up @@ -46,6 +49,12 @@ const NodeCard = React.forwardRef<
<div className="overflow-x-auto break-normal">
{data.clientHost}:{data.clientPort}
</div>
<span className="font-semibold">Commit Hash:</span>
<div className="overflow-x-auto break-normal">
<a href={`https://github.com/MatrixAI/Polykey-CLI/commit/${data.versionMetadata.cliAgentCommitHash}`}>
{data.versionMetadata.cliAgentCommitHash}
</a>
</div>
</>
) : (
<></>
Expand Down
65 changes: 64 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ export default function Home(): JSX.Element {
),
refetchInterval: 60 * 1000,
});
const deploymentsQuery = useQuery<Array<{
id: string;
commitHash: string;
startedOn: number;
finishedOn?: number;
progress: number;
}>>({
queryKey: ['deployments'],
queryFn: () =>
fetch(`${siteConfig.url}/api/deployments`).then((response) =>
response.json(),
),
refetchInterval: 60 * 1000,
});

const seedNodesCommitHashes = seedNodesQuery.data == null ? undefined : Object.values(seedNodesQuery.data).map((seedNode) =>
seedNode.versionMetadata.cliAgentCommitHash
);

return (
<Layout
Expand Down Expand Up @@ -75,7 +93,7 @@ export default function Home(): JSX.Element {
<></>
)}
</div>
<div className="w-full">
<div className="bg-[#E4F6F2] rounded-2xl p-3">
<div className="w-full md:w-1/2 inline-block aspect-[1.5]">
{resourceCpuQuery.data != null ? (
<ResourceChart title="CPU Usage" data={resourceCpuQuery.data} />
Expand All @@ -94,6 +112,51 @@ export default function Home(): JSX.Element {
)}
</div>
</div>
<div className='bg-[#E4F6F2] rounded-2xl p-3'>
<span className="font-semibold">Deployments:</span>
<table className='w-full mt-3 max-h-96'>
<thead>
<tr>
<th>ID</th>
<th className='w-full'>Commit Hash</th>
<th>Started On</th>
<th>Finished On</th>
<th>Nodes</th>
<th>Progress</th>
</tr>
</thead>
<tbody>
{deploymentsQuery.data != null && deploymentsQuery.data.length !== 0 ? (
deploymentsQuery.data.map(
(deployment) => (
<tr>
<td>{deployment.id}</td>
<td>
<a href={`https://github.com/MatrixAI/Polykey-CLI/commit/${deployment.commitHash}`}>
{deployment.commitHash}
</a>
</td>
<td>{new Date(deployment.startedOn).toISOString()}</td>
<td>{deployment.finishedOn == null ? "" : new Date(deployment.finishedOn).toISOString()}</td>
<td>
{seedNodesCommitHashes?.filter((commitHash) => commitHash === deployment.commitHash).length ?? 0}
</td>
<td>
{deployment.progress * 100}%
</td>
</tr>
),
)
) : (
<tr>
<td colSpan={5} align="center">
No deployments have been recorded
</td>
</tr>
)}
</tbody>
</table>
</div>
</div>
</div>
</Layout>
Expand Down