Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66fe96f

Browse files
committed
Merge branch 'main' into openid
2 parents 42d8455 + 7076dee commit 66fe96f

File tree

93 files changed

+3730
-1834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+3730
-1834
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ jobs:
512512
- name: Install node_modules
513513
run: ./scripts/yarn_install.sh
514514

515-
- run: yarn test:ci
515+
- run: yarn test:ci --max-workers ${{ steps.cpu-cores.outputs.count }}
516516
working-directory: site
517517

518518
- uses: codecov/codecov-action@v3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ site/test-results/*
2727
site/e2e/test-results/*
2828
site/e2e/states/*.json
2929
site/playwright-report/*
30+
site/.swc
3031

3132
# Make target for updating golden files.
3233
cli/testdata/.gen-golden

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ site/test-results/*
3030
site/e2e/test-results/*
3131
site/e2e/states/*.json
3232
site/playwright-report/*
33+
site/.swc
3334

3435
# Make target for updating golden files.
3536
cli/testdata/.gen-golden

agent/agent.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type Options struct {
7878
EnvironmentVariables map[string]string
7979
Logger slog.Logger
8080
AgentPorts map[int]string
81+
SSHMaxTimeout time.Duration
8182
}
8283

8384
type Client interface {
@@ -126,6 +127,7 @@ func New(options Options) io.Closer {
126127
lifecycleReported: make(chan codersdk.WorkspaceAgentLifecycle, 1),
127128
ignorePorts: options.AgentPorts,
128129
connStatsChan: make(chan *agentsdk.Stats, 1),
130+
sshMaxTimeout: options.SSHMaxTimeout,
129131
}
130132
a.init(ctx)
131133
return a
@@ -153,9 +155,10 @@ type agent struct {
153155

154156
envVars map[string]string
155157
// metadata is atomic because values can change after reconnection.
156-
metadata atomic.Value
157-
sessionToken atomic.Pointer[string]
158-
sshServer *ssh.Server
158+
metadata atomic.Value
159+
sessionToken atomic.Pointer[string]
160+
sshServer *ssh.Server
161+
sshMaxTimeout time.Duration
159162

160163
lifecycleUpdate chan struct{}
161164
lifecycleReported chan codersdk.WorkspaceAgentLifecycle
@@ -780,6 +783,7 @@ func (a *agent) init(ctx context.Context) {
780783
_ = session.Exit(1)
781784
},
782785
},
786+
MaxTimeout: a.sshMaxTimeout,
783787
}
784788

785789
go a.runLoop(ctx)

cli/agent.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ import (
3131

3232
func workspaceAgent() *cobra.Command {
3333
var (
34-
auth string
35-
logDir string
36-
pprofAddress string
37-
noReap bool
34+
auth string
35+
logDir string
36+
pprofAddress string
37+
noReap bool
38+
sshMaxTimeout time.Duration
3839
)
3940
cmd := &cobra.Command{
4041
Use: "agent",
@@ -208,7 +209,8 @@ func workspaceAgent() *cobra.Command {
208209
EnvironmentVariables: map[string]string{
209210
"GIT_ASKPASS": executablePath,
210211
},
211-
AgentPorts: agentPorts,
212+
AgentPorts: agentPorts,
213+
SSHMaxTimeout: sshMaxTimeout,
212214
})
213215
<-ctx.Done()
214216
return closer.Close()
@@ -219,6 +221,7 @@ func workspaceAgent() *cobra.Command {
219221
cliflag.StringVarP(cmd.Flags(), &logDir, "log-dir", "", "CODER_AGENT_LOG_DIR", os.TempDir(), "Specify the location for the agent log files")
220222
cliflag.StringVarP(cmd.Flags(), &pprofAddress, "pprof-address", "", "CODER_AGENT_PPROF_ADDRESS", "127.0.0.1:6060", "The address to serve pprof.")
221223
cliflag.BoolVarP(cmd.Flags(), &noReap, "no-reap", "", "", false, "Do not start a process reaper.")
224+
cliflag.DurationVarP(cmd.Flags(), &sshMaxTimeout, "ssh-max-timeout", "", "CODER_AGENT_SSH_MAX_TIMEOUT", time.Duration(0), "Specify the max timeout for a SSH connection")
222225
return cmd
223226
}
224227

cli/testdata/coder_agent_--help.golden

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ Usage:
22
coder agent [flags]
33

44
Flags:
5-
--auth string Specify the authentication type to use for the agent.
6-
Consumes $CODER_AGENT_AUTH (default "token")
7-
-h, --help help for agent
8-
--log-dir string Specify the location for the agent log files.
9-
Consumes $CODER_AGENT_LOG_DIR (default "/tmp")
10-
--no-reap Do not start a process reaper.
11-
--pprof-address string The address to serve pprof.
12-
Consumes $CODER_AGENT_PPROF_ADDRESS (default "127.0.0.1:6060")
5+
--auth string Specify the authentication type to use for the agent.
6+
Consumes $CODER_AGENT_AUTH (default "token")
7+
-h, --help help for agent
8+
--log-dir string Specify the location for the agent log files.
9+
Consumes $CODER_AGENT_LOG_DIR (default "/tmp")
10+
--no-reap Do not start a process reaper.
11+
--pprof-address string The address to serve pprof.
12+
Consumes $CODER_AGENT_PPROF_ADDRESS (default "127.0.0.1:6060")
13+
--ssh-max-timeout duration Specify the max timeout for a SSH connection.
14+
Consumes $CODER_AGENT_SSH_MAX_TIMEOUT
1315

1416
Global Flags:
1517
--global-config coder Path to the global coder config directory.

coderd/apidoc/docs.go

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

coderd/coderd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ func New(options *Options) *API {
175175
if options.AgentInactiveDisconnectTimeout == 0 {
176176
// Multiply the update by two to allow for some lag-time.
177177
options.AgentInactiveDisconnectTimeout = options.AgentConnectionUpdateFrequency * 2
178+
// Set a minimum timeout to avoid disconnecting too soon.
179+
if options.AgentInactiveDisconnectTimeout < 2*time.Second {
180+
options.AgentInactiveDisconnectTimeout = 2 * time.Second
181+
}
178182
}
179183
if options.AgentStatsRefreshInterval == 0 {
180184
options.AgentStatsRefreshInterval = 5 * time.Minute

coderd/coderdtest/coderdtest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
258258
stunAddr, stunCleanup := stuntest.ServeWithPacketListener(t, nettype.Std{})
259259
t.Cleanup(stunCleanup)
260260

261-
derpServer := derp.NewServer(key.NewNode(), tailnet.Logger(slogtest.Make(t, nil).Named("derp")))
261+
derpServer := derp.NewServer(key.NewNode(), tailnet.Logger(slogtest.Make(t, nil).Named("derp").Leveled(slog.LevelDebug)))
262262
derpServer.SetMeshKey("test-key")
263263

264264
// match default with cli default

coderd/database/dbauthz/system.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ func (q *querier) GetDeploymentWorkspaceAgentStats(ctx context.Context, createdA
284284
return q.db.GetDeploymentWorkspaceAgentStats(ctx, createdAfter)
285285
}
286286

287+
func (q *querier) GetWorkspaceAgentStats(ctx context.Context, createdAfter time.Time) ([]database.GetWorkspaceAgentStatsRow, error) {
288+
return q.db.GetWorkspaceAgentStats(ctx, createdAfter)
289+
}
290+
287291
func (q *querier) GetDeploymentWorkspaceStats(ctx context.Context) (database.GetDeploymentWorkspaceStatsRow, error) {
288292
return q.db.GetDeploymentWorkspaceStats(ctx)
289293
}

coderd/database/dbfake/databasefake.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,7 @@ func (q *fakeQuerier) InsertTemplateVersionParameter(_ context.Context, arg data
28262826
ValidationMax: arg.ValidationMax,
28272827
ValidationMonotonic: arg.ValidationMonotonic,
28282828
Required: arg.Required,
2829+
LegacyVariableName: arg.LegacyVariableName,
28292830
}
28302831
q.templateVersionParameters = append(q.templateVersionParameters, param)
28312832
return param, nil
@@ -3707,6 +3708,79 @@ func (q *fakeQuerier) GetDeploymentWorkspaceStats(ctx context.Context) (database
37073708
return stat, nil
37083709
}
37093710

3711+
func (q *fakeQuerier) GetWorkspaceAgentStats(_ context.Context, createdAfter time.Time) ([]database.GetWorkspaceAgentStatsRow, error) {
3712+
q.mutex.RLock()
3713+
defer q.mutex.RUnlock()
3714+
3715+
agentStatsCreatedAfter := make([]database.WorkspaceAgentStat, 0)
3716+
for _, agentStat := range q.workspaceAgentStats {
3717+
if agentStat.CreatedAt.After(createdAfter) {
3718+
agentStatsCreatedAfter = append(agentStatsCreatedAfter, agentStat)
3719+
}
3720+
}
3721+
3722+
latestAgentStats := map[uuid.UUID]database.WorkspaceAgentStat{}
3723+
for _, agentStat := range q.workspaceAgentStats {
3724+
if agentStat.CreatedAt.After(createdAfter) {
3725+
latestAgentStats[agentStat.AgentID] = agentStat
3726+
}
3727+
}
3728+
3729+
statByAgent := map[uuid.UUID]database.GetWorkspaceAgentStatsRow{}
3730+
for _, agentStat := range latestAgentStats {
3731+
stat := statByAgent[agentStat.AgentID]
3732+
stat.SessionCountVSCode += agentStat.SessionCountVSCode
3733+
stat.SessionCountJetBrains += agentStat.SessionCountJetBrains
3734+
stat.SessionCountReconnectingPTY += agentStat.SessionCountReconnectingPTY
3735+
stat.SessionCountSSH += agentStat.SessionCountSSH
3736+
statByAgent[stat.AgentID] = stat
3737+
}
3738+
3739+
latenciesByAgent := map[uuid.UUID][]float64{}
3740+
minimumDateByAgent := map[uuid.UUID]time.Time{}
3741+
for _, agentStat := range agentStatsCreatedAfter {
3742+
if agentStat.ConnectionMedianLatencyMS <= 0 {
3743+
continue
3744+
}
3745+
stat := statByAgent[agentStat.AgentID]
3746+
minimumDate := minimumDateByAgent[agentStat.AgentID]
3747+
if agentStat.CreatedAt.Before(minimumDate) || minimumDate.IsZero() {
3748+
minimumDateByAgent[agentStat.AgentID] = agentStat.CreatedAt
3749+
}
3750+
stat.WorkspaceRxBytes += agentStat.RxBytes
3751+
stat.WorkspaceTxBytes += agentStat.TxBytes
3752+
statByAgent[agentStat.AgentID] = stat
3753+
latenciesByAgent[agentStat.AgentID] = append(latenciesByAgent[agentStat.AgentID], agentStat.ConnectionMedianLatencyMS)
3754+
}
3755+
3756+
tryPercentile := func(fs []float64, p float64) float64 {
3757+
if len(fs) == 0 {
3758+
return -1
3759+
}
3760+
sort.Float64s(fs)
3761+
return fs[int(float64(len(fs))*p/100)]
3762+
}
3763+
3764+
for _, stat := range statByAgent {
3765+
stat.AggregatedFrom = minimumDateByAgent[stat.AgentID]
3766+
statByAgent[stat.AgentID] = stat
3767+
3768+
latencies, ok := latenciesByAgent[stat.AgentID]
3769+
if !ok {
3770+
continue
3771+
}
3772+
stat.WorkspaceConnectionLatency50 = tryPercentile(latencies, 50)
3773+
stat.WorkspaceConnectionLatency95 = tryPercentile(latencies, 95)
3774+
statByAgent[stat.AgentID] = stat
3775+
}
3776+
3777+
stats := make([]database.GetWorkspaceAgentStatsRow, 0, len(statByAgent))
3778+
for _, agent := range statByAgent {
3779+
stats = append(stats, agent)
3780+
}
3781+
return stats, nil
3782+
}
3783+
37103784
func (q *fakeQuerier) UpdateWorkspaceTTLToBeWithinTemplateMax(_ context.Context, arg database.UpdateWorkspaceTTLToBeWithinTemplateMaxParams) error {
37113785
if err := validateDatabaseType(arg); err != nil {
37123786
return err

coderd/database/dump.sql

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE template_version_parameters DROP COLUMN legacy_variable_name;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE template_version_parameters ADD COLUMN legacy_variable_name text NOT NULL DEFAULT '';
2+
3+
COMMENT ON COLUMN template_version_parameters.legacy_variable_name IS 'Name of the legacy variable for migration purposes';

coderd/database/models.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/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.

0 commit comments

Comments
 (0)