Skip to content

fix(agent): add tracking for JetBrains Gateway and Fleet #10491

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

Closed
wants to merge 10 commits into from
Closed
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
1 change: 0 additions & 1 deletion .github/workflows/typos.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[default.extend-identifiers]
alog = "alog"
Jetbrains = "JetBrains"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

Copy link
Member Author

@matifali matifali Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to remove this to fix the lint check. Otherwise, typos CLI complains about
https://github.com/coder/coder/pull/10491/files#diff-e2fb60d4b313fc2ad42c37ce065c0c880e04615b339a843e14892338d0bb4396R268

There is no way to skip checking a single line.
The best we can do is skip the whole file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. And this is a github linter, no golang-ci lint. That you could skip one line.

IST = "IST"
MacOS = "macOS"
AKS = "AKS"
Expand Down
18 changes: 18 additions & 0 deletions agent/agentssh/agentssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,23 @@ func (s *Server) sessionStart(session ssh.Session, extraEnv []string) (retErr er
env = append(env[:index], env[index+1:]...)
}

// Check for JetBrains Gateway and Fleet if MagicType is empty
// JetBrains Geteway does not support SetEnv so this is not being set. See: #9673
// As a workaround, we can check for the TERMINAL_EMULATOR env variable to identify JetBrains Gateway
// and TERM_PROGRAM for JetBrains Fleet
if magicType == "" {
for _, kv := range env {
switch {
case strings.HasPrefix(kv, "TERMINAL_EMULATOR=JetBrains-JediTerm"):
magicType = MagicSessionTypeJetBrains
case strings.HasPrefix(kv, "TERM_PROGRAM=Jetbrains.Fleet"):
magicType = MagicSessionTypeJetBrains
default:
continue
}
}
}

