Skip to content

Commit

Permalink
[TEST ONLY] add track for ssh channel open
Browse files Browse the repository at this point in the history
  • Loading branch information
iQQBot committed Jun 28, 2022
1 parent 2dd0a29 commit b50b273
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions components/ws-proxy/pkg/sshproxy/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"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"
"github.com/google/uuid"
"golang.org/x/net/context"
)

Expand All @@ -30,6 +31,8 @@ func (s *Server) ChannelForward(ctx context.Context, session *Session, targetCon
log.WithFields(log.OWI("", session.WorkspaceID, session.InstanceID)).Error("accept origin channel failed")
return
}
channelId := uuid.New().String()
TrackSSHConnectionChannel(session, originChannel.ChannelType(), channelId, "open")
if originChannel.ChannelType() == "session" {
originChan = startHeartbeatingChannel(originChan, s.Heartbeater, session)
}
Expand Down Expand Up @@ -89,6 +92,7 @@ func (s *Server) ChannelForward(ctx context.Context, session *Session, targetCon
go forward(targetReqs, originChan)

wg.Wait()
TrackSSHConnectionChannel(session, originChannel.ChannelType(), channelId, "close")
log.WithFields(log.OWI("", session.WorkspaceID, session.InstanceID)).Debug("session forward stop")
}

Expand All @@ -104,6 +108,19 @@ func TrackIDECloseSignal(session *Session) {
})
}

func TrackSSHConnectionChannel(session *Session, channel string, uuid string, status string) {
propertics := make(map[string]interface{})
propertics["workspaceId"] = session.WorkspaceID
propertics["instanceId"] = session.InstanceID
propertics["channel"] = channel
propertics["status"] = status
tracker.Track(analytics.TrackMessage{
Identity: analytics.Identity{UserID: session.OwnerUserId},
Event: "ssh_connection_channel",
Properties: propertics,
})
}

func startHeartbeatingChannel(c ssh.Channel, heartbeat Heartbeat, session *Session) ssh.Channel {
ctx, cancel := context.WithCancel(context.Background())
res := &heartbeatingChannel{
Expand Down

0 comments on commit b50b273

Please sign in to comment.