Anton Kosyakov 6533581a0e [ssh-proxy] only mark first active when user establish ssh connection
VS Code Remote SSH will reestablish a ssh connection even if window is not uesd.
It will retrigger heartbeat over and over in SSH Gateway.
SSH Gateway should only triggert heartbeat if pty sessions is present.

Co-authored-by: Pudong <tianshi8650@gmail.com>
2022-11-09 21:46:39 +02:00

42 lines
1.2 KiB
Go

// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.
package sshproxy
import (
"context"
"time"
"github.com/gitpod-io/gitpod/common-go/log"
wsmanapi "github.com/gitpod-io/gitpod/ws-manager/api"
)
type Heartbeat interface {
// SendHeartbeat sends a heartbeat for a workspace
SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool)
}
type noHeartbeat struct{}
func (noHeartbeat) SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool) {}
type WorkspaceManagerHeartbeat struct {
Client wsmanapi.WorkspaceManagerClient
}
func (m *WorkspaceManagerHeartbeat) SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_, err := m.Client.MarkActive(ctx, &wsmanapi.MarkActiveRequest{
Id: instanceID,
Closed: isClosed,
IgnoreIfActive: ignoreIfActive,
})
if err != nil {
log.WithError(err).Warn("cannot send heartbeat for workspace instance")
} else {
log.WithField("instanceId", instanceID).Debug("sent heartbeat to ws-manager")
}
}