Skip to content

Commit 24f61c7

Browse files
utam0kroboquat
authored andcommitted
ws-manager: Redact logs of a workspace status.
1 parent d46531d commit 24f61c7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ func (m *Manager) dropSubscriber(dropouts []string) {
13331333

13341334
// onChange is the default OnChange implementation which publishes workspace status updates to subscribers
13351335
func (m *Manager) onChange(ctx context.Context, status *api.WorkspaceStatus) {
1336-
log := log.WithFields(log.OWI(status.Metadata.Owner, status.Metadata.MetaId, status.Id))
1336+
clog := log.WithFields(log.OWI(status.Metadata.Owner, status.Metadata.MetaId, status.Id))
13371337

13381338
header := make(map[string]string)
13391339
span := opentracing.SpanFromContext(ctx)
@@ -1344,7 +1344,7 @@ func (m *Manager) onChange(ctx context.Context, status *api.WorkspaceStatus) {
13441344
// if the error was caused by the span coming from the Noop tracer - ignore it.
13451345
// This can happen if the workspace doesn't have a span associated with it, then we resort to creating Noop spans.
13461346
if _, isNoopTracer := span.Tracer().(opentracing.NoopTracer); !isNoopTracer {
1347-
log.WithError(err).Debug("unable to extract tracing information - trace will be broken")
1347+
clog.WithError(err).Debug("unable to extract tracing information - trace will be broken")
13481348
}
13491349
} else {
13501350
for k, v := range tracingHeader {
@@ -1367,10 +1367,14 @@ func (m *Manager) onChange(ctx context.Context, status *api.WorkspaceStatus) {
13671367
// they represent out-of-the-ordinary situations.
13681368
// We attempt to use the GCP Error Reporting for this, hence log these situations as errors.
13691369
if status.Conditions.Failed != "" {
1370-
log.WithField("status", status).Error("workspace failed")
1370+
status, _ := protojson.Marshal(status)
1371+
safeStatus, _ := log.RedactJSON(status)
1372+
clog.WithField("status", safeStatus).Error("workspace failed")
13711373
}
13721374
if status.Phase == 0 {
1373-
log.WithField("status", status).Error("workspace in UNKNOWN phase")
1375+
status, _ := protojson.Marshal(status)
1376+
safeStatus, _ := log.RedactJSON(status)
1377+
clog.WithField("status", safeStatus).Error("workspace in UNKNOWN phase")
13741378
}
13751379
}
13761380

0 commit comments

Comments
 (0)