From cea07cfb41cbda0fee6f1345e7803208622db6c1 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 4 Mar 2024 17:29:20 +0200 Subject: [PATCH 1/4] fix(cli): produce corrently named file in DumpHandler --- cli/agent.go | 2 +- cli/root.go | 4 ++-- cli/server.go | 2 +- enterprise/cli/proxyserver.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/agent.go b/cli/agent.go index 23473022abea7..af54bfc969bce 100644 --- a/cli/agent.go +++ b/cli/agent.go @@ -149,7 +149,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd { // DumpHandler does signal handling, so we call it after the // reaper. - go DumpHandler(ctx) + go DumpHandler(ctx, "agent") logWriter := &lumberjackWriteCloseFixer{w: &lumberjack.Logger{ Filename: filepath.Join(logDir, "coder-agent.log"), diff --git a/cli/root.go b/cli/root.go index 6a9b8367fbeb6..16ebb227f3aae 100644 --- a/cli/root.go +++ b/cli/root.go @@ -937,7 +937,7 @@ func (r *RootCmd) Verbosef(inv *clibase.Invocation, fmtStr string, args ...inter // A SIGQUIT handler will not be registered if GOTRACEBACK=crash. // // On Windows this immediately returns. -func DumpHandler(ctx context.Context) { +func DumpHandler(ctx context.Context, name string) { if runtime.GOOS == "windows" { // free up the goroutine since it'll be permanently blocked anyways return @@ -992,7 +992,7 @@ func DumpHandler(ctx context.Context) { if err != nil { dir = os.TempDir() } - fpath := filepath.Join(dir, fmt.Sprintf("coder-agent-%s.dump", time.Now().Format("2006-01-02T15:04:05.000Z"))) + fpath := filepath.Join(dir, fmt.Sprintf("coder-%s-%s.dump", name, time.Now().Format("2006-01-02T15:04:05.000Z"))) _, _ = fmt.Fprintf(os.Stderr, "writing dump to %q\n", fpath) f, err := os.Create(fpath) diff --git a/cli/server.go b/cli/server.go index 95fca7caa84d5..6788639193fdd 100644 --- a/cli/server.go +++ b/cli/server.go @@ -289,7 +289,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd. cliui.Warnf(inv.Stderr, "YAML support is experimental and offers no compatibility guarantees.") } - go DumpHandler(ctx) + go DumpHandler(ctx, "coderd") // Validate bind addresses. if vals.Address.String() != "" { diff --git a/enterprise/cli/proxyserver.go b/enterprise/cli/proxyserver.go index 9ac59735b120d..59b650ffc26cb 100644 --- a/enterprise/cli/proxyserver.go +++ b/enterprise/cli/proxyserver.go @@ -119,7 +119,7 @@ func (r *RootCmd) proxyServer() *clibase.Cmd { defer topCancel() closers.Add(topCancel) - go cli.DumpHandler(ctx) + go cli.DumpHandler(ctx, "workspace-proxy") cli.PrintLogo(inv, "Coder Workspace Proxy") logger, logCloser, err := clilog.New(clilog.FromDeploymentValues(cfg)).Build(inv) From d855d947dcc830c8162455f9d7deed3deeb57c99 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 4 Mar 2024 17:38:35 +0200 Subject: [PATCH 2/4] include filsystem safe time --- cli/root.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/root.go b/cli/root.go index 16ebb227f3aae..c7f5636715763 100644 --- a/cli/root.go +++ b/cli/root.go @@ -992,7 +992,10 @@ func DumpHandler(ctx context.Context, name string) { if err != nil { dir = os.TempDir() } - fpath := filepath.Join(dir, fmt.Sprintf("coder-%s-%s.dump", name, time.Now().Format("2006-01-02T15:04:05.000Z"))) + // Make the time filesystem-safe, for example ":" is not + // permitted on many filesystems. + filesystemSafeTime := time.Now().Format("2006-01-02T15-04-05.000Z") + fpath := filepath.Join(dir, fmt.Sprintf("coder-%s-%s.dump", name, filesystemSafeTime)) _, _ = fmt.Fprintf(os.Stderr, "writing dump to %q\n", fpath) f, err := os.Create(fpath) From 20938554cfe53e5ec31b82cde936c02834d0130d Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 4 Mar 2024 17:48:41 +0200 Subject: [PATCH 3/4] make sure time is in UTC since we append Z --- cli/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/root.go b/cli/root.go index c7f5636715763..9ee8e37d1bee2 100644 --- a/cli/root.go +++ b/cli/root.go @@ -994,7 +994,7 @@ func DumpHandler(ctx context.Context, name string) { } // Make the time filesystem-safe, for example ":" is not // permitted on many filesystems. - filesystemSafeTime := time.Now().Format("2006-01-02T15-04-05.000Z") + filesystemSafeTime := time.Now().UTC().Format("2006-01-02T15-04-05.000Z") fpath := filepath.Join(dir, fmt.Sprintf("coder-%s-%s.dump", name, filesystemSafeTime)) _, _ = fmt.Fprintf(os.Stderr, "writing dump to %q\n", fpath) From 43d97eaec8365050e5b8d53496b4abdd282b6433 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 4 Mar 2024 17:50:31 +0200 Subject: [PATCH 4/4] improve note --- cli/root.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/root.go b/cli/root.go index 9ee8e37d1bee2..b4a381052cda5 100644 --- a/cli/root.go +++ b/cli/root.go @@ -993,7 +993,8 @@ func DumpHandler(ctx context.Context, name string) { dir = os.TempDir() } // Make the time filesystem-safe, for example ":" is not - // permitted on many filesystems. + // permitted on many filesystems. Note that Z here only appends + // Z to the string, it does not actually change the time zone. filesystemSafeTime := time.Now().UTC().Format("2006-01-02T15-04-05.000Z") fpath := filepath.Join(dir, fmt.Sprintf("coder-%s-%s.dump", name, filesystemSafeTime)) _, _ = fmt.Fprintf(os.Stderr, "writing dump to %q\n", fpath)