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

chore: report ssh stats by getting session type from env#13598

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

Closed
Closed
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
35 changes: 29 additions & 6 deletionscli/ssh.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,7 @@ import (

"cdr.dev/slog"
"cdr.dev/slog/sloggers/sloghuman"
"github.com/coder/coder/v2/agent/agentssh"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/cli/cliutil"
"github.com/coder/coder/v2/coderd/autobuild/notify"
Expand DownExpand Up@@ -58,6 +59,7 @@ func (r *RootCmd) ssh() *serpent.Command {
remoteForwards []string
env []string
disableAutostart bool
noUsageTracking bool
)
client := new(codersdk.Client)
cmd := &serpent.Command{
Expand DownExpand Up@@ -408,12 +410,27 @@ func (r *RootCmd) ssh() *serpent.Command {
return xerrors.Errorf("start shell: %w", err)
}

// track workspace usage while connection is open
closeUsage := client.UpdateWorkspaceUsageWithBodyContext(ctx, workspace.ID, codersdk.PostWorkspaceUsageRequest{
AgentID: workspaceAgent.ID,
AppName: codersdk.UsageAppNameSSH,
})
defer closeUsage()
if !noUsageTracking {
// check env for magic variable to determine the session type
appName := codersdk.UsageAppNameSSH
for _, kv := range parsedEnv {
if kv[0] == agentssh.MagicSessionTypeEnvironmentVariable {
switch kv[1] {
case agentssh.MagicSessionTypeJetBrains:
appName = codersdk.UsageAppNameJetbrains
case agentssh.MagicSessionTypeVSCode:
appName = codersdk.UsageAppNameVscode
}
}
}

// track workspace usage while connection is open
closeUsage := client.UpdateWorkspaceUsageWithBodyContext(ctx, workspace.ID, codersdk.PostWorkspaceUsageRequest{
AgentID: workspaceAgent.ID,
AppName: appName,
})
defer closeUsage()
}

// Put cancel at the top of the defer stack to initiate
// shutdown of services.
Expand DownExpand Up@@ -517,6 +534,12 @@ func (r *RootCmd) ssh() *serpent.Command {
Value: serpent.StringArrayOf(&env),
},
sshDisableAutostartOption(serpent.BoolOf(&disableAutostart)),
{
Flag: "no-usage-tracking",
Description: "Disables tracking of workspace usage.",
Env: "CODER_SSH_NO_USAGE_TRACKING",
Value: serpent.BoolOf(&noUsageTracking),
},
}
return cmd
}
Expand Down
3 changes: 3 additions & 0 deletionscli/testdata/coder_ssh_--help.golden
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,6 +30,9 @@ OPTIONS:
-l, --log-dir string, $CODER_SSH_LOG_DIR
Specify the directory containing SSH diagnostic log files.

--no-usage-tracking bool, $CODER_SSH_NO_USAGE_TRACKING
Disables tracking of workspace usage.

--no-wait bool, $CODER_SSH_NO_WAIT
Enter workspace immediately after the agent has connected. This is the
default if the template has configured the agent startup script
Expand Down
9 changes: 9 additions & 0 deletionsdocs/cli/ssh.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.


[8]ページ先頭

©2009-2025 Movatter.jp