Skip to content

Commit 88cf939

Browse files
committed
Merge branch 'main' into 9983-license-prometheus-2
2 parents 366f33a + 1e75762 commit 88cf939

File tree

200 files changed

+4898
-2398
lines changed

Some content is hidden

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

200 files changed

+4898
-2398
lines changed

.github/actions/setup-go/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: |
44
inputs:
55
version:
66
description: "The Go version to use."
7-
default: "1.20.8"
7+
default: "1.20.10"
88
runs:
99
using: "composite"
1010
steps:

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ jobs:
220220
with:
221221
# This doesn't need caching. It's super fast anyways!
222222
cache: false
223-
go-version: 1.20.8
223+
go-version: 1.20.10
224224

225225
- name: Install shfmt
226226
run: go install mvdan.cc/sh/v3/cmd/shfmt@v3.5.0

agent/agent.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,11 +1290,7 @@ func (a *agent) manageProcessPriority(ctx context.Context) ([]*agentproc.Process
12901290
// Getpriority actually returns priority for the nice value
12911291
// which is niceness + 20, so here 20 = a niceness of 0 (aka unset).
12921292
if score != 20 {
1293-
if score != niceness {
1294-
logger.Debug(ctx, "skipping process due to custom niceness",
1295-
slog.F("niceness", score),
1296-
)
1297-
}
1293+
// We don't log here since it can get spammy
12981294
continue
12991295
}
13001296

agent/agent_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,11 +1544,13 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
15441544
_, err := exec.LookPath("screen")
15451545
hasScreen := err == nil
15461546

1547+
// Make sure UTF-8 works even with LANG set to something like C.
1548+
t.Setenv("LANG", "C")
1549+
15471550
for _, backendType := range backends {
15481551
backendType := backendType
15491552
t.Run(backendType, func(t *testing.T) {
15501553
if backendType == "Screen" {
1551-
t.Parallel()
15521554
if runtime.GOOS != "linux" {
15531555
t.Skipf("`screen` is not supported on %s", runtime.GOOS)
15541556
} else if !hasScreen {
@@ -1563,8 +1565,6 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
15631565
err = os.Symlink(bashPath, filepath.Join(dir, "bash"))
15641566
require.NoError(t, err, "symlink bash into reconnecting pty PATH")
15651567
t.Setenv("PATH", dir)
1566-
} else {
1567-
t.Parallel()
15681568
}
15691569

15701570
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
@@ -1656,6 +1656,17 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16561656
tr4 := testutil.NewTerminalReader(t, netConn4)
16571657
require.NoError(t, tr4.ReadUntil(ctx, matchEchoOutput), "find echo output")
16581658
require.ErrorIs(t, tr4.ReadUntil(ctx, nil), io.EOF)
1659+
1660+
// Ensure that UTF-8 is supported. Avoid the terminal emulator because it
1661+
// does not appear to support UTF-8, just make sure the bytes that come
1662+
// back have the character in it.
1663+
netConn5, err := conn.ReconnectingPTY(ctx, uuid.New(), 80, 80, "echo ❯")
1664+
require.NoError(t, err)
1665+
defer netConn5.Close()
1666+
1667+
bytes, err := io.ReadAll(netConn5)
1668+
require.NoError(t, err)
1669+
require.Contains(t, string(bytes), "❯")
16591670
})
16601671
}
16611672
}

agent/reconnectingpty/screen.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ func (rpty *screenReconnectingPTY) doAttach(ctx context.Context, conn net.Conn,
206206
cmd := pty.CommandContext(ctx, "screen", append([]string{
207207
// -S is for setting the session's name.
208208
"-S", rpty.id,
209+
// -U tells screen to use UTF-8 encoding.
209210
// -x allows attaching to an already attached session.
210211
// -RR reattaches to the daemon or creates the session daemon if missing.
211212
// -q disables the "New screen..." message that appears for five seconds
212213
// when creating a new session with -RR.
213214
// -c is the flag for the config file.
214-
"-xRRqc", rpty.configFile,
215+
"-UxRRqc", rpty.configFile,
215216
rpty.command.Path,
216217
// pty.Cmd duplicates Path as the first argument so remove it.
217218
}, rpty.command.Args[1:]...)...)

cli/exp_scaletest.go

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
503503
count int64
504504
template string
505505

506-
noPlan bool
507506
noCleanup bool
508507
// TODO: implement this flag
509508
// noCleanupFailures bool
@@ -594,10 +593,6 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
594593
if tpl.ID == uuid.Nil {
595594
return xerrors.Errorf("could not find template %q in any organization", template)
596595
}
597-
templateVersion, err := client.TemplateVersion(ctx, tpl.ActiveVersionID)
598-
if err != nil {
599-
return xerrors.Errorf("get template version %q: %w", tpl.ActiveVersionID, err)
600-
}
601596

602597
cliRichParameters, err := asWorkspaceBuildParameters(parameterFlags.richParameters)
603598
if err != nil {
@@ -607,7 +602,7 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
607602
richParameters, err := prepWorkspaceBuild(inv, client, prepWorkspaceBuildArgs{
608603
Action: WorkspaceCreate,
609604
Template: tpl,
610-
NewWorkspaceName: "scaletest-%", // TODO: the scaletest runner will pass in a different name here. Does this matter?
605+
NewWorkspaceName: "scaletest-N", // TODO: the scaletest runner will pass in a different name here. Does this matter?
611606

612607
RichParameterFile: parameterFlags.richParameterFile,
613608
RichParameters: cliRichParameters,
@@ -616,35 +611,6 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
616611
return xerrors.Errorf("prepare build: %w", err)
617612
}
618613

619-
// Do a dry-run to ensure the template and parameters are valid
620-
// before we start creating users and workspaces.
621-
if !noPlan {
622-
dryRun, err := client.CreateTemplateVersionDryRun(ctx, templateVersion.ID, codersdk.CreateTemplateVersionDryRunRequest{
623-
WorkspaceName: "scaletest",
624-
RichParameterValues: richParameters,
625-
})
626-
if err != nil {
627-
return xerrors.Errorf("start dry run workspace creation: %w", err)
628-
}
629-
_, _ = fmt.Fprintln(inv.Stdout, "Planning workspace...")
630-
err = cliui.ProvisionerJob(inv.Context(), inv.Stdout, cliui.ProvisionerJobOptions{
631-
Fetch: func() (codersdk.ProvisionerJob, error) {
632-
return client.TemplateVersionDryRun(inv.Context(), templateVersion.ID, dryRun.ID)
633-
},
634-
Cancel: func() error {
635-
return client.CancelTemplateVersionDryRun(inv.Context(), templateVersion.ID, dryRun.ID)
636-
},
637-
Logs: func() (<-chan codersdk.ProvisionerJobLog, io.Closer, error) {
638-
return client.TemplateVersionDryRunLogsAfter(inv.Context(), templateVersion.ID, dryRun.ID, 0)
639-
},
640-
// Don't show log output for the dry-run unless there's an error.
641-
Silent: true,
642-
})
643-
if err != nil {
644-
return xerrors.Errorf("dry-run workspace: %w", err)
645-
}
646-
}
647-
648614
tracerProvider, closeTracing, tracingEnabled, err := tracingFlags.provider(ctx)
649615
if err != nil {
650616
return xerrors.Errorf("create tracer provider: %w", err)
@@ -793,12 +759,6 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
793759
Description: "Required: Name or ID of the template to use for workspaces.",
794760
Value: clibase.StringOf(&template),
795761
},
796-
{
797-
Flag: "no-plan",
798-
Env: "CODER_SCALETEST_NO_PLAN",
799-
Description: `Skip the dry-run step to plan the workspace creation. This step ensures that the given parameters are valid for the given template.`,
800-
Value: clibase.BoolOf(&noPlan),
801-
},
802762
{
803763
Flag: "no-cleanup",
804764
Env: "CODER_SCALETEST_NO_CLEANUP",
@@ -1099,6 +1059,9 @@ func (r *RootCmd) scaletestDashboard() *clibase.Cmd {
10991059
}
11001060
ctx := inv.Context()
11011061
logger := slog.Make(sloghuman.Sink(inv.Stdout)).Leveled(slog.LevelInfo)
1062+
if r.verbose {
1063+
logger = logger.Leveled(slog.LevelDebug)
1064+
}
11021065
tracerProvider, closeTracing, tracingEnabled, err := tracingFlags.provider(ctx)
11031066
if err != nil {
11041067
return xerrors.Errorf("create tracer provider: %w", err)
@@ -1148,17 +1111,22 @@ func (r *RootCmd) scaletestDashboard() *clibase.Cmd {
11481111
userClient.SetSessionToken(userTokResp.Key)
11491112

11501113
config := dashboard.Config{
1151-
Interval: interval,
1152-
Jitter: jitter,
1153-
Trace: tracingEnabled,
1154-
Logger: logger.Named(name),
1155-
Headless: headless,
1156-
ActionFunc: dashboard.ClickRandomElement,
1157-
RandIntn: rndGen.Intn,
1114+
Interval: interval,
1115+
Jitter: jitter,
1116+
Trace: tracingEnabled,
1117+
Logger: logger.Named(name),
1118+
Headless: headless,
1119+
RandIntn: rndGen.Intn,
1120+
}
1121+
// Only take a screenshot if we're in verbose mode.
1122+
// This could be useful for debugging, but it will blow up the disk.
1123+
if r.verbose {
1124+
config.Screenshot = dashboard.Screenshot
11581125
}
11591126
//nolint:gocritic
1160-
logger.Info(ctx, "runner config", slog.F("min_wait", interval), slog.F("max_wait", jitter), slog.F("headless", headless), slog.F("trace", tracingEnabled))
1127+
logger.Info(ctx, "runner config", slog.F("interval", interval), slog.F("jitter", jitter), slog.F("headless", headless), slog.F("trace", tracingEnabled))
11611128
if err := config.Validate(); err != nil {
1129+
logger.Fatal(ctx, "validate config", slog.Error(err))
11621130
return err
11631131
}
11641132
var runner harness.Runnable = dashboard.NewRunner(userClient, metrics, config)
@@ -1200,14 +1168,14 @@ func (r *RootCmd) scaletestDashboard() *clibase.Cmd {
12001168
{
12011169
Flag: "interval",
12021170
Env: "CODER_SCALETEST_DASHBOARD_INTERVAL",
1203-
Default: "3s",
1171+
Default: "10s",
12041172
Description: "Interval between actions.",
12051173
Value: clibase.DurationOf(&interval),
12061174
},
12071175
{
12081176
Flag: "jitter",
12091177
Env: "CODER_SCALETEST_DASHBOARD_JITTER",
1210-
Default: "2s",
1178+
Default: "5s",
12111179
Description: "Jitter between actions.",
12121180
Value: clibase.DurationOf(&jitter),
12131181
},

cli/root.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,18 @@ func (r *RootCmd) checkWarnings(i *clibase.Invocation, client *codersdk.Client)
836836
ctx, cancel := context.WithTimeout(i.Context(), 10*time.Second)
837837
defer cancel()
838838

839+
user, err := client.User(ctx, codersdk.Me)
840+
if err != nil {
841+
return xerrors.Errorf("get user me: %w", err)
842+
}
843+
839844
entitlements, err := client.Entitlements(ctx)
840845
if err == nil {
841-
for _, w := range entitlements.Warnings {
842-
_, _ = fmt.Fprintln(i.Stderr, pretty.Sprint(cliui.DefaultStyles.Warn, w))
846+
// Don't show warning to regular users.
847+
if len(user.Roles) > 0 {
848+
for _, w := range entitlements.Warnings {
849+
_, _ = fmt.Fprintln(i.Stderr, pretty.Sprint(cliui.DefaultStyles.Warn, w))
850+
}
843851
}
844852
}
845853
return nil

cli/ssh_test.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ import (
4343
"github.com/coder/coder/v2/testutil"
4444
)
4545

46+
const (
47+
startupScriptPattern = "i-am-ready"
48+
)
49+
4650
func setupWorkspaceForAgent(t *testing.T, mutate func([]*proto.Agent) []*proto.Agent) (*codersdk.Client, codersdk.Workspace, string) {
4751
t.Helper()
4852
if mutate == nil {
@@ -68,6 +72,12 @@ func setupWorkspaceForAgent(t *testing.T, mutate func([]*proto.Agent) []*proto.A
6872
Auth: &proto.Agent_Token{
6973
Token: agentToken,
7074
},
75+
Scripts: []*proto.Script{
76+
{
77+
Script: fmt.Sprintf("echo '%s'", startupScriptPattern),
78+
RunOnStart: true,
79+
},
80+
},
7181
}}),
7282
}},
7383
},
@@ -393,12 +403,6 @@ func TestSSH(t *testing.T) {
393403

394404
client, workspace, agentToken := setupWorkspaceForAgent(t, nil)
395405

396-
_ = agenttest.New(t, client.URL, agentToken)
397-
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
398-
399-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
400-
defer cancel()
401-
402406
inv, root := clitest.New(t,
403407
"ssh",
404408
workspace.Name,
@@ -408,14 +412,23 @@ func TestSSH(t *testing.T) {
408412
clitest.SetupConfig(t, client, root)
409413
pty := ptytest.New(t).Attach(inv)
410414
inv.Stderr = pty.Output()
415+
416+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
417+
defer cancel()
418+
411419
cmdDone := tGo(t, func() {
412420
err := inv.WithContext(ctx).Run()
413421
assert.NoError(t, err, "ssh command failed")
414422
})
415423

416-
// Wait for the prompt or any output really to indicate the command has
417-
// started and accepting input on stdin.
418-
_ = pty.Peek(ctx, 1)
424+
// Agent is still starting
425+
pty.ExpectMatch("Waiting")
426+
427+
_ = agenttest.New(t, client.URL, agentToken)
428+
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
429+
430+
// Startup script has just finished
431+
pty.ExpectMatch(startupScriptPattern)
419432

420433
// Download the test page
421434
pty.WriteLine("curl localhost:8222")

cli/templatedelete.go

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,13 @@ func (r *RootCmd) templateDelete() *clibase.Cmd {
4848
templates = append(templates, template)
4949
}
5050
} else {
51-
allTemplates, err := client.TemplatesByOrganization(ctx, organization.ID)
51+
template, err := selectTemplate(inv, client, organization)
5252
if err != nil {
53-
return xerrors.Errorf("get templates by organization: %w", err)
53+
return err
5454
}
5555

56-
if len(allTemplates) == 0 {
57-
return xerrors.Errorf("no templates exist in the current organization %q", organization.Name)
58-
}
59-
60-
opts := make([]string, 0, len(allTemplates))
61-
for _, template := range allTemplates {
62-
opts = append(opts, template.Name)
63-
}
64-
65-
selection, err := cliui.Select(inv, cliui.SelectOptions{
66-
Options: opts,
67-
})
68-
if err != nil {
69-
return xerrors.Errorf("select template: %w", err)
70-
}
71-
72-
for _, template := range allTemplates {
73-
if template.Name == selection {
74-
templates = append(templates, template)
75-
templateNames = append(templateNames, template.Name)
76-
}
77-
}
56+
templates = append(templates, template)
57+
templateNames = append(templateNames, template.Name)
7858
}
7959

8060
// Confirm deletion of the template.

0 commit comments

Comments
 (0)