Skip to content

Commit f0f7216

Browse files
committed
show provisioner health warnings for templates
1 parent 0f78afc commit f0f7216

File tree

4 files changed

+49
-48
lines changed

4 files changed

+49
-48
lines changed

site/src/modules/provisioners/useCompatibleProvisioners.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,26 @@ export const useCompatibleProvisioners = (organization: string | undefined, tags
2727

2828
return compatibleProvisioners
2929
}
30+
31+
export const provisionersUnhealthy = (provisioners : ProvisionerDaemon[]) => {
32+
return provisioners.reduce((allUnhealthy, provisioner) => {
33+
if (!allUnhealthy) {
34+
// If we've found one healthy provisioner, then we don't need to look at the rest
35+
return allUnhealthy;
36+
}
37+
// Otherwise, all provisioners so far have been unhealthy, so we check the next one
38+
39+
// If a provisioner has no last_seen_at value, then it's considered unhealthy
40+
if (!provisioner.last_seen_at) {
41+
return allUnhealthy;
42+
}
43+
44+
// If a provisioner has not been seen within the last 60 seconds, then it's considered unhealthy
45+
const lastSeen = new Date(provisioner.last_seen_at);
46+
const oneMinuteAgo = new Date(Date.now() - 60000);
47+
const unhealthy = lastSeen < oneMinuteAgo;
48+
49+
50+
return allUnhealthy && unhealthy;
51+
}, true);
52+
}

site/src/pages/CreateTemplatePage/BuildLogsDrawer.tsx

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useWatchVersionLogs } from "modules/templates/useWatchVersionLogs";
1212
import { WorkspaceBuildLogs } from "modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs";
1313
import { type FC, useLayoutEffect, useRef } from "react";
1414
import { navHeight } from "theme/constants";
15-
import { useCompatibleProvisioners } from "modules/provisioners/useCompatibleProvisioners";
15+
import { provisionersUnhealthy, useCompatibleProvisioners } from "modules/provisioners/useCompatibleProvisioners";
1616

