Skip to content

Commit c9dfaec

Browse files
committed
chore: add http debug support to pgcoord
1 parent c236a29 commit c9dfaec

File tree

11 files changed

+365
-100
lines changed

11 files changed

+365
-100
lines changed

coderd/coderd.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import (
6363
"github.com/coder/coder/coderd/wsconncache"
6464
"github.com/coder/coder/codersdk"
6565
"github.com/coder/coder/codersdk/agentsdk"
66+
enterprisetailnet "github.com/coder/coder/enterprise/tailnet"
6667
"github.com/coder/coder/provisionerd/proto"
6768
"github.com/coder/coder/provisionersdk"
6869
"github.com/coder/coder/site"
@@ -246,7 +247,7 @@ func New(options *Options) *API {
246247
options.DERPMapUpdateFrequency = 5 * time.Second
247248
}
248249
if options.TailnetCoordinator == nil {
249-
options.TailnetCoordinator = tailnet.NewCoordinator(options.Logger)
250+
// options.TailnetCoordinator = tailnet.NewCoordinator(options.Logger)
250251
}
251252
if options.Auditor == nil {
252253
options.Auditor = audit.NewNop()
@@ -324,6 +325,11 @@ func New(options *Options) *API {
324325
ctx, cancel := context.WithCancel(context.Background())
325326
r := chi.NewRouter()
326327

328+
options.TailnetCoordinator, err = enterprisetailnet.NewPGCoord(ctx, options.Logger, options.Pubsub, options.Database)
329+
if err != nil {
330+
panic(xerrors.Errorf("new pg coord: %w", err))
331+
}
332+
327333
// nolint:gocritic // Load deployment ID. This never changes
328334
depID, err := options.Database.GetDeploymentID(dbauthz.AsSystemRestricted(ctx))
329335
if err != nil {

coderd/database/dbauthz/dbauthz.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,20 @@ func (q *querier) GetActiveUserCount(ctx context.Context) (int64, error) {
784784
return q.db.GetActiveUserCount(ctx)
785785
}
786786

787+
func (q *querier) GetAllTailnetAgents(ctx context.Context) ([]database.TailnetAgent, error) {
788+
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceTailnetCoordinator); err != nil {
789+
return []database.TailnetAgent{}, err
790+
}
791+
return q.db.GetAllTailnetAgents(ctx)
792+
}
793+
794+
func (q *querier) GetAllTailnetClients(ctx context.Context) ([]database.TailnetClient, error) {
795+
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceTailnetCoordinator); err != nil {
796+
return []database.TailnetClient{}, err
797+
}
798+
return q.db.GetAllTailnetClients(ctx)
799+
}
800+
787801
func (q *querier) GetAppSecurityKey(ctx context.Context) (string, error) {
788802
// No authz checks
789803
return q.db.GetAppSecurityKey(ctx)

coderd/database/dbfake/dbfake.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,14 @@ func (q *FakeQuerier) GetActiveUserCount(_ context.Context) (int64, error) {
903903
return active, nil
904904
}
905905

906+
func (q *FakeQuerier) GetAllTailnetAgents(ctx context.Context) ([]database.TailnetAgent, error) {
907+
panic("not implemented")
908+
}
909+
910+
func (q *FakeQuerier) GetAllTailnetClients(ctx context.Context) ([]database.TailnetClient, error) {
911+
panic("not implemented")
912+
}
913+
906914
func (q *FakeQuerier) GetAppSecurityKey(_ context.Context) (string, error) {
907915
q.mutex.RLock()
908916
defer q.mutex.RUnlock()

coderd/database/dbmetrics/dbmetrics.go

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

coderd/database/dbmock/dbmock.go

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

coderd/database/querier.go

Lines changed: 2 additions & 0 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: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/tailnet.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,20 @@ SELECT *
5959
FROM tailnet_agents
6060
WHERE id = $1;
6161

62+
-- name: GetAllTailnetAgents :many
63+
SELECT *
64+
FROM tailnet_agents;
65+
6266
-- name: GetTailnetClientsForAgent :many
6367
SELECT *
6468
FROM tailnet_clients
6569
WHERE agent_id = $1;
6670

71+
-- name: GetAllTailnetClients :many
72+
SELECT *
73+
FROM tailnet_clients
74+
ORDER BY agent_id;
75+
6776
-- name: UpsertTailnetCoordinator :one
6877
INSERT INTO
6978
tailnet_coordinators (

enterprise/tailnet/coordinator.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,5 +704,7 @@ func (c *haCoordinator) ServeHTTPDebug(w http.ResponseWriter, r *http.Request) {
704704
c.mutex.RLock()
705705
defer c.mutex.RUnlock()
706706

707-
agpl.CoordinatorHTTPDebug(true, c.agentSockets, c.agentToConnectionSockets, c.nodes, c.agentNameCache)(w, r)
707+
agpl.CoordinatorHTTPDebug(
708+
agpl.HTTPDebugFromLocal(true, c.agentSockets, c.agentToConnectionSockets, c.nodes, c.agentNameCache),
709+
)(w, r)
708710
}

0 commit comments

Comments
 (0)