-
Notifications
You must be signed in to change notification settings - Fork 926
chore: switch ssh session stats based on experiment #13637
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c8f173e
aaad075
438b7a6
61648cb
338d2b1
b3a240b
645bc5a
1370ab3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"slices" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
@@ -40,6 +41,10 @@ import ( | |
"github.com/coder/serpent" | ||
) | ||
|
||
const ( | ||
disableUsageApp = "disable" | ||
) | ||
|
||
var ( | ||
workspacePollInterval = time.Minute | ||
autostopNotifyCountdown = []time.Duration{30 * time.Minute} | ||
|
@@ -57,6 +62,7 @@ func (r *RootCmd) ssh() *serpent.Command { | |
logDirPath string | ||
remoteForwards []string | ||
env []string | ||
usageApp string | ||
disableAutostart bool | ||
) | ||
client := new(codersdk.Client) | ||
|
@@ -251,6 +257,15 @@ func (r *RootCmd) ssh() *serpent.Command { | |
stopPolling := tryPollWorkspaceAutostop(ctx, client, workspace) | ||
defer stopPolling() | ||
|
||
usageAppName := getUsageAppName(usageApp) | ||
if usageAppName != "" { | ||
closeUsage := client.UpdateWorkspaceUsageWithBodyContext(ctx, workspace.ID, codersdk.PostWorkspaceUsageRequest{ | ||
AgentID: workspaceAgent.ID, | ||
AppName: usageAppName, | ||
}) | ||
defer closeUsage() | ||
} | ||
|
||
if stdio { | ||
rawSSH, err := conn.SSH(ctx) | ||
if err != nil { | ||
|
@@ -509,6 +524,13 @@ func (r *RootCmd) ssh() *serpent.Command { | |
FlagShorthand: "e", | ||
Value: serpent.StringArrayOf(&env), | ||
}, | ||
{ | ||
Flag: "usage-app", | ||
Description: "Specifies the usage app to use for workspace activity tracking.", | ||
Env: "CODER_SSH_USAGE_APP", | ||
Value: serpent.StringOf(&usageApp), | ||
Hidden: true, | ||
}, | ||
sshDisableAutostartOption(serpent.BoolOf(&disableAutostart)), | ||
} | ||
return cmd | ||
|
@@ -1044,3 +1066,20 @@ func (r stdioErrLogReader) Read(_ []byte) (int, error) { | |
r.l.Error(context.Background(), "reading from stdin in stdio mode is not allowed") | ||
return 0, io.EOF | ||
} | ||
|
||
func getUsageAppName(usageApp string) codersdk.UsageAppName { | ||
if usageApp == disableUsageApp { | ||
return "" | ||
} | ||
|
||
allowedUsageApps := []string{ | ||
string(codersdk.UsageAppNameSSH), | ||
string(codersdk.UsageAppNameVscode), | ||
string(codersdk.UsageAppNameJetbrains), | ||
} | ||
if slices.Contains(allowedUsageApps, usageApp) { | ||
return codersdk.UsageAppName(usageApp) | ||
} | ||
|
||
return codersdk.UsageAppNameSSH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Letting the zero value mean 'disabled' feels more idiomatic to me, but 'disabled' is way more explicit and better from a user perspective. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered having the default value on the flag be |
||
} |
Uh oh!
There was an error while loading. Please reload this page.