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

Skip to content

Commit 01dae76

Browse files
committed
Merge branch 'main' into 3321-template-space-b
2 parents 88c6ddc + 18a97c6 commit 01dae76

Some content is hidden

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

50 files changed

+871
-556
lines changed

agent/agent_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ func TestAgent(t *testing.T) {
499499

500500
conn, _ := setupAgent(t, codersdk.WorkspaceAgentMetadata{}, 0)
501501
require.Eventually(t, func() bool {
502-
_, err := conn.Ping(context.Background())
502+
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.IntervalFast)
503+
defer cancelFunc()
504+
_, err := conn.Ping(ctx)
503505
return err == nil
504506
}, testutil.WaitMedium, testutil.IntervalFast)
505507
conn1, err := conn.DialContext(context.Background(), l.Addr().Network(), l.Addr().String())

agent/apphealth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"sync"
77
"time"
88

9-
"golang.org/x/xerrors"
109
"github.com/google/uuid"
10+
"golang.org/x/xerrors"
1111

1212
"cdr.dev/slog"
1313
"github.com/coder/coder/codersdk"

cli/agent_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func TestWorkspaceAgent(t *testing.T) {
7272
require.NoError(t, err)
7373
defer dialer.Close()
7474
require.Eventually(t, func() bool {
75+
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
76+
defer cancelFunc()
7577
_, err := dialer.Ping(ctx)
7678
return err == nil
7779
}, testutil.WaitMedium, testutil.IntervalFast)
@@ -133,6 +135,8 @@ func TestWorkspaceAgent(t *testing.T) {
133135
require.NoError(t, err)
134136
defer dialer.Close()
135137
require.Eventually(t, func() bool {
138+
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
139+
defer cancelFunc()
136140
_, err := dialer.Ping(ctx)
137141
return err == nil
138142
}, testutil.WaitMedium, testutil.IntervalFast)
@@ -194,6 +198,8 @@ func TestWorkspaceAgent(t *testing.T) {
194198
require.NoError(t, err)
195199
defer dialer.Close()
196200
require.Eventually(t, func() bool {
201+
ctx, cancelFunc := context.WithTimeout(ctx, testutil.IntervalFast)
202+
defer cancelFunc()
197203
_, err := dialer.Ping(ctx)
198204
return err == nil
199205
}, testutil.WaitMedium, testutil.IntervalFast)

cli/deployment/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ func newConfig() *codersdk.DeploymentConfig {
295295
Flag: "trace-honeycomb-api-key",
296296
Secret: true,
297297
},
298+
CaptureLogs: &codersdk.DeploymentConfigField[bool]{
299+
Name: "Capture Logs in Traces",
300+
Usage: "Enables capturing of logs as events in traces. This is useful for debugging, but may result in a very large amount of events being sent to the tracing backend which may incur significant costs. If the verbose flag was supplied, debug-level logs will be included.",
301+
Flag: "trace-logs",
302+
},
298303
},
299304
SecureAuthCookie: &codersdk.DeploymentConfigField[bool]{
300305
Name: "Secure Auth Cookie",

cli/server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
8888
if ok, _ := cmd.Flags().GetBool(varVerbose); ok {
8989
logger = logger.Leveled(slog.LevelDebug)
9090
}
91+
if cfg.Trace.CaptureLogs.Value {
92+
logger = logger.AppendSinks(tracing.SlogSink{})
93+
}
9194

9295
// Main command context for managing cancellation
9396
// of running services.
@@ -126,7 +129,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
126129
shouldCoderTrace = cfg.Telemetry.Trace.Value
127130
}
128131

129-
if cfg.Trace.Enable.Value || shouldCoderTrace {
132+
if cfg.Trace.Enable.Value || shouldCoderTrace || cfg.Trace.HoneycombAPIKey.Value != "" {
130133
sdkTracerProvider, closeTracing, err := tracing.TracerProvider(ctx, "coderd", tracing.TracerOpts{
131134
Default: cfg.Trace.Enable.Value,
132135
Coder: shouldCoderTrace,

cli/templatecreate.go

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

2525
func templateCreate() *cobra.Command {
2626
var (
27-
directory string
28-
provisioner string
29-
parameterFile string
30-
maxTTL time.Duration
31-
minAutostartInterval time.Duration
27+
directory string
28+
provisioner string
29+
parameterFile string
30+
defaultTTL time.Duration
3231
)
3332
cmd := &cobra.Command{
3433
Use: "create [name]",
@@ -108,10 +107,9 @@ func templateCreate() *cobra.Command {
108107
}
109108

110109
createReq := codersdk.CreateTemplateRequest{
111-
Name: templateName,
112-
VersionID: job.ID,
113-
MaxTTLMillis: ptr.Ref(maxTTL.Milliseconds()),
114-
MinAutostartIntervalMillis: ptr.Ref(minAutostartInterval.Milliseconds()),
110+
Name: templateName,
111+
VersionID: job.ID,
112+
DefaultTTLMillis: ptr.Ref(defaultTTL.Milliseconds()),
115113
}
116114

117115
_, err = client.CreateTemplate(cmd.Context(), organization.ID, createReq)
@@ -133,8 +131,7 @@ func templateCreate() *cobra.Command {
133131
cmd.Flags().StringVarP(&directory, "directory", "d", currentDirectory, "Specify the directory to create from")
134132
cmd.Flags().StringVarP(&provisioner, "test.provisioner", "", "terraform", "Customize the provisioner backend")
135133
cmd.Flags().StringVarP(&parameterFile, "parameter-file", "", "", "Specify a file path with parameter values.")
136-
cmd.Flags().DurationVarP(&maxTTL, "max-ttl", "", 24*time.Hour, "Specify a maximum TTL for workspaces created from this template.")
137-
cmd.Flags().DurationVarP(&minAutostartInterval, "min-autostart-interval", "", time.Hour, "Specify a minimum autostart interval for workspaces created from this template.")
134+
cmd.Flags().DurationVarP(&defaultTTL, "default-ttl", "", 24*time.Hour, "Specify a default TTL for workspaces created from this template.")
138135
// This is for testing!
139136
err := cmd.Flags().MarkHidden("test.provisioner")
140137
if err != nil {

cli/templatecreate_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ func TestTemplateCreate(t *testing.T) {
5252
"my-template",
5353
"--directory", source,
5454
"--test.provisioner", string(database.ProvisionerTypeEcho),
55-
"--max-ttl", "24h",
56-
"--min-autostart-interval", "2h",
55+
"--default-ttl", "24h",
5756
}
5857
cmd, root := clitest.New(t, args...)
5958
clitest.SetupConfig(t, client, root)

cli/templateedit.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ import (
1313

1414
func templateEdit() *cobra.Command {
1515
var (
16-
name string
17-
displayName string
18-
description string
19-
icon string
20-
maxTTL time.Duration
21-
minAutostartInterval time.Duration
16+
name string
17+
displayName string
18+
description string
19+
icon string
20+
defaultTTL time.Duration
2221
)
2322

2423
cmd := &cobra.Command{
@@ -41,12 +40,11 @@ func templateEdit() *cobra.Command {
4140

4241
// NOTE: coderd will ignore empty fields.
4342
req := codersdk.UpdateTemplateMeta{
44-
Name: name,
45-
DisplayName: displayName,
46-
Description: description,
47-
Icon: icon,
48-
MaxTTLMillis: maxTTL.Milliseconds(),
49-
MinAutostartIntervalMillis: minAutostartInterval.Milliseconds(),
43+
Name: name,
44+
DisplayName: displayName,
45+
Description: description,
46+
Icon: icon,
47+
DefaultTTLMillis: defaultTTL.Milliseconds(),
5048
}
5149

5250
_, err = client.UpdateTemplateMeta(cmd.Context(), template.ID, req)
@@ -62,8 +60,7 @@ func templateEdit() *cobra.Command {
6260
cmd.Flags().StringVarP(&displayName, "display-name", "", "", "Edit the template display name")
6361
cmd.Flags().StringVarP(&description, "description", "", "", "Edit the template description")
6462
cmd.Flags().StringVarP(&icon, "icon", "", "", "Edit the template icon path")
65-
cmd.Flags().DurationVarP(&maxTTL, "max-ttl", "", 0, "Edit the template maximum time before shutdown - workspaces created from this template cannot stay running longer than this.")
66-
cmd.Flags().DurationVarP(&minAutostartInterval, "min-autostart-interval", "", 0, "Edit the template minimum autostart interval - workspaces created from this template must wait at least this long between autostarts.")
63+
cmd.Flags().DurationVarP(&defaultTTL, "default-ttl", "", 0, "Edit the template default time before shutdown - workspaces created from this template to this value.")
6764
cliui.AllowSkipPrompt(cmd)
6865

6966
return cmd

cli/templateedit_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ func TestTemplateEdit(t *testing.T) {
3030
displayName := "New Display Name 789"
3131
desc := "lorem ipsum dolor sit amet et cetera"
3232
icon := "/icons/new-icon.png"
33-
maxTTL := 12 * time.Hour
34-
minAutostartInterval := time.Minute
33+
defaultTTL := 12 * time.Hour
3534
cmdArgs := []string{
3635
"templates",
3736
"edit",
@@ -40,8 +39,7 @@ func TestTemplateEdit(t *testing.T) {
4039
"--display-name", displayName,
4140
"--description", desc,
4241
"--icon", icon,
43-
"--max-ttl", maxTTL.String(),
44-
"--min-autostart-interval", minAutostartInterval.String(),
42+
"--default-ttl", defaultTTL.String(),
4543
}
4644
cmd, root := clitest.New(t, cmdArgs...)
4745
clitest.SetupConfig(t, client, root)
@@ -58,8 +56,7 @@ func TestTemplateEdit(t *testing.T) {
5856
assert.Equal(t, displayName, updated.DisplayName)
5957
assert.Equal(t, desc, updated.Description)
6058
assert.Equal(t, icon, updated.Icon)
61-
assert.Equal(t, maxTTL.Milliseconds(), updated.MaxTTLMillis)
62-
assert.Equal(t, minAutostartInterval.Milliseconds(), updated.MinAutostartIntervalMillis)
59+
assert.Equal(t, defaultTTL.Milliseconds(), updated.DefaultTTLMillis)
6360
})
6461
t.Run("NotModified", func(t *testing.T) {
6562
t.Parallel()
@@ -77,8 +74,7 @@ func TestTemplateEdit(t *testing.T) {
7774
"--name", template.Name,
7875
"--description", template.Description,
7976
"--icon", template.Icon,
80-
"--max-ttl", (time.Duration(template.MaxTTLMillis) * time.Millisecond).String(),
81-
"--min-autostart-interval", (time.Duration(template.MinAutostartIntervalMillis) * time.Millisecond).String(),
77+
"--default-ttl", (time.Duration(template.DefaultTTLMillis) * time.Millisecond).String(),
8278
}
8379
cmd, root := clitest.New(t, cmdArgs...)
8480
clitest.SetupConfig(t, client, root)
@@ -94,8 +90,7 @@ func TestTemplateEdit(t *testing.T) {
9490
assert.Equal(t, template.Name, updated.Name)
9591
assert.Equal(t, template.Description, updated.Description)
9692
assert.Equal(t, template.Icon, updated.Icon)
97-
assert.Equal(t, template.MaxTTLMillis, updated.MaxTTLMillis)
98-
assert.Equal(t, template.MinAutostartIntervalMillis, updated.MinAutostartIntervalMillis)
93+
assert.Equal(t, template.DefaultTTLMillis, updated.DefaultTTLMillis)
9994
})
10095
t.Run("InvalidDisplayName", func(t *testing.T) {
10196
t.Parallel()

cli/templates.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@ func templates() *cobra.Command {
5050
}
5151

5252
type templateTableRow struct {
53-
Name string `table:"name"`
54-
CreatedAt string `table:"created at"`
55-
LastUpdated string `table:"last updated"`
56-
OrganizationID uuid.UUID `table:"organization id"`
57-
Provisioner codersdk.ProvisionerType `table:"provisioner"`
58-
ActiveVersionID uuid.UUID `table:"active version id"`
59-
UsedBy string `table:"used by"`
60-
MaxTTL time.Duration `table:"max ttl"`
61-
MinAutostartInterval time.Duration `table:"min autostart"`
53+
Name string `table:"name"`
54+
CreatedAt string `table:"created at"`
55+
LastUpdated string `table:"last updated"`
56+
OrganizationID uuid.UUID `table:"organization id"`
57+
Provisioner codersdk.ProvisionerType `table:"provisioner"`
58+
ActiveVersionID uuid.UUID `table:"active version id"`
59+
UsedBy string `table:"used by"`
60+
DefaultTTL time.Duration `table:"default ttl"`
6261
}
6362

6463
// displayTemplates will return a table displaying all templates passed in.
@@ -68,15 +67,14 @@ func displayTemplates(filterColumns []string, templates ...codersdk.Template) (s
6867
rows := make([]templateTableRow, len(templates))
6968
for i, template := range templates {
7069
rows[i] = templateTableRow{
71-
Name: template.Name,
72-
CreatedAt: template.CreatedAt.Format("January 2, 2006"),
73-
LastUpdated: template.UpdatedAt.Format("January 2, 2006"),
74-
OrganizationID: template.OrganizationID,
75-
Provisioner: template.Provisioner,
76-
ActiveVersionID: template.ActiveVersionID,
77-
UsedBy: cliui.Styles.Fuchsia.Render(formatActiveDevelopers(template.ActiveUserCount)),
78-
MaxTTL: (time.Duration(template.MaxTTLMillis) * time.Millisecond),
79-
MinAutostartInterval: (time.Duration(template.MinAutostartIntervalMillis) * time.Millisecond),
70+
Name: template.Name,
71+
CreatedAt: template.CreatedAt.Format("January 2, 2006"),
72+
LastUpdated: template.UpdatedAt.Format("January 2, 2006"),
73+
OrganizationID: template.OrganizationID,
74+
Provisioner: template.Provisioner,
75+
ActiveVersionID: template.ActiveVersionID,
76+
UsedBy: cliui.Styles.Fuchsia.Render(formatActiveDevelopers(template.ActiveUserCount)),
77+
DefaultTTL: (time.Duration(template.DefaultTTLMillis) * time.Millisecond),
8078
}
8179
}
8280

cli/testdata/coder_server_--help.golden

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ Flags:
188188
--trace-honeycomb-api-key string Enables trace exporting to Honeycomb.io
189189
using the provided API Key.
190190
Consumes $CODER_TRACE_HONEYCOMB_API_KEY
191+
--trace-logs Enables capturing of logs as events in
192+
traces. This is useful for debugging, but
193+
may result in a very large amount of
194+
events being sent to the tracing backend
195+
which may incur significant costs. If the
196+
verbose flag was supplied, debug-level
197+
logs will be included.
198+
Consumes $CODER_TRACE_CAPTURE_LOGS
191199
--wildcard-access-url string Specifies the wildcard hostname to use
192200
for workspace applications in the form
193201
"*.example.com".

coderd/database/databasefake/databasefake.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,8 +1456,7 @@ func (q *fakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.Upd
14561456
tpl.DisplayName = arg.DisplayName
14571457
tpl.Description = arg.Description
14581458
tpl.Icon = arg.Icon
1459-
tpl.MaxTtl = arg.MaxTtl
1460-
tpl.MinAutostartInterval = arg.MinAutostartInterval
1459+
tpl.DefaultTtl = arg.DefaultTtl
14611460
q.templates[idx] = tpl
14621461
return tpl, nil
14631462
}
@@ -2228,25 +2227,20 @@ func (q *fakeQuerier) InsertTemplate(_ context.Context, arg database.InsertTempl
22282227
q.mutex.Lock()
22292228
defer q.mutex.Unlock()
22302229

2231-
if arg.MinAutostartInterval == 0 {
2232-
arg.MinAutostartInterval = int64(time.Hour)
2233-
}
2234-
22352230
//nolint:gosimple
22362231
template := database.Template{
2237-
ID: arg.ID,
2238-
CreatedAt: arg.CreatedAt,
2239-
UpdatedAt: arg.UpdatedAt,
2240-
OrganizationID: arg.OrganizationID,
2241-
Name: arg.Name,
2242-
Provisioner: arg.Provisioner,
2243-
ActiveVersionID: arg.ActiveVersionID,
2244-
Description: arg.Description,
2245-
MaxTtl: arg.MaxTtl,
2246-
MinAutostartInterval: arg.MinAutostartInterval,
2247-
CreatedBy: arg.CreatedBy,
2248-
UserACL: arg.UserACL,
2249-
GroupACL: arg.GroupACL,
2232+
ID: arg.ID,
2233+
CreatedAt: arg.CreatedAt,
2234+
UpdatedAt: arg.UpdatedAt,
2235+
OrganizationID: arg.OrganizationID,
2236+
Name: arg.Name,
2237+
Provisioner: arg.Provisioner,
2238+
ActiveVersionID: arg.ActiveVersionID,
2239+
Description: arg.Description,
2240+
DefaultTtl: arg.DefaultTtl,
2241+
CreatedBy: arg.CreatedBy,
2242+
UserACL: arg.UserACL,
2243+
GroupACL: arg.GroupACL,
22502244
}
22512245
q.templates = append(q.templates, template)
22522246
return template, nil

coderd/database/dump.sql

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- add "slug" min_autostart_interval to "templates" table
2+
ALTER TABLE "templates" ADD COLUMN "min_autostart_interval" int DEFAULT 0;
3+
4+
-- rename "default_ttl" to "max_ttl" on "templates" table
5+
ALTER TABLE "templates" RENAME COLUMN "default_ttl" TO "max_ttl";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- drop "min_autostart_interval" column from "templates" table
2+
ALTER TABLE "templates" DROP COLUMN "min_autostart_interval";
3+
4+
-- rename "max_ttl" to "default_ttl" on "templates" table
5+
ALTER TABLE "templates" RENAME COLUMN "max_ttl" TO "default_ttl";
6+
COMMENT ON COLUMN templates.default_ttl IS 'The default duration for auto-stop for workspaces created from this template.';

0 commit comments

Comments
 (0)