mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
chore: upgrade tailscale to v1.46.1 (#8913)
This commit is contained in:
26
coderd/apidoc/docs.go
generated
26
coderd/apidoc/docs.go
generated
@ -11543,11 +11543,31 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"tailcfg.DERPHomeParams": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"regionScore": {
|
||||
"description": "RegionScore scales latencies of DERP regions by a given scaling\nfactor when determining which region to use as the home\n(\"preferred\") DERP. Scores in the range (0, 1) will cause this\nregion to be proportionally more preferred, and scores in the range\n(1, ∞) will penalize a region.\n\nIf a region is not present in this map, it is treated as having a\nscore of 1.0.\n\nScores should not be 0 or negative; such scores will be ignored.\n\nA nil map means no change from the previous value (if any); an empty\nnon-nil map can be sent to reset all scores back to 1.0.",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tailcfg.DERPMap": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"homeParams": {
|
||||
"description": "HomeParams, if non-nil, is a change in home parameters.\n\nThe rest of the DEPRMap fields, if zero, means unchanged.",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/tailcfg.DERPHomeParams"
|
||||
}
|
||||
]
|
||||
},
|
||||
"omitDefaultRegions": {
|
||||
"description": "OmitDefaultRegions specifies to not use Tailscale's DERP servers, and only use those\nspecified in this DERPMap. If there are none set outside of the defaults, this is a noop.",
|
||||
"description": "OmitDefaultRegions specifies to not use Tailscale's DERP servers, and only use those\nspecified in this DERPMap. If there are none set outside of the defaults, this is a noop.\n\nThis field is only meaningful if the Regions map is non-nil (indicating a change).",
|
||||
"type": "boolean"
|
||||
},
|
||||
"regions": {
|
||||
@ -11562,6 +11582,10 @@ const docTemplate = `{
|
||||
"tailcfg.DERPNode": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"canPort80": {
|
||||
"description": "CanPort80 specifies whether this DERP node is accessible over HTTP\non port 80 specifically. This is used for captive portal checks.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"certName": {
|
||||
"description": "CertName optionally specifies the expected TLS cert common\nname. If empty, HostName is used. If CertName is non-empty,\nHostName is only used for the TCP dial (if IPv4/IPv6 are\nnot present) + TLS ClientHello.",
|
||||
"type": "string"
|
||||
|
26
coderd/apidoc/swagger.json
generated
26
coderd/apidoc/swagger.json
generated
@ -10521,11 +10521,31 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"tailcfg.DERPHomeParams": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"regionScore": {
|
||||
"description": "RegionScore scales latencies of DERP regions by a given scaling\nfactor when determining which region to use as the home\n(\"preferred\") DERP. Scores in the range (0, 1) will cause this\nregion to be proportionally more preferred, and scores in the range\n(1, ∞) will penalize a region.\n\nIf a region is not present in this map, it is treated as having a\nscore of 1.0.\n\nScores should not be 0 or negative; such scores will be ignored.\n\nA nil map means no change from the previous value (if any); an empty\nnon-nil map can be sent to reset all scores back to 1.0.",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tailcfg.DERPMap": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"homeParams": {
|
||||
"description": "HomeParams, if non-nil, is a change in home parameters.\n\nThe rest of the DEPRMap fields, if zero, means unchanged.",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/tailcfg.DERPHomeParams"
|
||||
}
|
||||
]
|
||||
},
|
||||
"omitDefaultRegions": {
|
||||
"description": "OmitDefaultRegions specifies to not use Tailscale's DERP servers, and only use those\nspecified in this DERPMap. If there are none set outside of the defaults, this is a noop.",
|
||||
"description": "OmitDefaultRegions specifies to not use Tailscale's DERP servers, and only use those\nspecified in this DERPMap. If there are none set outside of the defaults, this is a noop.\n\nThis field is only meaningful if the Regions map is non-nil (indicating a change).",
|
||||
"type": "boolean"
|
||||
},
|
||||
"regions": {
|
||||
@ -10540,6 +10560,10 @@
|
||||
"tailcfg.DERPNode": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"canPort80": {
|
||||
"description": "CanPort80 specifies whether this DERP node is accessible over HTTP\non port 80 specifically. This is used for captive portal checks.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"certName": {
|
||||
"description": "CertName optionally specifies the expected TLS cert common\nname. If empty, HostName is used. If CertName is non-empty,\nHostName is only used for the TCP dial (if IPv4/IPv6 are\nnot present) + TLS ClientHello.",
|
||||
"type": "string"
|
||||
|
@ -605,8 +605,8 @@ func uniqueSortedUUIDs(uuids []uuid.UUID) []uuid.UUID {
|
||||
for id := range set {
|
||||
unique = append(unique, id)
|
||||
}
|
||||
slices.SortFunc(unique, func(a, b uuid.UUID) bool {
|
||||
return a.String() < b.String()
|
||||
slices.SortFunc(unique, func(a, b uuid.UUID) int {
|
||||
return slice.Ascending(a.String(), b.String())
|
||||
})
|
||||
return unique
|
||||
}
|
||||
@ -2060,8 +2060,8 @@ func (q *FakeQuerier) GetTemplateDailyInsights(_ context.Context, arg database.G
|
||||
for templateID := range ds.templateIDSet {
|
||||
templateIDs = append(templateIDs, templateID)
|
||||
}
|
||||
slices.SortFunc(templateIDs, func(a, b uuid.UUID) bool {
|
||||
return a.String() < b.String()
|
||||
slices.SortFunc(templateIDs, func(a, b uuid.UUID) int {
|
||||
return slice.Ascending(a.String(), b.String())
|
||||
})
|
||||
result = append(result, database.GetTemplateDailyInsightsRow{
|
||||
StartTime: ds.startTime,
|
||||
@ -2119,8 +2119,8 @@ func (q *FakeQuerier) GetTemplateInsights(_ context.Context, arg database.GetTem
|
||||
for templateID := range templateIDSet {
|
||||
templateIDs = append(templateIDs, templateID)
|
||||
}
|
||||
slices.SortFunc(templateIDs, func(a, b uuid.UUID) bool {
|
||||
return a.String() < b.String()
|
||||
slices.SortFunc(templateIDs, func(a, b uuid.UUID) int {
|
||||
return slice.Ascending(a.String(), b.String())
|
||||
})
|
||||
result := database.GetTemplateInsightsRow{
|
||||
TemplateIDs: templateIDs,
|
||||
@ -2343,13 +2343,16 @@ func (q *FakeQuerier) GetTemplateVersionsByTemplateID(_ context.Context, arg dat
|
||||
}
|
||||
|
||||
// Database orders by created_at
|
||||
slices.SortFunc(version, func(a, b database.TemplateVersion) bool {
|
||||
slices.SortFunc(version, func(a, b database.TemplateVersion) int {
|
||||
if a.CreatedAt.Equal(b.CreatedAt) {
|
||||
// Technically the postgres database also orders by uuid. So match
|
||||
// that behavior
|
||||
return a.ID.String() < b.ID.String()
|
||||
return slice.Ascending(a.ID.String(), b.ID.String())
|
||||
}
|
||||
return a.CreatedAt.Before(b.CreatedAt)
|
||||
if a.CreatedAt.Before(b.CreatedAt) {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
})
|
||||
|
||||
if arg.AfterID != uuid.Nil {
|
||||
@ -2408,11 +2411,11 @@ func (q *FakeQuerier) GetTemplates(_ context.Context) ([]database.Template, erro
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
templates := slices.Clone(q.templates)
|
||||
slices.SortFunc(templates, func(i, j database.TemplateTable) bool {
|
||||
if i.Name != j.Name {
|
||||
return i.Name < j.Name
|
||||
slices.SortFunc(templates, func(a, b database.TemplateTable) int {
|
||||
if a.Name != b.Name {
|
||||
return slice.Ascending(a.Name, b.Name)
|
||||
}
|
||||
return i.ID.String() < j.ID.String()
|
||||
return slice.Ascending(a.ID.String(), b.ID.String())
|
||||
})
|
||||
|
||||
return q.templatesWithUserNoLock(templates), nil
|
||||
@ -2525,8 +2528,8 @@ func (q *FakeQuerier) GetUserLatencyInsights(_ context.Context, arg database.Get
|
||||
for templateID := range templateIDSet {
|
||||
templateIDs = append(templateIDs, templateID)
|
||||
}
|
||||
slices.SortFunc(templateIDs, func(a, b uuid.UUID) bool {
|
||||
return a.String() < b.String()
|
||||
slices.SortFunc(templateIDs, func(a, b uuid.UUID) int {
|
||||
return slice.Ascending(a.String(), b.String())
|
||||
})
|
||||
user, err := q.getUserByIDNoLock(userID)
|
||||
if err != nil {
|
||||
@ -2542,8 +2545,8 @@ func (q *FakeQuerier) GetUserLatencyInsights(_ context.Context, arg database.Get
|
||||
}
|
||||
rows = append(rows, row)
|
||||
}
|
||||
slices.SortFunc(rows, func(a, b database.GetUserLatencyInsightsRow) bool {
|
||||
return a.UserID.String() < b.UserID.String()
|
||||
slices.SortFunc(rows, func(a, b database.GetUserLatencyInsightsRow) int {
|
||||
return slice.Ascending(a.UserID.String(), b.UserID.String())
|
||||
})
|
||||
|
||||
return rows, nil
|
||||
@ -2590,8 +2593,8 @@ func (q *FakeQuerier) GetUsers(_ context.Context, params database.GetUsersParams
|
||||
copy(users, q.users)
|
||||
|
||||
// Database orders by username
|
||||
slices.SortFunc(users, func(a, b database.User) bool {
|
||||
return strings.ToLower(a.Username) < strings.ToLower(b.Username)
|
||||
slices.SortFunc(users, func(a, b database.User) int {
|
||||
return slice.Ascending(strings.ToLower(a.Username), strings.ToLower(b.Username))
|
||||
})
|
||||
|
||||
// Filter out deleted since they should never be returned..
|
||||
@ -2799,14 +2802,14 @@ func (q *FakeQuerier) GetWorkspaceAgentStats(_ context.Context, createdAfter tim
|
||||
|
||||
agentStatsCreatedAfter := make([]database.WorkspaceAgentStat, 0)
|
||||
for _, agentStat := range q.workspaceAgentStats {
|
||||
if agentStat.CreatedAt.After(createdAfter) {
|
||||
if agentStat.CreatedAt.After(createdAfter) || agentStat.CreatedAt.Equal(createdAfter) {
|
||||
agentStatsCreatedAfter = append(agentStatsCreatedAfter, agentStat)
|
||||
}
|
||||
}
|
||||
|
||||
latestAgentStats := map[uuid.UUID]database.WorkspaceAgentStat{}
|
||||
for _, agentStat := range q.workspaceAgentStats {
|
||||
if agentStat.CreatedAt.After(createdAfter) {
|
||||
if agentStat.CreatedAt.After(createdAfter) || agentStat.CreatedAt.Equal(createdAfter) {
|
||||
latestAgentStats[agentStat.AgentID] = agentStat
|
||||
}
|
||||
}
|
||||
@ -3132,9 +3135,8 @@ func (q *FakeQuerier) GetWorkspaceBuildsByWorkspaceID(_ context.Context,
|
||||
}
|
||||
|
||||
// Order by build_number
|
||||
slices.SortFunc(history, func(a, b database.WorkspaceBuild) bool {
|
||||
// use greater than since we want descending order
|
||||
return a.BuildNumber > b.BuildNumber
|
||||
slices.SortFunc(history, func(a, b database.WorkspaceBuild) int {
|
||||
return slice.Descending(a.BuildNumber, b.BuildNumber)
|
||||
})
|
||||
|
||||
if params.AfterID != uuid.Nil {
|
||||
@ -3533,8 +3535,14 @@ func (q *FakeQuerier) InsertAuditLog(_ context.Context, arg database.InsertAudit
|
||||
alog := database.AuditLog(arg)
|
||||
|
||||
q.auditLogs = append(q.auditLogs, alog)
|
||||
slices.SortFunc(q.auditLogs, func(a, b database.AuditLog) bool {
|
||||
return a.Time.Before(b.Time)
|
||||
slices.SortFunc(q.auditLogs, func(a, b database.AuditLog) int {
|
||||
if a.Time.Before(b.Time) {
|
||||
return -1
|
||||
} else if a.Time.Equal(b.Time) {
|
||||
return 0
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
})
|
||||
|
||||
return alog, nil
|
||||
@ -5588,11 +5596,11 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G
|
||||
templates = append(templates, template)
|
||||
}
|
||||
if len(templates) > 0 {
|
||||
slices.SortFunc(templates, func(i, j database.Template) bool {
|
||||
if i.Name != j.Name {
|
||||
return i.Name < j.Name
|
||||
slices.SortFunc(templates, func(a, b database.Template) int {
|
||||
if a.Name != b.Name {
|
||||
return slice.Ascending(a.Name, b.Name)
|
||||
}
|
||||
return i.ID.String() < j.ID.String()
|
||||
return slice.Ascending(a.ID.String(), b.ID.String())
|
||||
})
|
||||
return templates, nil
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/coderd/util/slice"
|
||||
"github.com/coder/coder/cryptorand"
|
||||
)
|
||||
|
||||
@ -115,8 +116,8 @@ func FindClosestNode(nodes []Node) (Node, error) {
|
||||
return Node{}, err
|
||||
}
|
||||
|
||||
slices.SortFunc(nodes, func(i, j Node) bool {
|
||||
return i.AvgLatency < j.AvgLatency
|
||||
slices.SortFunc(nodes, func(a, b Node) int {
|
||||
return slice.Ascending(a.AvgLatency, b.AvgLatency)
|
||||
})
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func (r *DERPReport) Run(ctx context.Context, opts *DERPReportOptions) {
|
||||
mu.Unlock()
|
||||
}
|
||||
nc := &netcheck.Client{
|
||||
PortMapper: portmapper.NewClient(tslogger.WithPrefix(ncLogf, "portmap: "), nil),
|
||||
PortMapper: portmapper.NewClient(tslogger.WithPrefix(ncLogf, "portmap: "), nil, nil, nil),
|
||||
Logf: tslogger.WithPrefix(ncLogf, "netcheck: "),
|
||||
}
|
||||
ncReport, netcheckErr := nc.GetReport(ctx, opts.DERPMap)
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/coder/coder/coderd/database/db2sdk"
|
||||
"github.com/coder/coder/coderd/httpapi"
|
||||
"github.com/coder/coder/coderd/rbac"
|
||||
"github.com/coder/coder/coderd/util/slice"
|
||||
"github.com/coder/coder/codersdk"
|
||||
)
|
||||
|
||||
@ -131,8 +132,8 @@ func (api *API) insightsUserLatency(rw http.ResponseWriter, r *http.Request) {
|
||||
for templateID := range templateIDSet {
|
||||
seenTemplateIDs = append(seenTemplateIDs, templateID)
|
||||
}
|
||||
slices.SortFunc(seenTemplateIDs, func(a, b uuid.UUID) bool {
|
||||
return a.String() < b.String()
|
||||
slices.SortFunc(seenTemplateIDs, func(a, b uuid.UUID) int {
|
||||
return slice.Ascending(a.String(), b.String())
|
||||
})
|
||||
|
||||
resp := codersdk.UserLatencyInsightsResponse{
|
||||
|
@ -146,8 +146,14 @@ func convertDAUResponse[T dauRow](rows []T, tzOffset int) codersdk.DAUsResponse
|
||||
}
|
||||
|
||||
dates := maps.Keys(respMap)
|
||||
slices.SortFunc(dates, func(a, b time.Time) bool {
|
||||
return a.Before(b)
|
||||
slices.SortFunc(dates, func(a, b time.Time) int {
|
||||
if a.Before(b) {
|
||||
return -1
|
||||
} else if a.Equal(b) {
|
||||
return 0
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
})
|
||||
|
||||
var resp codersdk.DAUsResponse
|
||||
|
@ -115,11 +115,11 @@ func TestCollector_Set_Add(t *testing.T) {
|
||||
assert.Equal(t, 6, int(metrics[1].Gauge.GetValue())) // Metric value
|
||||
}
|
||||
|
||||
func collectAndSortMetrics(t *testing.T, collector prometheus.Collector, count int) []dto.Metric {
|
||||
func collectAndSortMetrics(t *testing.T, collector prometheus.Collector, count int) []*dto.Metric {
|
||||
ch := make(chan prometheus.Metric, count)
|
||||
defer close(ch)
|
||||
|
||||
var metrics []dto.Metric
|
||||
var metrics []*dto.Metric
|
||||
|
||||
collector.Collect(ch)
|
||||
for i := 0; i < count; i++ {
|
||||
@ -129,7 +129,7 @@ func collectAndSortMetrics(t *testing.T, collector prometheus.Collector, count i
|
||||
err := m.Write(&metric)
|
||||
require.NoError(t, err)
|
||||
|
||||
metrics = append(metrics, metric)
|
||||
metrics = append(metrics, &metric)
|
||||
}
|
||||
|
||||
// Ensure always the same order of metrics
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@ -12,6 +11,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/exp/slices"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/coder/coder/cli/clibase"
|
||||
@ -20,6 +20,7 @@ import (
|
||||
"github.com/coder/coder/coderd/database"
|
||||
"github.com/coder/coder/coderd/database/dbauthz"
|
||||
"github.com/coder/coder/coderd/rbac"
|
||||
"github.com/coder/coder/coderd/util/slice"
|
||||
"github.com/coder/coder/codersdk"
|
||||
"github.com/coder/coder/testutil"
|
||||
)
|
||||
@ -1804,8 +1805,8 @@ func assertPagination(ctx context.Context, t *testing.T, client *codersdk.Client
|
||||
|
||||
// sortUsers sorts by (created_at, id)
|
||||
func sortUsers(users []codersdk.User) {
|
||||
sort.Slice(users, func(i, j int) bool {
|
||||
return strings.ToLower(users[i].Username) < strings.ToLower(users[j].Username)
|
||||
slices.SortFunc(users, func(a, b codersdk.User) int {
|
||||
return slice.Ascending(strings.ToLower(a.Username), strings.ToLower(b.Username))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
package slice
|
||||
|
||||
import (
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
// SameElements returns true if the 2 lists have the same elements in any
|
||||
// order.
|
||||
func SameElements[T comparable](a []T, b []T) bool {
|
||||
@ -69,3 +73,17 @@ func OverlapCompare[T any](a []T, b []T, equal func(a, b T) bool) bool {
|
||||
func New[T any](items ...T) []T {
|
||||
return items
|
||||
}
|
||||
|
||||
func Ascending[T constraints.Ordered](a, b T) int {
|
||||
if a < b {
|
||||
return -1
|
||||
} else if a == b {
|
||||
return 0
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
func Descending[T constraints.Ordered](a, b T) int {
|
||||
return -Ascending[T](a, b)
|
||||
}
|
||||
|
@ -107,3 +107,19 @@ func assertSetContains[T comparable](t *testing.T, set []T, in []T, out []T) {
|
||||
require.False(t, slice.Contains(set, e), "expect element in set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAscending(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, -1, slice.Ascending(1, 2))
|
||||
assert.Equal(t, 0, slice.Ascending(1, 1))
|
||||
assert.Equal(t, 1, slice.Ascending(2, 1))
|
||||
}
|
||||
|
||||
func TestDescending(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, 1, slice.Descending(1, 2))
|
||||
assert.Equal(t, 0, slice.Descending(1, 1))
|
||||
assert.Equal(t, -1, slice.Descending(2, 1))
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import (
|
||||
"github.com/coder/coder/coderd/httpmw"
|
||||
"github.com/coder/coder/coderd/rbac"
|
||||
"github.com/coder/coder/coderd/util/ptr"
|
||||
"github.com/coder/coder/coderd/util/slice"
|
||||
"github.com/coder/coder/codersdk"
|
||||
"github.com/coder/coder/codersdk/agentsdk"
|
||||
"github.com/coder/coder/tailnet"
|
||||
@ -1616,8 +1617,8 @@ func (api *API) watchWorkspaceAgentMetadata(rw http.ResponseWriter, r *http.Requ
|
||||
})
|
||||
return
|
||||
}
|
||||
slices.SortFunc(lastDBMeta, func(i, j database.WorkspaceAgentMetadatum) bool {
|
||||
return i.Key < j.Key
|
||||
slices.SortFunc(lastDBMeta, func(a, b database.WorkspaceAgentMetadatum) int {
|
||||
return slice.Ascending(a.Key, b.Key)
|
||||
})
|
||||
|
||||
// Avoid sending refresh if the client is about to get a
|
||||
|
Reference in New Issue
Block a user