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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 12 additions & 13 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,19 +424,18 @@ func (a *agent) init() {
BlockFileTransfer: a.blockFileTransfer,
BlockReversePortForwarding: a.blockReversePortForwarding,
BlockLocalPortForwarding: a.blockLocalPortForwarding,
ReportConnection: func(id uuid.UUID, magicType agentssh.MagicSessionType, ip string) func(code int, reason string) {
ReportConnection: func(id uuid.UUID, appName string, ip string) func(code int, reason string) {
var connectionType proto.Connection_Type
switch magicType {
case agentssh.MagicSessionTypeSSH:
// Connection_Type is a fixed enum, stored as a database enum in
// the connection log, so it can only hold a family.
switch codersdk.AppNameFamily(appName) {
case codersdk.AppFamilySSH:
connectionType = proto.Connection_SSH
case agentssh.MagicSessionTypeVSCode:
case codersdk.AppFamilyVSCode:
connectionType = proto.Connection_VSCODE
case agentssh.MagicSessionTypeJetBrains:
case codersdk.AppFamilyJetBrains:
connectionType = proto.Connection_JETBRAINS
case agentssh.MagicSessionTypeUnknown:
connectionType = proto.Connection_TYPE_UNSPECIFIED
default:
a.logger.Error(a.hardCtx, "unhandled magic session type when reporting connection", slog.F("magic_type", magicType))
connectionType = proto.Connection_TYPE_UNSPECIFIED
}

Expand Down Expand Up @@ -2162,11 +2161,11 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
stats.TxPackets += int64(counts.TxPackets)
}

// The count of active sessions.
sshStats := a.sshServer.ConnStats()
stats.SessionCountSsh = sshStats.Sessions
stats.SessionCountVscode = sshStats.VSCode
stats.SessionCountJetbrains = sshStats.JetBrains
// The count of active sessions; types without a protocol field are dropped.
sessionCounts := a.sshServer.SessionCounts()
stats.SessionCountSsh = sessionCounts[string(codersdk.AppFamilySSH)]
stats.SessionCountVscode = sessionCounts[string(codersdk.AppFamilyVSCode)]
stats.SessionCountJetbrains = sessionCounts[string(codersdk.AppFamilyJetBrains)]

stats.SessionCountReconnectingPty = a.reconnectingPTYServer.ConnCount()

Expand Down
8 changes: 4 additions & 4 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ func TestAgent_Stats_Magic(t *testing.T) {
defer sshClient.Close()
session, err := sshClient.NewSession()
require.NoError(t, err)
session.Setenv(agentssh.MagicSessionTypeEnvironmentVariable, string(agentssh.MagicSessionTypeVSCode))
session.Setenv(agentssh.AppNameEnvironmentVariable, string(codersdk.AppFamilyVSCode))
defer session.Close()

command := "sh -c 'echo $" + agentssh.MagicSessionTypeEnvironmentVariable + "'"
command := "sh -c 'echo $" + agentssh.AppNameEnvironmentVariable + "'"
expected := ""
if runtime.GOOS == "windows" {
expected = "%" + agentssh.MagicSessionTypeEnvironmentVariable + "%"
expected = "%" + agentssh.AppNameEnvironmentVariable + "%"
command = "cmd.exe /c echo " + expected
}
output, err := session.Output(command)
Expand All @@ -338,7 +338,7 @@ func TestAgent_Stats_Magic(t *testing.T) {
defer sshClient.Close()
session, err := sshClient.NewSession()
require.NoError(t, err)
session.Setenv(agentssh.MagicSessionTypeEnvironmentVariable, string(agentssh.MagicSessionTypeVSCode))
session.Setenv(agentssh.AppNameEnvironmentVariable, string(codersdk.AppFamilyVSCode))
defer session.Close()
stdin, err := session.StdinPipe()
require.NoError(t, err)
Expand Down
Loading
Loading