-
Notifications
You must be signed in to change notification settings - Fork 943
feat: display provisioner jobs and daemons for an organization #16532
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b6430bb
Set base structure to display the provisioner jobs
BrunoQuaresma 5d7d58f
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma 643c362
[WIP]: Load data and display them in the table
BrunoQuaresma f9db209
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma 6e967f1
Update table to use API data
BrunoQuaresma 943b7d7
Finish job structure
BrunoQuaresma 2bc6ccf
Display tiny alert for error
BrunoQuaresma 71f4fe5
Fix tags
BrunoQuaresma f027485
Add daemons page
BrunoQuaresma dcf8140
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma 994e186
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma 3083cef
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma d66141e
Display all daemon data from server
BrunoQuaresma 49a7ec7
Remove unused imports
BrunoQuaresma ffee2ed
Run fmt
BrunoQuaresma 7802636
Add cancel provisioner job
BrunoQuaresma 4f9030f
Run fmt
BrunoQuaresma 22dc7be
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma 0ff39e5
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma 5953960
Apply PR reviews
BrunoQuaresma aabf8df
FMT
BrunoQuaresma ed61ce7
Reset devcontainer.json
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add daemons page
- Loading branch information
commit f0274853daf302cba1e525eedb5d13735a859c1c
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
site/src/pages/OrganizationSettingsPage/ProvisionersPage/JobStatusIndicator.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { | ||
ProvisionerDaemonJob, | ||
ProvisionerJob, | ||
ProvisionerJobStatus, | ||
} from "api/typesGenerated"; | ||
import { | ||
StatusIndicator, | ||
StatusIndicatorDot, | ||
type StatusIndicatorProps, | ||
} from "components/StatusIndicator/StatusIndicator"; | ||
import { TriangleAlertIcon } from "lucide-react"; | ||
import type { FC } from "react"; | ||
|
||
type JobStatusIndicatorProps = { | ||
job: ProvisionerJob | ProvisionerDaemonJob; | ||
}; | ||
|
||
export const JobStatusIndicator: FC<JobStatusIndicatorProps> = ({ job }) => { | ||
const isProvisionerJob = "queue_position" in job; | ||
return ( | ||
<StatusIndicator size="sm" variant={statusIndicatorVariant(job.status)}> | ||
<StatusIndicatorDot /> | ||
<span className="[&:first-letter]:uppercase">{job.status}</span> | ||
{job.status === "failed" && ( | ||
<TriangleAlertIcon className="size-icon-xs p-[1px]" /> | ||
)} | ||
{job.status === "pending" && | ||
isProvisionerJob && | ||
`(${job.queue_position}/${job.queue_size})`} | ||
</StatusIndicator> | ||
); | ||
}; | ||
|
||
function statusIndicatorVariant( | ||
status: ProvisionerJobStatus, | ||
): StatusIndicatorProps["variant"] { | ||
switch (status) { | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case "succeeded": | ||
return "success"; | ||
case "failed": | ||
return "failed"; | ||
case "pending": | ||
case "running": | ||
case "canceling": | ||
return "pending"; | ||
case "canceled": | ||
case "unknown": | ||
return "inactive"; | ||
} | ||
} |
204 changes: 204 additions & 0 deletions
204
site/src/pages/OrganizationSettingsPage/ProvisionersPage/ProvisionerDaemonsPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
import { provisionerDaemons } from "api/queries/organizations"; | ||
import type { | ||
Organization, | ||
ProvisionerDaemon, | ||
ProvisionerDaemonStatus, | ||
} from "api/typesGenerated"; | ||
import { Badge } from "components/Badge/Badge"; | ||
import { Link } from "components/Link/Link"; | ||
import { | ||
StatusIndicator, | ||
StatusIndicatorDot, | ||
type StatusIndicatorProps, | ||
} from "components/StatusIndicator/StatusIndicator"; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from "components/Table/Table"; | ||
import { TableEmpty } from "components/TableEmpty/TableEmpty"; | ||
import { TableLoader } from "components/TableLoader/TableLoader"; | ||
import { ChevronDownIcon, ChevronRightIcon } from "lucide-react"; | ||
import { useState, type FC } from "react"; | ||
import { useQuery } from "react-query"; | ||
import { cn } from "utils/cn"; | ||
import { docs } from "utils/docs"; | ||
import { relativeTime } from "utils/time"; | ||
import { JobStatusIndicator } from "./JobStatusIndicator"; | ||
|
||
type ProvisionerDaemonsPageProps = { | ||
org: Organization; | ||
}; | ||
|
||
export const ProvisionerDaemonsPage: FC<ProvisionerDaemonsPageProps> = ({ | ||
org, | ||
}) => { | ||
const { data: daemons, isLoadingError } = useQuery( | ||
provisionerDaemons(org.id), | ||
); | ||
|
||
return ( | ||
<section className="flex flex-col gap-8"> | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<p className="text-sm text-content-secondary m-0 mt-2"> | ||
Coder server runs provisioner daemons which execute terraform during | ||
workspace and template builds.{" "} | ||
<Link | ||
href={docs( | ||
"/tutorials/best-practices/security-best-practices#provisioner-daemons", | ||
)} | ||
> | ||
View docs | ||
</Link> | ||
</p> | ||
|
||
<Table> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHead>Last seen</TableHead> | ||
<TableHead>Name</TableHead> | ||
<TableHead>Template</TableHead> | ||
<TableHead>Tags</TableHead> | ||
<TableHead>Status</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{daemons ? ( | ||
daemons.length > 0 ? ( | ||
daemons.map((d) => <DaemonRow key={d.id} daemon={d} />) | ||
) : ( | ||
<TableEmpty message="No provisioner daemons found" /> | ||
) | ||
) : isLoadingError ? ( | ||
<TableEmpty message="Error loading the provisioner daemons" /> | ||
) : ( | ||
<TableLoader /> | ||
)} | ||
</TableBody> | ||
</Table> | ||
</section> | ||
); | ||
}; | ||
|
||
type DaemonRowProps = { | ||
daemon: ProvisionerDaemon; | ||
}; | ||
|
||
const DaemonRow: FC<DaemonRowProps> = ({ daemon }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
<TableRow key={daemon.id}> | ||
<TableCell> | ||
<button | ||
className={cn([ | ||
"flex items-center gap-1 p-0 bg-transparent border-0 text-inherit text-xs cursor-pointer", | ||
"transition-colors hover:text-content-primary font-medium whitespace-nowrap", | ||
isOpen && "text-content-primary", | ||
])} | ||
type="button" | ||
onClick={() => { | ||
setIsOpen((v) => !v); | ||
}} | ||
> | ||
{isOpen ? ( | ||
<ChevronDownIcon className="size-icon-sm p-0.5" /> | ||
) : ( | ||
<ChevronRightIcon className="size-icon-sm p-0.5" /> | ||
)} | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<span className="[&:first-letter]:uppercase"> | ||
{relativeTime( | ||
new Date(daemon.last_seen_at ?? new Date().toISOString()), | ||
)} | ||
</span> | ||
</button> | ||
</TableCell> | ||
<TableCell>{daemon.name}</TableCell> | ||
<TableCell>Template</TableCell> | ||
<TableCell> | ||
<div className="flex items-center gap-1 flex-wrap"> | ||
{Object.entries(daemon.tags).map(([k, v]) => ( | ||
<Badge size="sm" key={k} className="whitespace-nowrap"> | ||
[{k} | ||
{v && `=${v}`}] | ||
</Badge> | ||
))} | ||
</div> | ||
</TableCell> | ||
<TableCell> | ||
<StatusIndicator | ||
size="sm" | ||
variant={statusIndicatorVariant(daemon.status)} | ||
> | ||
<StatusIndicatorDot /> | ||
<span className="[&:first-letter]:uppercase">{daemon.status}</span> | ||
</StatusIndicator> | ||
</TableCell> | ||
</TableRow> | ||
|
||
{isOpen && ( | ||
<TableRow> | ||
<TableCell colSpan={999} className="p-4 border-t-0"> | ||
<div | ||
className={cn([ | ||
"grid grid-cols-[auto_1fr] gap-x-4 items-center", | ||
"[&_span:nth-child(even)]:text-content-primary [&_span:nth-child(even)]:font-mono", | ||
"[&_span:nth-child(even)]:leading-[22px]", | ||
])} | ||
> | ||
<span>Last seen:</span> | ||
<span>{daemon.last_seen_at}</span> | ||
|
||
<span>Creation time:</span> | ||
<span>{daemon.created_at}</span> | ||
|
||
<span>Version:</span> | ||
<span>{daemon.version}</span> | ||
|
||
{daemon.current_job && ( | ||
<> | ||
<span>Last job:</span> | ||
<span>{daemon.current_job.id}</span> | ||
|
||
<span>Last job state:</span> | ||
<span> | ||
<JobStatusIndicator job={daemon.current_job} /> | ||
</span> | ||
</> | ||
)} | ||
|
||
{daemon.previous_job && ( | ||
<> | ||
<span>Previous job:</span> | ||
<span>{daemon.previous_job.id}</span> | ||
|
||
<span>Previous job state:</span> | ||
<span> | ||
<JobStatusIndicator job={daemon.previous_job} /> | ||
</span> | ||
</> | ||
)} | ||
</div> | ||
</TableCell> | ||
</TableRow> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
function statusIndicatorVariant( | ||
status: ProvisionerDaemonStatus | null, | ||
): StatusIndicatorProps["variant"] { | ||
switch (status) { | ||
case "idle": | ||
return "success"; | ||
case "busy": | ||
return "pending"; | ||
case "offline": | ||
case null: | ||
return "inactive"; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.