Skip to content

Commit e39382d

Browse files
authored
Merge branch 'main' into main
2 parents 7f74ff0 + 979687c commit e39382d

30 files changed

+280
-150
lines changed

coderd/apidoc/docs.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,11 @@ func New(options *Options) *API {
675675
api.Auditor.Store(&options.Auditor)
676676
api.TailnetCoordinator.Store(&options.TailnetCoordinator)
677677
dialer := &InmemTailnetDialer{
678-
CoordPtr: &api.TailnetCoordinator,
679-
DERPFn: api.DERPMap,
680-
Logger: options.Logger,
681-
ClientID: uuid.New(),
678+
CoordPtr: &api.TailnetCoordinator,
679+
DERPFn: api.DERPMap,
680+
Logger: options.Logger,
681+
ClientID: uuid.New(),
682+
DatabaseHealthCheck: api.Database,
682683
}
683684
stn, err := NewServerTailnet(api.ctx,
684685
options.Logger,

coderd/database/db2sdk/db2sdk.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,14 @@ func WorkspaceAppStatuses(statuses []database.WorkspaceAppStatus) []codersdk.Wor
537537

538538
func WorkspaceAppStatus(status database.WorkspaceAppStatus) codersdk.WorkspaceAppStatus {
539539
return codersdk.WorkspaceAppStatus{
540-
ID: status.ID,
541-
CreatedAt: status.CreatedAt,
542-
WorkspaceID: status.WorkspaceID,
543-
AgentID: status.AgentID,
544-
AppID: status.AppID,
545-
NeedsUserAttention: status.NeedsUserAttention,
546-
URI: status.Uri.String,
547-
Icon: status.Icon.String,
548-
Message: status.Message,
549-
State: codersdk.WorkspaceAppStatusState(status.State),
540+
ID: status.ID,
541+
CreatedAt: status.CreatedAt,
542+
WorkspaceID: status.WorkspaceID,
543+
AgentID: status.AgentID,
544+
AppID: status.AppID,
545+
URI: status.Uri.String,
546+
Message: status.Message,
547+
State: codersdk.WorkspaceAppStatusState(status.State),
550548
}
551549
}
552550

coderd/database/dbmem/dbmem.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9764,16 +9764,14 @@ func (q *FakeQuerier) InsertWorkspaceAppStatus(_ context.Context, arg database.I
97649764
defer q.mutex.Unlock()
97659765

97669766
status := database.WorkspaceAppStatus{
9767-
ID: arg.ID,
9768-
CreatedAt: arg.CreatedAt,
9769-
WorkspaceID: arg.WorkspaceID,
9770-
AgentID: arg.AgentID,
9771-
AppID: arg.AppID,
9772-
NeedsUserAttention: arg.NeedsUserAttention,
9773-
State: arg.State,
9774-
Message: arg.Message,
9775-
Uri: arg.Uri,
9776-
Icon: arg.Icon,
9767+
ID: arg.ID,
9768+
CreatedAt: arg.CreatedAt,
9769+
WorkspaceID: arg.WorkspaceID,
9770+
AgentID: arg.AgentID,
9771+
AppID: arg.AppID,
9772+
State: arg.State,
9773+
Message: arg.Message,
9774+
Uri: arg.Uri,
97779775
}
97789776
q.workspaceAppStatuses = append(q.workspaceAppStatuses, status)
97799777
return status, nil

coderd/database/dump.sql

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE ONLY workspace_app_statuses
2+
ADD COLUMN IF NOT EXISTS needs_user_attention BOOLEAN NOT NULL DEFAULT FALSE,
3+
ADD COLUMN IF NOT EXISTS icon TEXT;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE ONLY workspace_app_statuses
2+
DROP COLUMN IF EXISTS needs_user_attention,
3+
DROP COLUMN IF EXISTS icon;

coderd/database/models.go

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 14 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceapps.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ WHERE
4444
id = $1;
4545

4646
-- name: InsertWorkspaceAppStatus :one
47-
INSERT INTO workspace_app_statuses (id, created_at, workspace_id, agent_id, app_id, state, message, needs_user_attention, uri, icon)
48-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
47+
INSERT INTO workspace_app_statuses (id, created_at, workspace_id, agent_id, app_id, state, message, uri)
48+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
4949
RETURNING *;
5050

5151
-- name: GetWorkspaceAppStatusesByAppIDs :many
@@ -54,6 +54,6 @@ SELECT * FROM workspace_app_statuses WHERE app_id = ANY(@ids :: uuid [ ]);
5454
-- name: GetLatestWorkspaceAppStatusesByWorkspaceIDs :many
5555
SELECT DISTINCT ON (workspace_id)
5656
*
57-
FROM workspace_app_statuses
57+
FROM workspace_app_statuses
5858
WHERE workspace_id = ANY(@ids :: uuid[])
5959
ORDER BY workspace_id, created_at DESC;

coderd/tailnet.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ import (
2424
"tailscale.com/tailcfg"
2525

2626
"cdr.dev/slog"
27+
2728
"github.com/coder/coder/v2/coderd/tracing"
2829
"github.com/coder/coder/v2/coderd/workspaceapps"
2930
"github.com/coder/coder/v2/coderd/workspaceapps/appurl"
31+
"github.com/coder/coder/v2/codersdk"
3032
"github.com/coder/coder/v2/codersdk/workspacesdk"
3133
"github.com/coder/coder/v2/site"
3234
"github.com/coder/coder/v2/tailnet"
@@ -534,16 +536,28 @@ func NewMultiAgentController(ctx context.Context, logger slog.Logger, tracer tra
534536
return m
535537
}
536538

539+
type Pinger interface {
540+
Ping(context.Context) (time.Duration, error)
541+
}
542+
537543
// InmemTailnetDialer is a tailnet.ControlProtocolDialer that connects to a Coordinator and DERPMap
538544
// service running in the same memory space.
539545
type InmemTailnetDialer struct {
540546
CoordPtr *atomic.Pointer[tailnet.Coordinator]
541547
DERPFn func() *tailcfg.DERPMap
542548
Logger slog.Logger
543549
ClientID uuid.UUID
550+
// DatabaseHealthCheck is used to validate that the store is reachable.
551+
DatabaseHealthCheck Pinger
544552
}
545553

546-
func (a *InmemTailnetDialer) Dial(_ context.Context, _ tailnet.ResumeTokenController) (tailnet.ControlProtocolClients, error) {
554+
func (a *InmemTailnetDialer) Dial(ctx context.Context, _ tailnet.ResumeTokenController) (tailnet.ControlProtocolClients, error) {
555+
if a.DatabaseHealthCheck != nil {
556+
if _, err := a.DatabaseHealthCheck.Ping(ctx); err != nil {
557+
return tailnet.ControlProtocolClients{}, xerrors.Errorf("%w: %v", codersdk.ErrDatabaseNotReachable, err)
558+
}
559+
}
560+
547561
coord := a.CoordPtr.Load()
548562
if coord == nil {
549563
return tailnet.ControlProtocolClients{}, xerrors.Errorf("tailnet coordinator not initialized")

0 commit comments

Comments
 (0)