Skip to content
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
6 changes: 5 additions & 1 deletion scaletest/terraform/action/cf_dns.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
data "cloudflare_zone" "domain" {
name = var.cloudflare_domain
}

resource "cloudflare_record" "coder" {
for_each = local.deployments
zone_id = var.cloudflare_zone_id
zone_id = data.cloudflare_zone.domain.zone_id
name = each.value.subdomain
content = google_compute_address.coder[each.key].address
type = "A"
Expand Down
7 changes: 6 additions & 1 deletion scaletest/terraform/action/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ terraform {
provider "google" {
}

data "google_secret_manager_secret_version_access" "cloudflare_api_token_dns" {
secret = "cloudflare-api-token-dns"
project = var.project_id
}

provider "cloudflare" {
api_token = var.cloudflare_api_token
api_token = coalesce(var.cloudflare_api_token, data.google_secret_manager_secret_version_access.cloudflare_api_token_dns.secret_data)
}

provider "kubernetes" {
Expand Down
14 changes: 5 additions & 9 deletions scaletest/terraform/action/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ variable "scenario" {
// GCP
variable "project_id" {
description = "The project in which to provision resources"
default = "coder-scaletest"
}

variable "k8s_version" {
Expand All @@ -24,19 +25,14 @@ variable "k8s_version" {
variable "cloudflare_api_token" {
description = "Cloudflare API token."
sensitive = true
}

variable "cloudflare_email" {
description = "Cloudflare email address."
sensitive = true
# only override if you want to change the cloudflare_domain; pulls the token for scaletest.dev from Google Secrets
# Manager if null.
default = null
}

variable "cloudflare_domain" {
description = "Cloudflare coder domain."
}

variable "cloudflare_zone_id" {
description = "Cloudflare zone ID."
default = "scaletest.dev"
}

// Coder
Expand Down
18 changes: 18 additions & 0 deletions site/src/pages/WorkspacePage/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { ProvisionerJobLog } from "api/typesGenerated";
import { action } from "storybook/actions";
import type { WorkspacePermissions } from "../../modules/workspaces/permissions";
import { Workspace } from "./Workspace";
import { defaultPermissions } from "./WorkspaceNotifications/WorkspaceNotifications.stories";

// Helper function to create timestamps easily - Copied from AppStatuses.stories.tsx
const createTimestamp = (
Expand Down Expand Up @@ -349,6 +350,23 @@ export const Stopping: Story = {
},
};

export const Unhealthy: Story = {
args: {
...Running.args,
workspace: Mocks.MockUnhealthyWorkspace,
},
};

export const UnhealthyWithoutUpdatePermission: Story = {
args: {
...Unhealthy.args,
permissions: {
...defaultPermissions,
updateWorkspace: false,
},
},
};

export const FailedWithLogs: Story = {
args: {
...Running.args,
Expand Down
39 changes: 39 additions & 0 deletions site/src/pages/WorkspacePage/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
WorkspaceBuildProgress,
} from "./WorkspaceBuildProgress";
import { WorkspaceDeletedBanner } from "./WorkspaceDeletedBanner";
import { NotificationActionButton } from "./WorkspaceNotifications/Notifications";
import { findTroubleshootingURL } from "./WorkspaceNotifications/WorkspaceNotifications";
import { WorkspaceTopbar } from "./WorkspaceTopbar";

interface WorkspaceProps {
Expand Down Expand Up @@ -97,6 +99,8 @@ export const Workspace: FC<WorkspaceProps> = ({
(workspace.latest_build.matched_provisioners?.available ?? 1) > 0;
const shouldShowProvisionerAlert =
workspacePending && !haveBuildLogs && !provisionersHealthy && !isRestarting;
const troubleshootingURL = findTroubleshootingURL(workspace.latest_build);
const hasActions = permissions.updateWorkspace || troubleshootingURL;

return (
<div className="flex flex-col flex-1 min-h-0">
Expand Down Expand Up @@ -194,6 +198,41 @@ export const Workspace: FC<WorkspaceProps> = ({
</Alert>
)}

{!workspace.health.healthy && (
<Alert severity="warning">
<AlertTitle>Workspace is unhealthy</AlertTitle>
<AlertDetail>
<p>
Your workspace is running but{" "}
{workspace.health.failing_agents.length > 1
? `${workspace.health.failing_agents.length} agents are unhealthy`
: "1 agent is unhealthy"}
.
</p>
{hasActions && (
<div className="flex items-center gap-2">
{permissions.updateWorkspace && (
<NotificationActionButton
onClick={() => handleRestart()}
>
Restart
</NotificationActionButton>
)}
{troubleshootingURL && (
<NotificationActionButton
onClick={() =>
window.open(troubleshootingURL, "_blank")
}
>
Troubleshooting
</NotificationActionButton>
)}
</div>
)}
</AlertDetail>
</Alert>
)}

{transitionStats !== undefined && (
<WorkspaceBuildProgress
workspace={workspace}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { WorkspacePermissions } from "modules/workspaces/permissions";
import { expect, userEvent, waitFor, within } from "storybook/test";
import { WorkspaceNotifications } from "./WorkspaceNotifications";

const defaultPermissions: WorkspacePermissions = {
export const defaultPermissions: WorkspacePermissions = {
readWorkspace: true,
updateWorkspaceVersion: true,
updateWorkspace: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const styles = {
},
} satisfies Record<string, Interpolation<Theme>>;

const findTroubleshootingURL = (
export const findTroubleshootingURL = (
workspaceBuild: WorkspaceBuild,
): string | undefined => {
for (const resource of workspaceBuild.resources) {
Expand Down
23 changes: 23 additions & 0 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,15 @@ export const MockWorkspaceSubAgent: TypesGen.WorkspaceAgent = {
],
};

const MockWorkspaceUnhealthyAgent: TypesGen.WorkspaceAgent = {
...MockWorkspaceAgent,
id: "test-workspace-unhealthy-agent",
name: "a-workspace-unhealthy-agent",
status: "timeout",
lifecycle_state: "start_error",
health: { healthy: false },
};

export const MockWorkspaceAppStatus: TypesGen.WorkspaceAppStatus = {
id: "test-app-status",
created_at: "2022-05-17T17:39:01.382927298Z",
Expand Down Expand Up @@ -1445,6 +1454,20 @@ export const MockStoppingWorkspace: TypesGen.Workspace = {
status: "stopping",
},
};
export const MockUnhealthyWorkspace: TypesGen.Workspace = {
...MockWorkspace,
id: "test-unhealthy-workspace",
health: {
healthy: false,
failing_agents: [MockWorkspaceUnhealthyAgent.id],
},
latest_build: {
...MockWorkspace.latest_build,
resources: [
{ ...MockWorkspaceResource, agents: [MockWorkspaceUnhealthyAgent] },
],
},
};
export const MockStartingWorkspace: TypesGen.Workspace = {
...MockWorkspace,
id: "test-starting-workspace",
Expand Down
2 changes: 1 addition & 1 deletion testutil/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetRandomName(t testing.TB) string {
// an underscore.
func GetRandomNameHyphenated(t testing.TB) string {
t.Helper()
name := namesgenerator.GetRandomName(0)
name := GetRandomName(t)
return strings.ReplaceAll(name, "_", "-")
}

Expand Down
Loading