1717
type BuildLogsDrawerProps = {
1818
error: unknown;
@@ -32,26 +32,7 @@ export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({
3232
templateVersion?.organization_id,
3333
templateVersion?.job.tags
3434
);
35-
const compatibleProvisionersUnhealthy = compatibleProvisioners.reduce((allUnhealthy, provisioner) => {
36-
if (!allUnhealthy) {
37-
// If we've found one healthy provisioner, then we don't need to look at the rest
38-
return allUnhealthy;
39-
}
40-
// Otherwise, all provisioners so far have been unhealthy, so we check the next one
41-
42-
// If a provisioner has no last_seen_at value, then it's considered unhealthy
43-
if (!provisioner.last_seen_at) {
44-
return allUnhealthy;
45-
}
46-
47-
// If a provisioner has not been seen within the last 60 seconds, then it's considered unhealthy
48-
const lastSeen = new Date(provisioner.last_seen_at);
49-
const oneMinuteAgo = new Date(Date.now() - 60000);
50-
const unhealthy = lastSeen < oneMinuteAgo;
51-
52-
53-
return allUnhealthy && unhealthy;
54-
}, true);
35+
const compatibleProvisionersUnhealthy = provisionersUnhealthy(compatibleProvisioners);
5536

5637
const logs = useWatchVersionLogs(templateVersion);
5738
const logsContainer = useRef<HTMLDivElement>(null);
@@ -94,13 +75,10 @@ export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({
9475
{ !compatibleProvisioners && !logs ? (
9576
// If there are no compatible provisioners, warn that this job may be stuck
9677
<>No compatible provisioners</>
97-
) : compatibleProvisionersUnhealthy && !logs ? (
78+
) : compatibleProvisionersUnhealthy && !logs && (
9879
// If there are compatible provisioners in the db, but they have not reported recent health checks,
9980
// warn that the job might be stuck
10081
<>Compatible provisioners are potentially unhealthy. Your job might be delayed</>
101-
) : (
102-
// If there are compatible provisioners and at least one was recently seen, no warning is necessary.
103-
<></>
10482
)}
10583

10684
{isMissingVariables ? (

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -305,28 +305,6 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
305305
</FormSection>
306306
)}
307307

308-
<FormSection title="" description="">
309-
<FormFields>
310-
{/* TODO (SasSwart):
311-
There are multiple error scenarios here. Do they each need specific copy, or is a general message fine?
312-
* If a free tier user with no organisations or external provisioners uses a template which requires tags:
313-
* can they provide tags to the internal provisioners to accept the job?
314-
* If not, the alert copy below will be confusing, because they don't use the organisations feature and we mention it.
315-
* Could there be no provisioners whatsoever, or do we always expect at least the internal provisioners to run?
316-
* There may be provisioners, but none with the requisite tags.
317-
* There may be provisioners with the requisite tags, but they may not have been seen by coderd for more an unacceptable duration
318-
and therefore be considered stale.
319-
* There may be provisioners with the requisite tags that have been recently seen and are actively processing jobs, but what if the queue for jobs is long?
320-
Should we warn about expected delays?
321-
*/}
322-
{/* TODO (SasSwart): Considering the above, do we want to keep the alert simple here, but provide a link to the provisioner list page and show alerts there? */}
323-
{/* TODO (SasSwart): Do we need a stuck jobs page which lists the jobs queue with an alert for why each may be stuck? */}
324-
<Alert variant="outlined" severity="error">
325-
This organization does not have any provisioners compatible with this workspace. Before you create a template, you'll need to configure a provisioner.
326-
</Alert>
327-
</FormFields>
328-
</FormSection>
329-
330308
<FormFooter
331309
onCancel={onCancel}
332310
isLoading={creatingWorkspace}

site/src/pages/TemplateVersionEditorPage/TemplateVersionEditor.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import { MonacoEditor } from "./MonacoEditor";
6060
import { ProvisionerTagsPopover } from "./ProvisionerTagsPopover";
6161
import { PublishTemplateVersionDialog } from "./PublishTemplateVersionDialog";
6262
import { TemplateVersionStatusBadge } from "./TemplateVersionStatusBadge";
63+
import { provisionersUnhealthy, useCompatibleProvisioners } from "modules/provisioners/useCompatibleProvisioners";
6364

6465
type Tab = "logs" | "resources" | undefined; // Undefined is to hide the tab
6566

@@ -127,6 +128,12 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
127128
const [renameFileOpen, setRenameFileOpen] = useState<string>();
128129
const [dirty, setDirty] = useState(false);
129130

131+
const compatibleProvisioners = useCompatibleProvisioners(
132+
templateVersion?.organization_id,
133+
templateVersion?.job.tags
134+
);
135+
const compatibleProvisionersUnhealthy = provisionersUnhealthy(compatibleProvisioners);
136+
130137
const triggerPreview = useCallback(async () => {
131138
await onPreview(fileTree);
132139
setSelectedTab("logs");
@@ -581,7 +588,7 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
581588
css={[styles.logs, styles.tabContent]}
582589
ref={logsContentRef}
583590
>
584-
{templateVersion.job.error && (
591+
{templateVersion.job.error ? (
585592
<div>
586593
<Alert
587594
severity="error"
@@ -596,6 +603,21 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
596603
<AlertDetail>{templateVersion.job.error}</AlertDetail>
597604
</Alert>
598605
</div>
606+
) : compatibleProvisionersUnhealthy && (
607+
<div>
608+
<Alert
609+
severity="warning"
610+
css={{
611+
borderRadius: 0,
612+
border: 0,
613+
borderBottom: `1px solid ${theme.palette.divider}`,
614+
borderLeft: `2px solid ${theme.palette.error.main}`,
615+
}}
616+
>
617+
<AlertTitle>Build may be delayed</AlertTitle>
618+
<AlertDetail>No Compatible Provisioner Daemons have been recently seen</AlertDetail>
619+
</Alert>
620+
</div>
599621
)}
600622

601623
{buildLogs && buildLogs.length > 0 ? (

0 commit comments

Comments
 (0)