Skip to content

chore: add derpserver to proxy, add proxies to derpmap #7311

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 32 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eae4c3a
chore: add derpserver to proxy, add proxies to derpmap
deansheather Apr 27, 2023
ac99525
progress
deansheather May 1, 2023
4b68a0b
Merge branch 'main' into dean/proxy-derp-map
deansheather May 2, 2023
4ba7af6
progress
deansheather May 3, 2023
dcf072e
derp mesh probably working
deansheather May 4, 2023
2d2f1a3
deregister
deansheather May 4, 2023
28ae155
tests and various fixes
deansheather May 4, 2023
2baa362
Merge branch 'main' into dean/proxy-derp-map
deansheather May 4, 2023
5f5d4ff
more tests
deansheather May 5, 2023
5441dc8
merge main, remove proxy goingaway route
deansheather May 30, 2023
e4a3008
derp tests work
deansheather May 30, 2023
3caa692
Merge branch 'main' into dean/proxy-derp-map
deansheather May 30, 2023
404c3e4
update derp map on new connection
deansheather May 31, 2023
8544882
Merge branch 'main' into dean/proxy-derp-map
deansheather Jun 13, 2023
9b503fa
fixes
deansheather Jun 13, 2023
0e6d39a
tests for derp map changing
deansheather Jun 13, 2023
bb699fb
Merge branch 'main' into dean/proxy-derp-map
deansheather Jun 13, 2023
2943ac2
backwards compatible
deansheather Jun 20, 2023
f0fa578
other comments
deansheather Jun 20, 2023
9d90dc2
Merge branch 'main' into dean/proxy-derp-map
deansheather Jun 25, 2023
b405113
fixup! Merge branch 'main' into dean/proxy-derp-map
deansheather Jun 25, 2023
6a08a59
change derp map updates to be separate websocket
deansheather Jun 28, 2023
403eac5
Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 17, 2023
d220266
Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 24, 2023
9e658d6
fixup! Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 24, 2023
67f2e5c
Working tests
deansheather Jul 25, 2023
3c96149
Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 25, 2023
c26936a
fixup! Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 25, 2023
e59de5a
fixup! Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 25, 2023
2df067f
fixup! Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 25, 2023
dfbfa96
Please
deansheather Jul 26, 2023
8223a35
fixup! Please
deansheather Jul 26, 2023
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
Prev Previous commit
Next Next commit
other comments
  • Loading branch information
deansheather committed Jun 20, 2023
commit f0fa5784cf2772b3a9150b68827fc1e929682a51
2 changes: 1 addition & 1 deletion coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func New(options *Options) *API {
options.HealthcheckFunc = func(ctx context.Context, apiKey string) *healthcheck.Report {
return healthcheck.Run(ctx, &healthcheck.ReportOptions{
AccessURL: options.AccessURL,
DERPMap: api.DERPMap().Clone(),
DERPMap: api.DERPMap(),
APIKey: apiKey,
})
}
Expand Down
28 changes: 22 additions & 6 deletions enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,22 +476,38 @@ func (api *API) updateEntitlements(ctx context.Context) error {
//
// Two ints are returned, the first is the starting region ID for proxies, and
// the second is the maximum region ID that already exists in the DERP map.
func getProxyDERPStartingRegionID(derpMap *tailcfg.DERPMap) (sID int, mID int) {
maxRegionID := 0
func getProxyDERPStartingRegionID(derpMap *tailcfg.DERPMap) (sID int64, mID int64) {
var maxRegionID int64
for _, region := range derpMap.Regions {
if region.RegionID > maxRegionID {
maxRegionID = region.RegionID
rid := int64(region.RegionID)
if rid > maxRegionID {
maxRegionID = rid
}
}
if maxRegionID < 0 {
maxRegionID = 0
}

// Round to the nearest 10,000 with a sufficient buffer of at least 2,000.
// The buffer allows for future "fixed" regions to be added to the base DERP
// map without conflicting with proxy region IDs (standard DERP maps usually
// use incrementing IDs for new regions).
//
// Example:
// maxRegionID = -2_000 -> startingRegionID = 10_000
// maxRegionID = 8_000 -> startingRegionID = 10_000
// maxRegionID = 8_500 -> startingRegionID = 20_000
// maxRegionID = 12_000 -> startingRegionID = 20_000
// maxRegionID = 20_000 -> startingRegionID = 30_000
const roundStartingRegionID = 10_000
const startingRegionIDBuffer = 2_000
// Add the buffer first.
startingRegionID := maxRegionID + startingRegionIDBuffer
startingRegionID = int(math.Ceil(float64(startingRegionID)/roundStartingRegionID) * roundStartingRegionID)
// Round UP to the nearest 10,000. Go's math.Ceil rounds up to the nearest
// integer, so we need to divide by 10,000 first and then multiply by
// 10,000.
startingRegionID = int64(math.Ceil(float64(startingRegionID)/roundStartingRegionID) * roundStartingRegionID)
// This should never be hit but it's here just in case.
if startingRegionID < roundStartingRegionID {
startingRegionID = roundStartingRegionID
}
Expand Down Expand Up @@ -565,7 +581,7 @@ func derpMapper(logger slog.Logger, proxyHealth *proxyhealth.ProxyHealth) func(*
// This should be impossible to hit as the IDs are enforced to be
// unique by the database and the computed ID is greater than any
// existing ID in the DERP map.
regionID := startingRegionID + int(status.Proxy.RegionID)
regionID := int(startingRegionID) + int(status.Proxy.RegionID)
regionCode := fmt.Sprintf("coder_%s", strings.ToLower(status.Proxy.Name))
for _, r := range derpMap.Regions {
if r.RegionID == regionID || r.RegionCode == regionCode {
Expand Down
6 changes: 5 additions & 1 deletion enterprise/coderd/workspaceproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/sha256"
"database/sql"
"flag"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -531,7 +532,10 @@ func (api *API) workspaceProxyRegister(rw http.ResponseWriter, r *http.Request)
return
}

if req.Version != buildinfo.Version() {
// Version check should be forced in non-dev builds and when running in
// tests.
shouldForceVersion := !buildinfo.IsDev() || flag.Lookup("test.v") != nil
if shouldForceVersion && req.Version != buildinfo.Version() {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Version mismatch.",
Detail: fmt.Sprintf("Proxy version %q does not match primary server version %q", req.Version, buildinfo.Version()),
Expand Down
1 change: 1 addition & 0 deletions enterprise/wsproxy/wsproxysdk/wsproxysdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ func (c *Client) RegisterWorkspaceProxyLoop(ctx context.Context, opts RegisterWo
failureFn(xerrors.Errorf("exceeded re-registration failure count of %d: last error: %w", opts.MaxFailureCount, err))
return
}
continue
}
failedAttempts = 0

Expand Down