Skip to content

Commit

Permalink
[ssh-gateway] add track for send closed heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
iQQBot committed Jun 28, 2022
1 parent 420c212 commit 2dd0a29
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 20 additions & 4 deletions components/ws-proxy/pkg/sshproxy/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"sync"
"time"

"github.com/gitpod-io/gitpod/common-go/analytics"
"github.com/gitpod-io/gitpod/common-go/log"
tracker "github.com/gitpod-io/gitpod/ws-proxy/pkg/analytics"
"github.com/gitpod-io/golang-crypto/ssh"
"golang.org/x/net/context"
)
Expand All @@ -29,7 +31,7 @@ func (s *Server) ChannelForward(ctx context.Context, session *Session, targetCon
return
}
if originChannel.ChannelType() == "session" {
originChan = startHeartbeatingChannel(originChan, s.Heartbeater, session.InstanceID)
originChan = startHeartbeatingChannel(originChan, s.Heartbeater, session)
}
defer originChan.Close()

Expand Down Expand Up @@ -90,7 +92,19 @@ func (s *Server) ChannelForward(ctx context.Context, session *Session, targetCon
log.WithFields(log.OWI("", session.WorkspaceID, session.InstanceID)).Debug("session forward stop")
}

func startHeartbeatingChannel(c ssh.Channel, heartbeat Heartbeat, instanceID string) ssh.Channel {
func TrackIDECloseSignal(session *Session) {
propertics := make(map[string]interface{})
propertics["workspaceId"] = session.WorkspaceID
propertics["instanceId"] = session.InstanceID
propertics["clientKind"] = "ssh"
tracker.Track(analytics.TrackMessage{
Identity: analytics.Identity{UserID: session.OwnerUserId},
Event: "ide_close_signal",
Properties: propertics,
})
}

func startHeartbeatingChannel(c ssh.Channel, heartbeat Heartbeat, session *Session) ssh.Channel {
ctx, cancel := context.WithCancel(context.Background())
res := &heartbeatingChannel{
Channel: c,
Expand All @@ -108,10 +122,12 @@ func startHeartbeatingChannel(c ssh.Channel, heartbeat Heartbeat, instanceID str
}
res.sawActivity = false
res.mux.Unlock()
heartbeat.SendHeartbeat(instanceID, false)
heartbeat.SendHeartbeat(session.InstanceID, false)
case <-ctx.Done():
if res.requestedPty {
heartbeat.SendHeartbeat(instanceID, true)
heartbeat.SendHeartbeat(session.InstanceID, true)
TrackIDECloseSignal(session)
log.WithField("instanceId", session.InstanceID).Info("send closed heartbeat")
}
return
}
Expand Down
2 changes: 2 additions & 0 deletions components/ws-proxy/pkg/sshproxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Session struct {

WorkspaceID string
InstanceID string
OwnerUserId string

PublicKey ssh.PublicKey
WorkspacePrivateKey ssh.Signer
Expand Down Expand Up @@ -251,6 +252,7 @@ func (s *Server) HandleConn(c net.Conn) {
Conn: clientConn,
WorkspaceID: workspaceId,
InstanceID: wsInfo.InstanceID,
OwnerUserId: wsInfo.OwnerUserId,
WorkspacePrivateKey: key,
}
remoteAddr := wsInfo.IPAddress + ":23001"
Expand Down

0 comments on commit 2dd0a29

Please sign in to comment.