Skip to content

Commit e1b335c

Browse files
sagor999roboquat
authored andcommitted
[ws-manager] change workspace state tracing
1 parent 2e55f9c commit e1b335c

37 files changed

+18
-115
lines changed

components/common-go/kubernetes/kubernetes.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ const (
3737
// ServiceTypeLabel help differentiate between port service and IDE service
3838
ServiceTypeLabel = "serviceType"
3939

40-
// TraceIDAnnotation adds a Jaeger/OpenTracing header to the pod so that we can trace it's behaviour
41-
TraceIDAnnotation = "gitpod/traceid"
42-
4340
// CPULimitAnnotation enforces a strict CPU limit on a workspace by virtue of ws-daemon
4441
CPULimitAnnotation = "gitpod.io/cpuLimit"
4542

components/ws-manager/pkg/manager/create.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"time"
1818

1919
"github.com/imdario/mergo"
20-
"github.com/opentracing/opentracing-go"
2120
"golang.org/x/xerrors"
2221
"google.golang.org/grpc/codes"
2322
"google.golang.org/grpc/status"
@@ -362,7 +361,6 @@ func (m *Manager) createDefiniteWorkspacePod(startContext *startWorkspaceContext
362361
kubernetes.WorkspaceAdmissionAnnotation: admissionLevel,
363362
kubernetes.WorkspaceImageSpecAnnotation: imageSpec,
364363
kubernetes.OwnerTokenAnnotation: startContext.OwnerToken,
365-
wsk8s.TraceIDAnnotation: startContext.TraceID,
366364
attemptingToCreatePodAnnotation: "true",
367365
// TODO(cw): post Kubernetes 1.19 use GA form for settings those profiles
368366
"container.apparmor.security.beta.kubernetes.io/workspace": "unconfined",
@@ -856,8 +854,7 @@ func (m *Manager) createDefaultSecurityContext() (*corev1.SecurityContext, error
856854
}
857855

858856
func (m *Manager) newStartWorkspaceContext(ctx context.Context, req *api.StartWorkspaceRequest) (res *startWorkspaceContext, err error) {
859-
// we deliberately do not shadow ctx here as we need the original context later to extract the TraceID
860-
span, ctx := tracing.FromContext(ctx, "newStartWorkspaceContext")
857+
span, _ := tracing.FromContext(ctx, "newStartWorkspaceContext")
861858
defer tracing.FinishSpan(span, &err)
862859

863860
workspaceType := strings.ToLower(api.WorkspaceType_name[int32(req.Type)])
@@ -881,10 +878,6 @@ func (m *Manager) newStartWorkspaceContext(ctx context.Context, req *api.StartWo
881878
return nil, xerrors.Errorf("cannot create owner token: %w", err)
882879
}
883880

884-
workspaceSpan := opentracing.StartSpan("workspace", opentracing.FollowsFrom(opentracing.SpanFromContext(ctx).Context()))
885-
traceID := tracing.GetTraceID(workspaceSpan)
886-
defer tracing.FinishSpan(workspaceSpan, &err)
887-
888881
clsName := req.Spec.Class
889882
if _, ok := m.Config.WorkspaceClasses[req.Spec.Class]; clsName == "" || !ok {
890883
// For the time being, if the requested workspace class is unknown, or if
@@ -927,7 +920,6 @@ func (m *Manager) newStartWorkspaceContext(ctx context.Context, req *api.StartWo
927920
IDEPort: 23000,
928921
SupervisorPort: 22999,
929922
WorkspaceURL: workspaceURL,
930-
TraceID: traceID,
931923
Headless: headless,
932924
Class: class,
933925
VolumeSnapshot: volumeSnapshot,

components/ws-manager/pkg/manager/imagespec.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"encoding/base64"
1010

11-
"github.com/opentracing/opentracing-go"
1211
"golang.org/x/xerrors"
1312
"google.golang.org/grpc/codes"
1413
"google.golang.org/grpc/status"
@@ -29,17 +28,7 @@ func (m *Manager) GetImageSpec(ctx context.Context, req *regapi.GetImageSpecRequ
2928
return nil, status.Error(codes.NotFound, "not found")
3029
}
3130

32-
var (
33-
span opentracing.Span
34-
traceID, ok = pod.Annotations[wsk8s.TraceIDAnnotation]
35-
)
36-
if ok {
37-
spanCtx := tracing.FromTraceID(traceID)
38-
span = opentracing.StartSpan("GetImageSpec", opentracing.FollowsFrom(spanCtx))
39-
ctx = opentracing.ContextWithSpan(ctx, span)
40-
} else {
41-
span, ctx = tracing.FromContext(ctx, "GetImageSpec")
42-
}
31+
span, ctx := tracing.FromContext(ctx, "GetImageSpec")
4332
tracing.ApplyOWI(span, wsk8s.GetOWIFromObject(&pod.ObjectMeta))
4433
defer func() {
4534
tracing.LogMessageSafe(span, "resp", resp)

components/ws-manager/pkg/manager/manager.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ type startWorkspaceContext struct {
7575
IDEPort int32 `json:"idePort"`
7676
SupervisorPort int32 `json:"supervisorPort"`
7777
WorkspaceURL string `json:"workspaceURL"`
78-
TraceID string `json:"traceID"`
7978
Headless bool `json:"headless"`
8079
Class *config.WorkspaceClass `json:"class"`
8180
VolumeSnapshot *workspaceVolumeSnapshotStatus `json:"volumeSnapshot"`

components/ws-manager/pkg/manager/monitor.go

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (m *Monitor) onPodEvent(evt watch.Event) error {
204204
// subsequent handling of the matter or not. However, we want to respond quickly to events,
205205
// thus we start OnChange as a goroutine.
206206
// BEWARE beyond this point one must not modify status anymore - we've already sent it out BEWARE
207-
span := m.traceWorkspace("handle-"+status.Phase.String(), wso)
207+
span := m.traceWorkspaceState(status.Phase.String(), wso)
208208
ctx = opentracing.ContextWithSpan(context.Background(), span)
209209
onChangeDone := make(chan bool)
210210
go func() {
@@ -351,14 +351,11 @@ func actOnPodEvent(ctx context.Context, m actingManager, status *api.WorkspaceSt
351351
return xerrors.Errorf("cannot add gitpod finalizer: %w", err)
352352
}
353353

354-
// once a regular workspace is up and running, we'll remove the traceID information so that the parent span
355-
// ends once the workspace has started.
356-
//
357-
// Also, in case the pod gets evicted we would not know the hostIP that pod ran on anymore.
354+
// In case the pod gets evicted we would not know the hostIP that pod ran on anymore.
358355
// In preparation for those cases, we'll add it as an annotation.
359-
err := m.markWorkspace(ctx, workspaceID, deleteMark(wsk8s.TraceIDAnnotation), addMark(nodeNameAnnotation, wso.NodeName()))
356+
err := m.markWorkspace(ctx, workspaceID, addMark(nodeNameAnnotation, wso.NodeName()))
360357
if err != nil {
361-
log.WithError(err).Warn("was unable to remove traceID and/or add host IP annotation from/to workspace")
358+
log.WithError(err).Warn("was unable to add host IP annotation from/to workspace")
362359
}
363360
}
364361

@@ -512,25 +509,14 @@ func (m *Monitor) writeEventTraceLog(status *api.WorkspaceStatus, wso *workspace
512509
json.NewEncoder(out).Encode(entry)
513510
}
514511

515-
// traceWorkspace updates the workspace span if the workspace has OpenTracing information associated with it.
516-
// The resulting context may be associated with trace information that can be used to trace the effects of this status
517-
// update throughout the rest of the system.
518-
func (m *Monitor) traceWorkspace(occasion string, wso *workspaceObjects) opentracing.Span {
519-
var traceID string
520-
if traceID == "" && wso.Pod != nil {
521-
traceID = wso.Pod.Annotations[wsk8s.TraceIDAnnotation]
522-
}
523-
spanCtx := tracing.FromTraceID(traceID)
524-
if spanCtx == nil {
525-
// no trace information available
526-
return opentracing.NoopTracer{}.StartSpan("noop")
527-
}
528-
529-
span := opentracing.StartSpan(fmt.Sprintf("/workspace/%s", occasion), opentracing.FollowsFrom(spanCtx))
512+
// traceWorkspaceState creates a new span that records the phase of workspace
513+
func (m *Monitor) traceWorkspaceState(state string, wso *workspaceObjects) opentracing.Span {
514+
span := opentracing.StartSpan(fmt.Sprintf("/workspace/%s", state))
530515
if wso.Pod != nil {
531516
tracing.ApplyOWI(span, wsk8s.GetOWIFromObject(&wso.Pod.ObjectMeta))
517+
span.LogKV("timeToState", time.Since(wso.Pod.CreationTimestamp.Time))
532518
}
533-
span.LogKV("occasion", occasion)
519+
span.LogKV("wsState", state)
534520

535521
// OpenTracing does not support creating a span from a SpanContext https://github.com/opentracing/specification/issues/81.
536522
// Until that changes we just finish the span immediately after calling on-change.

components/ws-manager/pkg/manager/testdata/actOnPodEvent_firstUserActivity_RUNNING.golden

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
"Func": "markWorkspace",
1313
"Params": {
1414
"annotations": [
15-
{
16-
"Name": "gitpod/traceid",
17-
"Value": "",
18-
"Delete": true
19-
},
2015
{
2116
"Name": "gitpod.io/nodeName",
2217
"Value": "gke-staging--gitpod--workspace-pool-2-331a2b32-mgbq",
@@ -27,4 +22,4 @@
2722
}
2823
}
2924
]
30-
}
25+
}

components/ws-manager/pkg/manager/testdata/actOnPodEvent_imagespec_RUNNING00.golden

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
"Func": "markWorkspace",
1313
"Params": {
1414
"annotations": [
15-
{
16-
"Name": "gitpod/traceid",
17-
"Value": "",
18-
"Delete": true
19-
},
2015
{
2116
"Name": "gitpod.io/nodeName",
2217
"Value": "gke-gitpod-dev-worker-pool-1-3df476cf-qxwr",
@@ -27,4 +22,4 @@
2722
}
2823
}
2924
]
30-
}
25+
}

components/ws-manager/pkg/manager/testdata/actOnPodEvent_interrupted_networkNotReady_1_event_only.golden

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
"Func": "markWorkspace",
1313
"Params": {
1414
"annotations": [
15-
{
16-
"Name": "gitpod/traceid",
17-
"Value": "",
18-
"Delete": true
19-
},
2015
{
2116
"Name": "gitpod.io/nodeName",
2217
"Value": "gke-production--gitp-workspace-pool-1-ee6c94af-h6lj",
@@ -27,4 +22,4 @@
2722
}
2823
}
2924
]
30-
}
25+
}

components/ws-manager/pkg/manager/testdata/actOnPodEvent_interrupted_networkNotReady_3_recovered_CONSTRUCTED.golden

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
"Func": "markWorkspace",
1313
"Params": {
1414
"annotations": [
15-
{
16-
"Name": "gitpod/traceid",
17-
"Value": "",
18-
"Delete": true
19-
},
2015
{
2116
"Name": "gitpod.io/nodeName",
2217
"Value": "gke-production--gitp-workspace-pool-1-c73d13c7-fzbk",
@@ -27,4 +22,4 @@
2722
}
2823
}
2924
]
30-
}
25+
}

components/ws-manager/pkg/manager/testdata/actOnPodEvent_metadata.golden

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
"Func": "markWorkspace",
1313
"Params": {
1414
"annotations": [
15-
{
16-
"Name": "gitpod/traceid",
17-
"Value": "",
18-
"Delete": true
19-
},
2015
{
2116
"Name": "gitpod.io/nodeName",
2217
"Value": "minikube",
@@ -27,4 +22,4 @@
2722
}
2823
}
2924
]
30-
}
25+
}

components/ws-manager/pkg/manager/testdata/actOnPodEvent_ownerToken.golden

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
"Func": "markWorkspace",
1313
"Params": {
1414
"annotations": [
15-
{
16-
"Name": "gitpod/traceid",
17-
"Value": "",
18-
"Delete": true
19-
},
2015
{
2116
"Name": "gitpod.io/nodeName",
2217
"Value": "gke-staging--gitpod--workspace-pool-2-331a2b32-mgbq",
@@ -27,4 +22,4 @@
2722
}
2823
}
2924
]
30-
}
25+
}

components/ws-manager/pkg/manager/testdata/actOnPodEvent_stoppedByRequest_000_RUNNING00.golden

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
"Func": "markWorkspace",
2020
"Params": {
2121
"annotations": [
22-
{
23-
"Name": "gitpod/traceid",
24-
"Value": "",
25-
"Delete": true
26-
},
2722
{
2823
"Name": "gitpod.io/nodeName",
2924
"Value": "gke-core-dev-workspace-3-a69c4dd8-jqzs",
@@ -34,4 +29,4 @@
3429
}
3530
}
3631
]
37-
}
32+
}

components/ws-manager/pkg/manager/testdata/cdwp_admission.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "test-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_affinity.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "test-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_class.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "test-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_class_notfound.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "test-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_customcerts.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "test-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_debug_workspace_pod.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "test-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_empty_resource_req.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "test-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_envvars.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "test-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_fixedresources.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"gitpod/never-ready": "true",
2929
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
3030
"gitpod/servicePrefix": "foobarservice",
31-
"gitpod/traceid": "",
3231
"gitpod/url": "test-foobarservice-gitpod.io",
3332
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3433
},

components/ws-manager/pkg/manager/testdata/cdwp_fullworkspacebackup.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"gitpod/never-ready": "true",
3030
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
3131
"gitpod/servicePrefix": "foobarservice",
32-
"gitpod/traceid": "",
3332
"gitpod/url": "test-foobarservice-gitpod.io",
3433
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3534
},

components/ws-manager/pkg/manager/testdata/cdwp_imagebuild.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "foobar-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_imagebuild_template.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "foobar-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_no_ideimage.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "test-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

components/ws-manager/pkg/manager/testdata/cdwp_prebuild.golden

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"gitpod/never-ready": "true",
2828
"gitpod/ownerToken": "%7J'[Of/8NDiWE+9F,I6^Jcj_1\u0026}-F8p",
2929
"gitpod/servicePrefix": "foobarservice",
30-
"gitpod/traceid": "",
3130
"gitpod/url": "foobar-foobarservice-gitpod.io",
3231
"seccomp.security.alpha.kubernetes.io/pod": "localhost/workspace-default"
3332
},

0 commit comments

Comments
 (0)