Skip to content

Commit 4ba7af6

Browse files
committed
progress
1 parent 4b68a0b commit 4ba7af6

22 files changed

+343
-39
lines changed

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/database/dbauthz/system.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ func (q *querier) InsertDeploymentID(ctx context.Context, value string) error {
154154
return q.db.InsertDeploymentID(ctx, value)
155155
}
156156

157+
func (q *querier) GetReplicaByID(ctx context.Context, id uuid.UUID) (database.Replica, error) {
158+
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceSystem); err != nil {
159+
return database.Replica{}, err
160+
}
161+
return q.db.GetReplicaByID(ctx, id)
162+
}
163+
157164
func (q *querier) InsertReplica(ctx context.Context, arg database.InsertReplicaParams) (database.Replica, error) {
158165
if err := q.authorizeContext(ctx, rbac.ActionCreate, rbac.ResourceSystem); err != nil {
159166
return database.Replica{}, err

coderd/database/dbfake/databasefake.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4908,6 +4908,19 @@ func (q *fakeQuerier) DeleteReplicasUpdatedBefore(_ context.Context, before time
49084908
return nil
49094909
}
49104910

4911+
func (q *fakeQuerier) GetReplicaByID(_ context.Context, id uuid.UUID) (database.Replica, error) {
4912+
q.mutex.RLock()
4913+
defer q.mutex.RUnlock()
4914+
4915+
for _, replica := range q.replicas {
4916+
if replica.ID == id {
4917+
return replica, nil
4918+
}
4919+
}
4920+
4921+
return database.Replica{}, sql.ErrNoRows
4922+
}
4923+
49114924
func (q *fakeQuerier) InsertReplica(_ context.Context, arg database.InsertReplicaParams) (database.Replica, error) {
49124925
if err := validateDatabaseType(arg); err != nil {
49134926
return database.Replica{}, err
@@ -4926,6 +4939,7 @@ func (q *fakeQuerier) InsertReplica(_ context.Context, arg database.InsertReplic
49264939
RelayAddress: arg.RelayAddress,
49274940
Version: arg.Version,
49284941
DatabaseLatency: arg.DatabaseLatency,
4942+
Primary: arg.Primary,
49294943
}
49304944
q.replicas = append(q.replicas, replica)
49314945
return replica, nil
@@ -4952,6 +4966,7 @@ func (q *fakeQuerier) UpdateReplica(_ context.Context, arg database.UpdateReplic
49524966
replica.Version = arg.Version
49534967
replica.Error = arg.Error
49544968
replica.DatabaseLatency = arg.DatabaseLatency
4969+
replica.Primary = arg.Primary
49554970
q.replicas[index] = replica
49564971
return replica, nil
49574972
}

coderd/database/dump.sql

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ALTER TABLE workspace_proxies
2-
-- adding a serial to a table without a default value will be filled as you
3-
-- would expect
2+
-- Adding a serial to a table without a default value will be filled as you
3+
-- would expect on versions of Postgres >= 9 AFAIK (which we require).
44
ADD COLUMN region_id serial NOT NULL,
55
ADD COLUMN derp_enabled boolean NOT NULL DEFAULT true,
66
ADD CONSTRAINT workspace_proxies_region_id_unique UNIQUE (region_id);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
BEGIN;
2+
3+
-- drop any rows that aren't primary replicas
4+
DELETE FROM replicas
5+
WHERE "primary" = false;
6+
7+
ALTER TABLE replicas
8+
DROP COLUMN "primary";
9+
10+
COMMIT;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE replicas
2+
ADD COLUMN "primary" boolean NOT NULL DEFAULT true;

coderd/database/models.go

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

coderd/database/queries/replicas.sql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
-- name: GetReplicasUpdatedAfter :many
22
SELECT * FROM replicas WHERE updated_at > $1 AND stopped_at IS NULL;
33

4+
-- name: GetReplicaByID :one
5+
SELECT * FROM replicas WHERE id = $1;
6+
47
-- name: InsertReplica :one
58
INSERT INTO replicas (
69
id,
@@ -11,8 +14,9 @@ INSERT INTO replicas (
1114
region_id,
1215
relay_address,
1316
version,
14-
database_latency
15-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *;
17+
database_latency,
18+
"primary"
19+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *;
1620

1721
-- name: UpdateReplica :one
1822
UPDATE replicas SET
@@ -24,7 +28,8 @@ UPDATE replicas SET
2428
hostname = $7,
2529
version = $8,
2630
error = $9,
27-
database_latency = $10
31+
database_latency = $10,
32+
"primary" = $11
2833
WHERE id = $1 RETURNING *;
2934

3035
-- name: DeleteReplicasUpdatedBefore :exec

docs/api/schemas.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6663,28 +6663,51 @@ _None_
66636663
{
66646664
"access_url": "string",
66656665
"derp_enabled": true,
6666+
"hostname": "string",
6667+
"replica_error": "string",
6668+
"replica_id": "string",
6669+
"replica_relay_address": "string",
6670+
"version": "string",
66666671
"wildcard_hostname": "string"
66676672
}
66686673
```
66696674

66706675
### Properties
66716676

6672-
| Name | Type | Required | Restrictions | Description |
6673-
| ------------------- | ------- | -------- | ------------ | ----------------------------------------------------------------------------------- |
6674-
| `access_url` | string | false | | Access URL that hits the workspace proxy api. |
6675-
| `derp_enabled` | boolean | false | | Derp enabled indicates whether the proxy should be included in the DERP map or not. |
6676-
| `wildcard_hostname` | string | false | | Wildcard hostname that the workspace proxy api is serving for subdomain apps. |
6677+
| Name | Type | Required | Restrictions | Description |
6678+
| ------------------------------------------------------------------------------------------------- | ------- | -------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
6679+
| `access_url` | string | false | | Access URL that hits the workspace proxy api. |
6680+
| `derp_enabled` | boolean | false | | Derp enabled indicates whether the proxy should be included in the DERP map or not. |
6681+
| `hostname` | string | false | | Hostname is the OS hostname of the machine that the proxy is running on. This is only used for tracking purposes in the replicas table. |
6682+
| `replica_error` | string | false | | Replica error is the error that the replica encountered when trying to dial it's peers. This is stored in the replicas table for debugging purposes but does not affect the proxy's ability to register. |
6683+
| This value is only stored on subsequent requests to the register endpoint, not the first request. |
6684+
| `replica_id` | string | false | | Replica ID is a unique identifier for the replica of the proxy that is registering. It should be generated by the client on startup and persisted (in memory only) until the process is restarted. |
6685+
| `replica_relay_address` | string | false | | Replica relay address is the DERP address of the replica that other replicas may use to connect internally for DERP meshing. |
6686+
| `version` | string | false | | Version is the Coder version of the proxy. |
6687+
| `wildcard_hostname` | string | false | | Wildcard hostname that the workspace proxy api is serving for subdomain apps. |
66776688

66786689
## wsproxysdk.RegisterWorkspaceProxyResponse
66796690

66806691
```json
66816692
{
6682-
"app_security_key": "string"
6693+
"app_security_key": "string",
6694+
"sibling_replicas": [
6695+
{
6696+
"created_at": "2019-08-24T14:15:22Z",
6697+
"database_latency": 0,
6698+
"error": "string",
6699+
"hostname": "string",
6700+
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
6701+
"region_id": 0,
6702+
"relay_address": "string"
6703+
}
6704+
]
66836705
}
66846706
```
66856707

66866708
### Properties
66876709

6688-
| Name | Type | Required | Restrictions | Description |
6689-
| ------------------ | ------ | -------- | ------------ | ----------- |
6690-
| `app_security_key` | string | false | | |
6710+
| Name | Type | Required | Restrictions | Description |
6711+
| ------------------ | --------------------------------------------- | -------- | ------------ | -------------------------------------------------------------------------------------- |
6712+
| `app_security_key` | string | false | | |
6713+
| `sibling_replicas` | array of [codersdk.Replica](#codersdkreplica) | false | | Sibling replicas is a list of all other replicas of the proxy that have not timed out. |

0 commit comments

Comments
 (0)