// Always force lowercase checking to be case-insensitive.
switch strings.ToLower(magicType) {
case strings.ToLower(MagicSessionTypeVSCode):
Expand All @@ -272,6 +289,7 @@ func (s *Server) sessionStart(session ssh.Session, extraEnv []string) (retErr er
}

magicTypeLabel := magicTypeMetricLabel(magicType)
fmt.Println("New connection, magic type =", magicType)
sshPty, windowSize, isPty := session.Pty()

cmd, err := s.CreateCommand(ctx, session.RawCommand(), env)
Expand Down
26 changes: 26 additions & 0 deletions agent/agentssh/agentssh_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net"
"testing"
"fmt"

gliderssh "github.com/gliderlabs/ssh"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -19,6 +20,10 @@ import (
"github.com/coder/coder/v2/testutil"

"cdr.dev/slog/sloggers/slogtest"
"go.uber.org/atomic"
"github.com/coder/coder/v2/codersdk/agentsdk"
"github.com/coder/coder/v2/codersdk"

)

const longScript = `
Expand Down Expand Up @@ -195,3 +200,24 @@ func (testSSHContext) SetValue(_, _ interface{}) {
func (testSSHContext) KeepAlive() *gliderssh.SessionKeepAlive {
panic("not implemented")
}

func TestSomeSSHServer(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()
logger := slogtest.Make(t, nil)

s, err := NewServer(ctx, logger, prometheus.NewRegistry(), afero.NewMemMapFs(), 0, "")
require.NoError(t, err)
defer s.Close()
// Required to not panic on new connection
s.Manifest = atomic.NewPointer(&agentsdk.Manifest{})
s.ServiceBanner = atomic.NewPointer(&codersdk.ServiceBannerConfig{})
s.AgentToken = func() string {
return "something"
}

l, err := net.Listen("tcp", "localhost:1828")
require.NoError(t, err)
fmt.Println(s.Serve(l))
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Tooltip from "@mui/material/Tooltip";
import { Link as RouterLink } from "react-router-dom";
import Link from "@mui/material/Link";
import { VSCodeIcon } from "components/Icons/VSCodeIcon";
import { JetBrainsIcon } from "components/Icons/JetBrainsIcon";
import DownloadIcon from "@mui/icons-material/CloudDownload";
import UploadIcon from "@mui/icons-material/CloudUpload";
import LatencyIcon from "@mui/icons-material/SettingsEthernet";
Expand Down Expand Up @@ -298,6 +299,21 @@ export const DeploymentBannerView: FC<DeploymentBannerViewProps> = (props) => {
</div>
</Tooltip>
<ValueSeparator />
<Tooltip title="JetBrains Gateway and Fleet">
<div css={styles.value}>
<JetBrainsIcon
css={css`
& * {
fill: currentColor;
}
`}
/>
{typeof stats?.session_count.jetbrains === "undefined"
? "-"
: stats?.session_count.jetbrains}
</div>
</Tooltip>
<ValueSeparator />
<Tooltip title="SSH Sessions">
<div css={styles.value}>
<TerminalIcon />
Expand Down
22 changes: 22 additions & 0 deletions site/src/components/Icons/JetBrainsIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SvgIcon, { SvgIconProps } from "@mui/material/SvgIcon";

export const JetBrainsIcon = (props: SvgIconProps) => (
<SvgIcon {...props} viewBox="0 0 100 100">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<path d="m22.5 22.5h60v60h-60z" />
<g fill="#fff">
<path d="m29.03 71.25h22.5v3.75h-22.5z" />
<path d="m28.09 38 1.67-1.58a1.88 1.88 0 0 0 1.47.87c.64 0 1.06-.44 1.06-1.31v-5.98h2.58v6a3.48 3.48 0 0 1 -.87 2.6 3.56 3.56 0 0 1 -2.57.95 3.84 3.84 0 0 1 -3.34-1.55z" />
<path d="m36 30h7.53v2.19h-5v1.44h4.49v2h-4.42v1.49h5v2.21h-7.6z" />
<path d="m47.23 32.29h-2.8v-2.29h8.21v2.27h-2.81v7.1h-2.6z" />
<path d="m29.13 43.08h4.42a3.53 3.53 0 0 1 2.55.83 2.09 2.09 0 0 1 .6 1.53 2.16 2.16 0 0 1 -1.44 2.09 2.27 2.27 0 0 1 1.86 2.29c0 1.61-1.31 2.59-3.55 2.59h-4.44zm5 2.89c0-.52-.42-.8-1.18-.8h-1.29v1.64h1.24c.79 0 1.25-.26 1.25-.81zm-.9 2.66h-1.57v1.73h1.62c.8 0 1.24-.31 1.24-.86 0-.5-.4-.87-1.27-.87z" />
<path d="m38 43.08h4.1a4.19 4.19 0 0 1 3 1 2.93 2.93 0 0 1 .9 2.19 3 3 0 0 1 -1.93 2.89l2.24 3.27h-3l-1.88-2.84h-.87v2.84h-2.56zm4 4.5c.87 0 1.39-.43 1.39-1.11 0-.75-.54-1.12-1.4-1.12h-1.44v2.26z" />
<path d="m49.59 43h2.5l4 9.44h-2.79l-.67-1.69h-3.63l-.67 1.69h-2.71zm2.27 5.73-1-2.65-1.06 2.65z" />
<path d="m56.46 43.05h2.6v9.37h-2.6z" />
<path d="m60.06 43.05h2.42l3.37 5v-5h2.57v9.37h-2.26l-3.53-5.14v5.14h-2.57z" />
<path d="m68.86 51 1.45-1.73a4.84 4.84 0 0 0 3 1.13c.71 0 1.08-.24 1.08-.65 0-.4-.31-.6-1.59-.91-2-.46-3.53-1-3.53-2.93 0-1.74 1.37-3 3.62-3a5.89 5.89 0 0 1 3.86 1.25l-1.26 1.84a4.63 4.63 0 0 0 -2.62-.92c-.63 0-.94.25-.94.6 0 .42.32.61 1.63.91 2.14.46 3.44 1.16 3.44 2.91 0 1.91-1.51 3-3.79 3a6.58 6.58 0 0 1 -4.35-1.5z" />
</g>
<path d="m0 0h105v105h-105z" fill="none" />
</svg>
</SvgIcon>
);
1 change: 1 addition & 0 deletions site/src/theme/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"java.svg",
"javascript.svg",
"jax.svg",
"jetbrains.svg",
"jfrog.svg",
"jupyter.svg",
"k8s.png",
Expand Down
1 change: 1 addition & 0 deletions site/static/icon/jetbrains.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.