Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: addlog-dir flag to vscodessh for debuggability#10514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kylecarbs merged 1 commit intomainfromvscodesshlogs
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: addlog-dir flag to vscodessh for debuggability
  • Loading branch information
@kylecarbs
kylecarbs committedNov 3, 2023
commitba68ac6a67c99fcfe92e9de09c3b11f226efdb92
28 changes: 23 additions & 5 deletionscli/vscodessh.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,7 @@ func (r *RootCmd) vscodeSSH() *clibase.Cmd {
var (
sessionTokenFile string
urlFile string
logDir string
networkInfoDir string
networkInfoInterval time.Duration
)
Expand DownExpand Up@@ -129,13 +130,25 @@ func (r *RootCmd) vscodeSSH() *clibase.Cmd {
}
}

// The VS Code extension obtains the PID of the SSH process to
// read files to display logs and network info.
//
// We get the parent PID because it's assumed `ssh` is calling this
// command via the ProxyCommand SSH option.
pid := os.Getppid()

var logger slog.Logger
if r.verbose {
logger = slog.Make(sloghuman.Sink(inv.Stdout)).Leveled(slog.LevelDebug)
if logDir != "" {
logFilePath := filepath.Join(logDir, fmt.Sprintf("%d.log", pid))
logFile, err := fs.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY, 0o600)
if err != nil {
return xerrors.Errorf("open log file %q: %w", logFilePath, err)
}
defer logFile.Close()
logger = slog.Make(sloghuman.Sink(logFile)).Leveled(slog.LevelDebug)
}

if r.disableDirect {
_, _ = fmt.Fprintln(inv.Stderr, "Direct connections disabled.")
logger.Info(ctx, "direct connections disabled")
}
agentConn, err := client.DialWorkspaceAgent(ctx, agent.ID, &codersdk.DialWorkspaceAgentOptions{
Logger: logger,
Expand DownExpand Up@@ -166,7 +179,7 @@ func (r *RootCmd) vscodeSSH() *clibase.Cmd {
//
// We get the parent PID because it's assumed `ssh` is calling this
// command via the ProxyCommand SSH option.
networkInfoFilePath := filepath.Join(networkInfoDir, fmt.Sprintf("%d.json",os.Getppid()))
networkInfoFilePath := filepath.Join(networkInfoDir, fmt.Sprintf("%d.json",pid))

statsErrChan := make(chan error, 1)
cb := func(start, end time.Time, virtual, _ map[netlogtype.Connection]netlogtype.Counts) {
Expand DownExpand Up@@ -213,6 +226,11 @@ func (r *RootCmd) vscodeSSH() *clibase.Cmd {
Description: "Specifies a directory to write network information periodically.",
Value: clibase.StringOf(&networkInfoDir),
},
{
Flag: "log-dir",
Description: "Specifies a directory to write logs to.",
Value: clibase.StringOf(&logDir),
},
{
Flag: "session-token-file",
Description: "Specifies a file that contains a session token.",
Expand Down
17 changes: 10 additions & 7 deletionscli/vscodessh_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,20 +43,23 @@ func TestVSCodeSSH(t *testing.T) {
"--url-file", "/url",
"--session-token-file", "/token",
"--network-info-dir", "/net",
"--log-dir", "/log",
"--network-info-interval", "25ms",
fmt.Sprintf("coder-vscode--%s--%s", user.Username, workspace.Name),
)
ptytest.New(t).Attach(inv)

waiter := clitest.StartWithWaiter(t, inv.WithContext(ctx))

assert.Eventually(t, func() bool {
entries, err := afero.ReadDir(fs, "/net")
if err != nil {
return false
}
return len(entries) > 0
}, testutil.WaitLong, testutil.IntervalFast)
for _, dir := range []string{"/net", "/log"} {
assert.Eventually(t, func() bool {
entries, err := afero.ReadDir(fs, dir)
if err != nil {
return false
}
return len(entries) > 0
}, testutil.WaitLong, testutil.IntervalFast)
}
waiter.Cancel()

if err := waiter.Wait(); err != nil {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp