Skip to content

Commit 808d58c

Browse files
utam0kroboquat
authored andcommitted
ws-daemon: Plant some traces around the hooks
1 parent 327f955 commit 808d58c

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

components/ws-daemon/pkg/content/hooks.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import (
1111
"os"
1212

1313
"github.com/gitpod-io/gitpod/common-go/log"
14+
"github.com/gitpod-io/gitpod/common-go/tracing"
1415
"github.com/gitpod-io/gitpod/content-service/pkg/initializer"
1516
"github.com/gitpod-io/gitpod/content-service/pkg/storage"
1617
"github.com/gitpod-io/gitpod/ws-daemon/api"
1718
"github.com/gitpod-io/gitpod/ws-daemon/pkg/internal/session"
1819
"github.com/gitpod-io/gitpod/ws-daemon/pkg/iws"
1920
"github.com/gitpod-io/gitpod/ws-daemon/pkg/quota"
21+
"github.com/opentracing/opentracing-go"
2022
"golang.org/x/xerrors"
2123
)
2224

@@ -50,7 +52,10 @@ func workspaceLifecycleHooks(cfg Config, kubernetesNamespace string, workspaceEx
5052

5153
// hookSetupRemoteStorage configures the remote storage for a workspace
5254
func hookSetupRemoteStorage(cfg Config) session.WorkspaceLivecycleHook {
53-
return func(ctx context.Context, ws *session.Workspace) error {
55+
return func(ctx context.Context, ws *session.Workspace) (err error) {
56+
span, ctx := opentracing.StartSpanFromContext(ctx, "hook.SetupRemoteStorage")
57+
defer tracing.FinishSpan(span, &err)
58+
5459
if _, ok := ws.NonPersistentAttrs[session.AttrRemoteStorage]; !ws.RemoteStorageDisabled && !ok {
5560
remoteStorage, err := storage.NewDirectAccess(&cfg.Storage)
5661
if err != nil {
@@ -75,7 +80,10 @@ func hookSetupRemoteStorage(cfg Config) session.WorkspaceLivecycleHook {
7580
}
7681

7782
// hookSetupWorkspaceLocation recreates the workspace location
78-
func hookSetupWorkspaceLocation(ctx context.Context, ws *session.Workspace) error {
83+
func hookSetupWorkspaceLocation(ctx context.Context, ws *session.Workspace) (err error) {
84+
//nolint:ineffassign
85+
span, _ := opentracing.StartSpanFromContext(ctx, "hook.SetupWorkspaceLocation")
86+
defer tracing.FinishSpan(span, &err)
7987
location := ws.Location
8088

8189
// 1. Clean out the workspace directory
@@ -90,7 +98,7 @@ func hookSetupWorkspaceLocation(ctx context.Context, ws *session.Workspace) erro
9098
}
9199

92100
// Chown the workspace directory
93-
err := os.Chown(location, initializer.GitpodUID, initializer.GitpodGID)
101+
err = os.Chown(location, initializer.GitpodUID, initializer.GitpodGID)
94102
if err != nil {
95103
return xerrors.Errorf("cannot create workspace: %w", err)
96104
}
@@ -99,7 +107,10 @@ func hookSetupWorkspaceLocation(ctx context.Context, ws *session.Workspace) erro
99107

100108
// hookInstallQuota enforces filesystem quota on the workspace location (if the filesystem supports it)
101109
func hookInstallQuota(xfs *quota.XFS, isHard bool) session.WorkspaceLivecycleHook {
102-
return func(ctx context.Context, ws *session.Workspace) error {
110+
return func(ctx context.Context, ws *session.Workspace) (err error) {
111+
span, _ := opentracing.StartSpanFromContext(ctx, "hook.InstallQuota")
112+
defer tracing.FinishSpan(span, &err)
113+
103114
if xfs == nil {
104115
return nil
105116
}
@@ -114,7 +125,6 @@ func hookInstallQuota(xfs *quota.XFS, isHard bool) session.WorkspaceLivecycleHoo
114125

115126
var (
116127
prj int
117-
err error
118128
)
119129
if ws.XFSProjectID != 0 {
120130
xfs.RegisterProject(ws.XFSProjectID)
@@ -134,7 +144,10 @@ func hookInstallQuota(xfs *quota.XFS, isHard bool) session.WorkspaceLivecycleHoo
134144

135145
// hookRemoveQuota removes the filesystem quota, freeing up resources if need be
136146
func hookRemoveQuota(xfs *quota.XFS) session.WorkspaceLivecycleHook {
137-
return func(ctx context.Context, ws *session.Workspace) error {
147+
return func(ctx context.Context, ws *session.Workspace) (err error) {
148+
span, _ := opentracing.StartSpanFromContext(ctx, "hook.RemoveQuota")
149+
defer tracing.FinishSpan(span, &err)
150+
138151
if xfs == nil {
139152
return nil
140153
}

components/ws-daemon/pkg/iws/iws.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,26 @@ var (
8787
// ServeWorkspace establishes the IWS server for a workspace
8888
func ServeWorkspace(uidmapper *Uidmapper, fsshift api.FSShiftMethod, cgroupMountPoint string) func(ctx context.Context, ws *session.Workspace) error {
8989
return func(ctx context.Context, ws *session.Workspace) (err error) {
90+
span, _ := opentracing.StartSpanFromContext(ctx, "iws.ServeWorkspace")
91+
defer tracing.FinishSpan(span, &err)
9092
if _, running := ws.NonPersistentAttrs[session.AttrWorkspaceServer]; running {
93+
span.SetTag("alreadyRunning", true)
9194
return nil
9295
}
9396

94-
//nolint:ineffassign
95-
span, ctx := opentracing.StartSpanFromContext(ctx, "iws.ServeWorkspace")
96-
defer tracing.FinishSpan(span, &err)
97-
98-
helper := &InWorkspaceServiceServer{
97+
iws := &InWorkspaceServiceServer{
9998
Uidmapper: uidmapper,
10099
Session: ws,
101100
FSShift: fsshift,
102101
CGroupMountPoint: cgroupMountPoint,
103102
}
104-
err = helper.Start()
103+
err = iws.Start()
105104
if err != nil {
106105
return xerrors.Errorf("cannot start in-workspace-helper server: %w", err)
107106
}
108107

109108
log.WithFields(ws.OWI()).Debug("established IWS server")
110-
ws.NonPersistentAttrs[session.AttrWorkspaceServer] = helper.Stop
109+
ws.NonPersistentAttrs[session.AttrWorkspaceServer] = iws.Stop
111110

112111
return nil
113112
}
@@ -116,7 +115,7 @@ func ServeWorkspace(uidmapper *Uidmapper, fsshift api.FSShiftMethod, cgroupMount
116115
// StopServingWorkspace stops a previously started workspace server
117116
func StopServingWorkspace(ctx context.Context, ws *session.Workspace) (err error) {
118117
//nolint:ineffassign
119-
span, ctx := opentracing.StartSpanFromContext(ctx, "iws.StopServingWorkspace")
118+
span, _ := opentracing.StartSpanFromContext(ctx, "iws.StopServingWorkspace")
120119
defer tracing.FinishSpan(span, &err)
121120

122121
rawStop, ok := ws.NonPersistentAttrs[session.AttrWorkspaceServer]

0 commit comments

Comments
 (0)