Skip to content

Commit c8ec22e

Browse files
committed
[supervisor] add readiness track
1 parent acd580c commit c8ec22e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

components/supervisor/pkg/supervisor/supervisor.go

+43
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ func Run(options ...RunOption) {
232232
if cfg.DesktopIDE != nil {
233233
desktopIdeReady = &ideReadyState{cond: sync.NewCond(&sync.Mutex{})}
234234
}
235+
go trackReadiness(ctx, gitpodService, cfg, cstate, ideReady, desktopIdeReady)
235236
tokenService.provider[KindGit] = []tokenProvider{NewGitTokenProvider(gitpodService, cfg.WorkspaceConfig, notificationService)}
236237

237238
go gitpodConfigService.Watch(ctx)
@@ -1554,6 +1555,48 @@ func analyseConfigChanges(ctx context.Context, wscfg *Config, w analytics.Writer
15541555
}
15551556
}
15561557

1558+
func trackReadiness(ctx context.Context, gitpodService *gitpod.APIoverJSONRPC, cfg *Config, cstate *InMemoryContentState, ideReady *ideReadyState, desktopIdeReady *ideReadyState) {
1559+
type SupervisorReadiness struct {
1560+
Kind string `json:"kind,omitempty"`
1561+
WorkspaceId string `json:"workspaceId,omitempty"`
1562+
WorkspaceInstanceId string `json:"instanceId,omitempty"`
1563+
Timestamp int64 `json:"timestamp,omitempty"`
1564+
}
1565+
trackFn := func(ctx context.Context, gitpodService *gitpod.APIoverJSONRPC, cfg *Config, kind string) {
1566+
err := gitpodService.TrackEvent(ctx, &gitpod.RemoteTrackMessage{
1567+
Event: "supervisor_readiness",
1568+
Properties: SupervisorReadiness{
1569+
Kind: kind,
1570+
WorkspaceId: cfg.WorkspaceID,
1571+
WorkspaceInstanceId: cfg.WorkspaceInstanceID,
1572+
Timestamp: time.Now().UnixMilli(),
1573+
},
1574+
})
1575+
if err != nil {
1576+
log.WithError(err).Error("error tracking supervisor_readiness")
1577+
}
1578+
}
1579+
const (
1580+
readinessKindContent = "content"
1581+
readinessKindIDE = "ide"
1582+
readinessKindDesktopIDE = "ide-desktop"
1583+
)
1584+
go func() {
1585+
<-cstate.ContentReady()
1586+
trackFn(ctx, gitpodService, cfg, readinessKindContent)
1587+
}()
1588+
go func() {
1589+
<-ideReady.Wait()
1590+
trackFn(ctx, gitpodService, cfg, readinessKindIDE)
1591+
}()
1592+
if cfg.DesktopIDE != nil {
1593+
go func() {
1594+
<-desktopIdeReady.Wait()
1595+
trackFn(ctx, gitpodService, cfg, readinessKindDesktopIDE)
1596+
}()
1597+
}
1598+
}
1599+
15571600
func runAsGitpodUser(cmd *exec.Cmd) *exec.Cmd {
15581601
if cmd.SysProcAttr == nil {
15591602
cmd.SysProcAttr = &syscall.SysProcAttr{}

0 commit comments

Comments
 (0)