Skip to content

feat(site): warn on provisioner health during builds #15589

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 18 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
show provisioner health warnings for templates
  • Loading branch information
SasSwart committed Nov 21, 2024
commit f0f72167c2299a1a10112ec06e36bda95bf67f8b
23 changes: 23 additions & 0 deletions site/src/modules/provisioners/useCompatibleProvisioners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,26 @@ export const useCompatibleProvisioners = (organization: string | undefined, tags

return compatibleProvisioners
}

export const provisionersUnhealthy = (provisioners : ProvisionerDaemon[]) => {
return provisioners.reduce((allUnhealthy, provisioner) => {
if (!allUnhealthy) {
// If we've found one healthy provisioner, then we don't need to look at the rest
return allUnhealthy;
}
// Otherwise, all provisioners so far have been unhealthy, so we check the next one

// If a provisioner has no last_seen_at value, then it's considered unhealthy
if (!provisioner.last_seen_at) {
return allUnhealthy;
}

// If a provisioner has not been seen within the last 60 seconds, then it's considered unhealthy
const lastSeen = new Date(provisioner.last_seen_at);
const oneMinuteAgo = new Date(Date.now() - 60000);
const unhealthy = lastSeen < oneMinuteAgo;


return allUnhealthy && unhealthy;
}, true);
}
28 changes: 3 additions & 25 deletions site/src/pages/CreateTemplatePage/BuildLogsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useWatchVersionLogs } from "modules/templates/useWatchVersionLogs";
import { WorkspaceBuildLogs } from "modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs";
import { type FC, useLayoutEffect, useRef } from "react";
import { navHeight } from "theme/constants";
import { useCompatibleProvisioners } from "modules/provisioners/useCompatibleProvisioners";
import { provisionersUnhealthy, useCompatibleProvisioners } from "modules/provisioners/useCompatibleProvisioners";

type BuildLogsDrawerProps = {
error: unknown;
Expand All @@ -32,26 +32,7 @@ export const BuildLogsDrawer: FC<BuildLogsDrawerProps> = ({
templateVersion?.organization_id,
templateVersion?.job.tags
);
const compatibleProvisionersUnhealthy = compatibleProvisioners.reduce((allUnhealthy, provisioner) => {
if (!allUnhealthy) {
// If we've found one healthy provisioner, then we don't need to look at the rest
return allUnhealthy;
}
// Otherwise, all provisioners so far have been unhealthy, so we check the next one

// If a provisioner has no last_seen_at value, then it's considered unhealthy
if (!provisioner.last_seen_at) {
return allUnhealthy;
}

// If a provisioner has not been seen within the last 60 seconds, then it's considered unhealthy
const lastSeen = new Date(provisioner.last_seen_at);
const oneMinuteAgo = new Date(Date.now() - 60000);
const unhealthy = lastSeen < oneMinuteAgo;


return allUnhealthy && unhealthy;
}, true);
const compatibleProvisionersUnhealthy = provisionersUnhealthy(compatibleProvisioners);

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

{isMissingVariables ? (
Expand Down
22 changes: 0 additions & 22 deletions site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,28 +305,6 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
</FormSection>
)}

<FormSection title="" description="">
<FormFields>
{/* TODO (SasSwart):
There are multiple error scenarios here. Do they each need specific copy, or is a general message fine?
* If a free tier user with no organisations or external provisioners uses a template which requires tags:
* can they provide tags to the internal provisioners to accept the job?
* If not, the alert copy below will be confusing, because they don't use the organisations feature and we mention it.
* Could there be no provisioners whatsoever, or do we always expect at least the internal provisioners to run?
* There may be provisioners, but none with the requisite tags.
* There may be provisioners with the requisite tags, but they may not have been seen by coderd for more an unacceptable duration
and therefore be considered stale.
* 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?
Should we warn about expected delays?
*/}
{/* 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? */}
{/* TODO (SasSwart): Do we need a stuck jobs page which lists the jobs queue with an alert for why each may be stuck? */}
<Alert variant="outlined" severity="error">
This organization does not have any provisioners compatible with this workspace. Before you create a template, you'll need to configure a provisioner.
</Alert>
</FormFields>
</FormSection>

<FormFooter
onCancel={onCancel}
isLoading={creatingWorkspace}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { MonacoEditor } from "./MonacoEditor";
import { ProvisionerTagsPopover } from "./ProvisionerTagsPopover";
import { PublishTemplateVersionDialog } from "./PublishTemplateVersionDialog";
import { TemplateVersionStatusBadge } from "./TemplateVersionStatusBadge";
import { provisionersUnhealthy, useCompatibleProvisioners } from "modules/provisioners/useCompatibleProvisioners";

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

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

const compatibleProvisioners = useCompatibleProvisioners(
templateVersion?.organization_id,
templateVersion?.job.tags
);
const compatibleProvisionersUnhealthy = provisionersUnhealthy(compatibleProvisioners);

const triggerPreview = useCallback(async () => {
await onPreview(fileTree);
setSelectedTab("logs");
Expand Down Expand Up @@ -581,7 +588,7 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
css={[styles.logs, styles.tabContent]}
ref={logsContentRef}
>
{templateVersion.job.error && (
{templateVersion.job.error ? (
<div>
<Alert
severity="error"
Expand All @@ -596,6 +603,21 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
<AlertDetail>{templateVersion.job.error}</AlertDetail>
</Alert>
</div>
) : compatibleProvisionersUnhealthy && (
<div>
<Alert
severity="warning"
css={{
borderRadius: 0,
border: 0,
borderBottom: `1px solid ${theme.palette.divider}`,
borderLeft: `2px solid ${theme.palette.error.main}`,
}}
>
<AlertTitle>Build may be delayed</AlertTitle>
<AlertDetail>No Compatible Provisioner Daemons have been recently seen</AlertDetail>
</Alert>
</div>
)}

{buildLogs && buildLogs.length > 0 ? (
Expand Down
Loading