Skip to content

fix(enterprise/coderd): make primary workspace proxy always be updated now #11499

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 1 commit into from
Jan 9, 2024
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 enterprise/coderd/workspaceproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ func convertRegion(proxy database.WorkspaceProxy, status proxyhealth.ProxyStatus
}

func convertProxy(p database.WorkspaceProxy, status proxyhealth.ProxyStatus) codersdk.WorkspaceProxy {
now := dbtime.Now()
if p.IsPrimary() {
// Primary is always healthy since the primary serves the api that this
// is returned from.
Expand All @@ -939,8 +940,11 @@ func convertProxy(p database.WorkspaceProxy, status proxyhealth.ProxyStatus) cod
ProxyHost: u.Host,
Status: proxyhealth.Healthy,
Report: codersdk.ProxyHealthReport{},
CheckedAt: time.Now(),
CheckedAt: now,
}
// For primary, created at / updated at are always 'now'
p.CreatedAt = now
p.UpdatedAt = now
}
if status.Status == "" {
status.Status = proxyhealth.Unknown
Expand Down
18 changes: 17 additions & 1 deletion enterprise/coderd/workspaceproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbtestutil"
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/coderd/workspaceapps"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
Expand Down Expand Up @@ -93,11 +94,16 @@ func TestRegions(t *testing.T) {
deploymentID, err := db.GetDeploymentID(ctx)
require.NoError(t, err, "get deployment ID")

// The default proxy is always called "primary".
primary, err := client.WorkspaceProxyByName(ctx, "primary")
require.NoError(t, err)

const proxyName = "hello"
_ = coderdenttest.NewWorkspaceProxy(t, api, client, &coderdenttest.ProxyOptions{
Name: proxyName,
AppHostname: appHostname + ".proxy",
})
approxCreateTime := dbtime.Now()
proxy, err := db.GetWorkspaceProxyByName(ctx, proxyName)
require.NoError(t, err)

Expand Down Expand Up @@ -135,7 +141,7 @@ func TestRegions(t *testing.T) {
require.NoError(t, err)
require.Len(t, regions, 2)

// Region 0 is the primary require.Len(t, regions, 1)
// Region 0 is the primary
require.NotEqual(t, uuid.Nil, regions[0].ID)
require.Equal(t, regions[0].ID.String(), deploymentID)
require.Equal(t, "primary", regions[0].Name)
Expand All @@ -145,6 +151,11 @@ func TestRegions(t *testing.T) {
require.Equal(t, client.URL.String(), regions[0].PathAppURL)
require.Equal(t, appHostname, regions[0].WildcardHostname)

// Ensure non-zero fields of the default proxy
require.NotZero(t, primary.Name)
require.NotZero(t, primary.CreatedAt)
require.NotZero(t, primary.UpdatedAt)

// Region 1 is the proxy.
require.NotEqual(t, uuid.Nil, regions[1].ID)
require.Equal(t, proxy.ID, regions[1].ID)
Expand All @@ -154,6 +165,11 @@ func TestRegions(t *testing.T) {
require.True(t, regions[1].Healthy)
require.Equal(t, proxy.Url, regions[1].PathAppURL)
require.Equal(t, proxy.WildcardHostname, regions[1].WildcardHostname)

// Unfortunately need to wait to assert createdAt/updatedAt
<-time.After(testutil.WaitShort / 10)
require.WithinDuration(t, approxCreateTime, proxy.CreatedAt, testutil.WaitShort/10)
require.WithinDuration(t, approxCreateTime, proxy.UpdatedAt, testutil.WaitShort/10)
})

t.Run("RequireAuth", func(t *testing.T) {
Expand Down