Skip to content

chore: If selecting an unhealthy proxy, default to primary #7472

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 2 commits into from
May 10, 2023
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
9 changes: 9 additions & 0 deletions site/src/contexts/ProxyContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
MockPrimaryWorkspaceProxy,
MockWorkspaceProxies,
MockHealthyWildWorkspaceProxy,
MockUnhealthyWildWorkspaceProxy,
} from "testHelpers/entities"
import { getPreferredProxy } from "./ProxyContext"

Expand Down Expand Up @@ -38,6 +39,14 @@ describe("ProxyContextGetURLs", () => {
"",
MockPrimaryWorkspaceProxy.wildcard_hostname,
],
// Primary is the default if the selected is unhealthy
[
"unhealthy selection",
MockWorkspaceProxies,
MockUnhealthyWildWorkspaceProxy,
"",
MockPrimaryWorkspaceProxy.wildcard_hostname,
],
// This should never happen, when there is no primary
["no primary", [MockHealthyWildWorkspaceProxy], undefined, "", ""],
])(
Expand Down
4 changes: 2 additions & 2 deletions site/src/contexts/ProxyContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ export const getPreferredProxy = (
(proxy) => selectedProxy && proxy.id === selectedProxy.id,
)

if (!selectedProxy) {
// If no proxy is selected, default to the primary proxy.
// If no proxy is selected, or the selected proxy is unhealthy default to the primary proxy.
if (!selectedProxy || !selectedProxy.healthy) {
selectedProxy = proxies.find((proxy) => proxy.name === "primary")
}

Expand Down
20 changes: 11 additions & 9 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,20 @@ export const MockHealthyWildWorkspaceProxy: TypesGen.Region = {
wildcard_hostname: "*.external.com",
}

export const MockUnhealthyWildWorkspaceProxy: TypesGen.Region = {
id: "8444931c-0247-4171-842a-569d9f9cbadb",
name: "unhealthy",
display_name: "Unhealthy",
icon_url: "/emojis/1f92e.png",
healthy: false,
path_app_url: "https://unhealthy.coder.com",
wildcard_hostname: "*unhealthy..coder.com",
}

export const MockWorkspaceProxies: TypesGen.Region[] = [
MockPrimaryWorkspaceProxy,
MockHealthyWildWorkspaceProxy,
{
id: "8444931c-0247-4171-842a-569d9f9cbadb",
name: "unhealthy",
display_name: "Unhealthy",
icon_url: "/emojis/1f92e.png",
healthy: false,
path_app_url: "https://unhealthy.coder.com",
wildcard_hostname: "*unhealthy..coder.com",
},
MockUnhealthyWildWorkspaceProxy,
{
id: "26e84c16-db24-4636-a62d-aa1a4232b858",
name: "nowildcard",
Expand Down