Skip to content

Commit 662bee1

Browse files
committed
[supervisor] implement sendHeartbeat method
1 parent 1fecbc5 commit 662bee1

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

components/supervisor/pkg/serverapi/publicapi.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type APIInterface interface {
3333
OpenPort(ctx context.Context, port *gitpod.WorkspaceInstancePort) (res *gitpod.WorkspaceInstancePort, err error)
3434
UpdateGitStatus(ctx context.Context, status *gitpod.WorkspaceInstanceRepoStatus) (err error)
3535
WorkspaceUpdates(ctx context.Context) (<-chan *gitpod.WorkspaceInstance, error)
36+
SendHeartbeat(ctx context.Context) (err error)
3637

3738
// Metrics
3839
RegisterMetrics(registry *prometheus.Registry) error
@@ -69,6 +70,29 @@ type Service struct {
6970
apiMetrics *ClientMetrics
7071
}
7172

73+
// SendHeartbeat implements APIInterface.
74+
func (s *Service) SendHeartbeat(ctx context.Context) (err error) {
75+
if s == nil {
76+
return errNotConnected
77+
}
78+
startTime := time.Now()
79+
defer func() {
80+
s.apiMetrics.ProcessMetrics("SendHeartbeat", err, startTime)
81+
}()
82+
83+
workspaceID := s.cfg.WorkspaceID
84+
service := v1.NewIDEClientServiceClient(s.publicAPIConn)
85+
86+
payload := &v1.SendHeartbeatRequest{
87+
WorkspaceId: workspaceID,
88+
}
89+
_, err = service.SendHeartbeat(ctx, payload)
90+
if err != nil {
91+
log.WithField("method", "SendHeartbeat").WithError(err).Error("failed to call PublicAPI")
92+
}
93+
return err
94+
}
95+
7296
var _ APIInterface = (*Service)(nil)
7397

7498
func NewServerApiService(ctx context.Context, cfg *ServiceConfig, tknsrv api.TokenServiceServer) *Service {
@@ -80,6 +104,7 @@ func NewServerApiService(ctx context.Context, cfg *ServiceConfig, tknsrv api.Tok
80104
"function:openPort",
81105
"function:trackEvent",
82106
"function:getWorkspace",
107+
"function:sendHeartBeat",
83108
},
84109
})
85110
if err != nil {

components/supervisor/pkg/supervisor/services.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ func (is *InfoService) WorkspaceInfo(ctx context.Context, req *api.WorkspaceInfo
732732

733733
// ControlService implements the supervisor control service.
734734
type ControlService struct {
735-
portsManager *ports.Manager
735+
portsManager *ports.Manager
736+
gitpodService serverapi.APIInterface
736737

737738
privateKey string
738739
publicKey string
@@ -874,6 +875,11 @@ func (c *ControlService) CreateDebugEnv(ctx context.Context, req *api.CreateDebu
874875
}, nil
875876
}
876877

878+
func (c *ControlService) SendHeartBeat(ctx context.Context, req *api.SendHeartBeatRequest) (*api.SendHeartBeatResponse, error) {
879+
err := c.gitpodService.SendHeartbeat(ctx)
880+
return &api.SendHeartBeatResponse{}, err
881+
}
882+
877883
// ContentState signals the workspace content state.
878884
type ContentState interface {
879885
MarkContentReady(src csapi.WorkspaceInitSource)

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func Run(options ...RunOption) {
389389
RegistrableTokenService{Service: tokenService},
390390
notificationService,
391391
NewInfoService(cfg, cstate, gitpodService),
392-
&ControlService{portsManager: portMgmt},
392+
&ControlService{portsManager: portMgmt, gitpodService: gitpodService},
393393
&portService{portsManager: portMgmt},
394394
&taskService{
395395
wg: taskServiceWg,

0 commit comments

Comments
 (0)