Skip to content

[ws-manager-mk2] redact log #18906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 16, 2023
Merged

[ws-manager-mk2] redact log #18906

merged 4 commits into from
Oct 16, 2023

Conversation

iQQBot
Copy link
Contributor

@iQQBot iQQBot commented Oct 10, 2023

Description

This PR introduces a new function DeepCopyStruct in scrubber, it can copy a struct and do scrub.

Summary generated by Copilot

🤖 Generated by Copilot at dbc828e

This pull request enhances the logging and scrubbing features of the ws-manager-mk2 component. It adds a new feature to the scrubber package to deep copy and scrub struct values, and uses it to log values securely with the logrusr package. It also refactors the logging logic in the workspace controller and removes some unused code.

Related Issue(s)

Fixes ENG-872

How to test

Documentation

Preview status

Gitpod was successfully deployed to your preview environment.

Build Options

Build
  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer
  • analytics=segment
  • with-dedicated-emulation
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated
Preview Environment / Integration Tests
  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh. If enabled, with-preview and with-large-vm will be enabled.
  • with-monitoring

/hold

@iQQBot iQQBot force-pushed the pd/ws-man-2-redact-log branch from 74894c7 to 6666333 Compare October 10, 2023 20:15
@roboquat roboquat added size/L and removed size/M labels Oct 10, 2023
@iQQBot iQQBot force-pushed the pd/ws-man-2-redact-log branch 3 times, most recently from 9812d55 to a64322f Compare October 11, 2023 09:36
@iQQBot iQQBot changed the title [test] ws-manager-mk2 redact log [ws-manager-mk2] redact log Oct 12, 2023
@roboquat roboquat added size/XL and removed size/L labels Oct 12, 2023
@iQQBot iQQBot force-pushed the pd/ws-man-2-redact-log branch from f4b3b79 to 32450c0 Compare October 12, 2023 15:36
@iQQBot iQQBot marked this pull request as ready for review October 12, 2023 15:37
@iQQBot iQQBot requested a review from a team as a code owner October 12, 2023 15:37
@WVerlaek
Copy link
Member

Thanks - do you have examples of how e.g. the workspace status/pod status fields show now in the logs? Which fields are included and which are redacted?

@iQQBot
Copy link
Contributor Author

iQQBot commented Oct 12, 2023

Thanks - do you have examples of how e.g. the workspace status/pod status fields show now in the logs? Which fields are included and which are redacted?

the pod status behavior same as before, if you need an example, I need to wait for the preview environment.

@iQQBot
Copy link
Contributor Author

iQQBot commented Oct 12, 2023

@WVerlaek see example below

Logs example
{
  "Workspace": {
    "name": "3a6affd2-e7bd-4a78-861c-5d85d90a9b06",
    "namespace": "default"
  },
  "controller": "workspace",
  "controllerGroup": "workspace.gitpod.io",
  "controllerKind": "Workspace",
  "level": "info",
  "message": "updating workspace status",
  "name": "3a6affd2-e7bd-4a78-861c-5d85d90a9b06",
  "namespace": "default",
  "podStatus": {
    "phase": "Pending",
    "conditions": [
      {
        "type": "Initialized",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2023-10-12T16:21:37Z"
      },
      {
        "type": "Ready",
        "status": "False",
        "lastProbeTime": null,
        "lastTransitionTime": "2023-10-12T16:21:37Z",
        "reason": "ContainersNotReady",
        "message": "containers with unready status: [workspace]"
      },
      {
        "type": "ContainersReady",
        "status": "False",
        "lastProbeTime": null,
        "lastTransitionTime": "2023-10-12T16:21:37Z",
        "reason": "ContainersNotReady",
        "message": "containers with unready status: [workspace]"
      },
      {
        "type": "PodScheduled",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2023-10-12T16:21:37Z"
      }
    ],
    "hostIP": "10.128.0.80",
    "startTime": "2023-10-12T16:21:37Z",
    "containerStatuses": [
      {
        "name": "workspace",
        "state": {
          "waiting": {
            "reason": "ContainerCreating"
          }
        },
        "lastState": {},
        "ready": false,
        "restartCount": 0,
        "image": "reg.pd-ws-man-5c0d6febc1.preview.gitpod-dev.com:31750/remote/3a6affd2-e7bd-4a78-861c-5d85d90a9b06",
        "imageID": "",
        "started": false
      }
    ],
    "qosClass": "Burstable"
  },
  "reconcileID": "db55667b-b3bb-4c44-a9d6-bea57007ce26",
  "serviceContext": {
    "service": "ws-manager-mk2",
    "version": "commit-32450c07bf23c12a5a999aab6f2aa40527ce8552"
  },
  "severity": "INFO",
  "status": {
    "podStarts": 1,
    "url": "https://iqqbot-gofuse-05xczdztvll.ws-dev.pd-ws-man-5c0d6febc1.preview.gitpod-dev.com",
    "ownerToken": "[redacted]",
    "phase": "Creating",
    "conditions": [
      {
        "type": "Deployed",
        "status": "True",
        "lastTransitionTime": "2023-10-12T16:21:37Z",
        "reason": "Unknown",
        "message": ""
      },
      {
        "type": "Refresh",
        "status": "True",
        "lastTransitionTime": "2023-10-12T16:21:37Z",
        "reason": "Unknown",
        "message": ""
      },
      {
        "type": "ContentReady",
        "status": "True",
        "lastTransitionTime": "2023-10-12T16:21:49Z",
        "reason": "InitializationSuccess",
        "message": ""
      }
    ],
    "runtime": {
      "nodeName": "preview-pd-ws-man-5c0d6febc1",
      "podName": "ws-3a6affd2-e7bd-4a78-861c-5d85d90a9b06",
      "hostIP": "10.128.0.80"
    }
  },
  "time": "2023-10-12T16:21:49.19141569Z"
}

{
  "Workspace": {
    "name": "3a6affd2-e7bd-4a78-861c-5d85d90a9b06",
    "namespace": "default"
  },
  "controller": "workspace",
  "controllerGroup": "workspace.gitpod.io",
  "controllerKind": "Workspace",
  "level": "info",
  "message": "updating workspace status",
  "name": "3a6affd2-e7bd-4a78-861c-5d85d90a9b06",
  "namespace": "default",
  "podStatus": {
    "phase": "Running",
    "conditions": [
      {
        "type": "Initialized",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2023-10-12T16:21:37Z"
      },
      {
        "type": "Ready",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2023-10-12T16:23:07Z"
      },
      {
        "type": "ContainersReady",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2023-10-12T16:23:07Z"
      },
      {
        "type": "PodScheduled",
        "status": "True",
        "lastProbeTime": null,
        "lastTransitionTime": "2023-10-12T16:21:37Z"
      }
    ],
    "hostIP": "10.128.0.80",
    "podIP": "192.168.2.44",
    "podIPs": [
      {
        "ip": "192.168.2.44"
      }
    ],
    "startTime": "2023-10-12T16:21:37Z",
    "containerStatuses": [
      {
        "name": "workspace",
        "state": {
          "running": {
            "startedAt": "2023-10-12T16:23:02Z"
          }
        },
        "lastState": {},
        "ready": true,
        "restartCount": 0,
        "image": "reg.pd-ws-man-5c0d6febc1.preview.gitpod-dev.com:31750/remote/3a6affd2-e7bd-4a78-861c-5d85d90a9b06:latest",
        "imageID": "reg.pd-ws-man-5c0d6febc1.preview.gitpod-dev.com:[redacted:email]:82966070187b644e4a214db1c0c6cdf4a7d23091d57995215775b1c7118dfdfe",
        "containerID": "containerd://c1826ee417cf681629a679e4b3304112fb724c4eddeee1e9cfd7b07a2bb87a6d",
        "started": true
      }
    ],
    "qosClass": "Burstable"
  },
  "reconcileID": "491e10c0-c1c2-4122-af72-ae974bbbce87",
  "serviceContext": {
    "service": "ws-manager-mk2",
    "version": "commit-32450c07bf23c12a5a999aab6f2aa40527ce8552"
  },
  "severity": "INFO",
  "status": {
    "podStarts": 1,
    "url": "https://iqqbot-gofuse-05xczdztvll.ws-dev.pd-ws-man-5c0d6febc1.preview.gitpod-dev.com",
    "ownerToken": "[redacted]",
    "phase": "Running",
    "conditions": [
      {
        "type": "Deployed",
        "status": "True",
        "lastTransitionTime": "2023-10-12T16:21:37Z",
        "reason": "Unknown",
        "message": ""
      },
      {
        "type": "Refresh",
        "status": "True",
        "lastTransitionTime": "2023-10-12T16:21:37Z",
        "reason": "Unknown",
        "message": ""
      },
      {
        "type": "ContentReady",
        "status": "True",
        "lastTransitionTime": "2023-10-12T16:21:49Z",
        "reason": "InitializationSuccess",
        "message": ""
      },
      {
        "type": "EverReady",
        "status": "True",
        "lastTransitionTime": "2023-10-12T16:23:07Z",
        "reason": "Unknown",
        "message": ""
      },
      {
        "type": "FirstUserActivity",
        "status": "True",
        "lastTransitionTime": "2023-10-12T16:23:07Z",
        "reason": "MarkActiveRequest",
        "message": ""
      }
    ],
    "runtime": {
      "nodeName": "preview-pd-ws-man-5c0d6febc1",
      "podName": "ws-3a6affd2-e7bd-4a78-861c-5d85d90a9b06",
      "podIP": "192.168.2.44",
      "hostIP": "10.128.0.80"
    },
    "lastActivity": "2023-10-12T16:23:07Z"
  },
  "time": "2023-10-12T16:23:07.922931558Z"
}

@iQQBot
Copy link
Contributor Author

iQQBot commented Oct 12, 2023

"url": "https://iqqbot-gofuse-05xczdztvll.ws-dev.pd-ws-man-5c0d6febc1.preview.gitpod-dev.com",

actually, this url contains workspace id, but the scriber don't have rule to redact it

l := log.WithFields(logrus.Fields{})
l.Logger.SetReportCaller(false)
baseLogger := logrusr.New(l, logrusr.WithFormatter(func(i interface{}) interface{} {
return &scrubber.TrustedValueWrap{Value: scrubber.Default.DeepCopyStruct(i)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the perf implication of doing a deep copy? If I remember correctly, @akosyakov was running into perf issues when we performed deep scrubbing and the call we made is we'd only scrub a fixed depth and redact anything below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On complex and deep structures it was considerably slow, but in golang is still was negligible.
Our concern though was that we introduce it generically and don't want to make some hot path even slower by mistake, so decided to go with enforcing rather flat primitive properties. If this code is not on such path I would think it should be alright.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For log, it's fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the point is that delivery of updates now will be slowed down by deep scrubbing of workspace status, you need to decide how acceptable it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/gitpod-io/gitpod/pull/18906/files#diff-f99e73fcd35fa75f1bb44136fccd8d70d328d02372d9b4e7d7884f3f7c9abd61R128-R134

The workspace status used to be deep copied and then logged, so it has a relatively small impact on it.

Printing logs is not a hot path, and printing logs itself is also slow. Whether it's printing to stdout or to a file, it consumes I/O.

@akosyakov
Copy link
Member

actually, this url contains workspace id, but the scriber don't have rule to redact it

@iQQBot I'm not sure it is good idea to scrub each URL string, since regex is very expensive. If you know the structure maybe just scrub this property specifically on the top?

@iQQBot iQQBot force-pushed the pd/ws-man-2-redact-log branch from 32450c0 to 68e87af Compare October 13, 2023 08:33
@iQQBot iQQBot requested a review from a team as a code owner October 13, 2023 08:33
Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve to unblock, fine with scrubber changes

@WVerlaek
Copy link
Member

@iQQBot changes lgtm but still see the URL unscrubbed, do you want to do that in a follow-up pr?

@iQQBot
Copy link
Contributor Author

iQQBot commented Oct 16, 2023

changes lgtm but still see the URL unscrubbed, do you want to do that in a follow-up pr?

It seems that we can only enable regex for each field called url to clear the workspace id (maybe it's make sense), other than that we may need to make big changes to scrubber

@akosyakov
Copy link
Member

akosyakov commented Oct 16, 2023

Could you clarify which URLs? Also do you really want to log the entire workspace status? e.g. are you interested in ports?

if you are interested only let's say in phase and conditions log only them? You don't need even deep scrubbing then?

It could be good idea rather start small and add more info as you find it useful. In the past we over logged because of using deep structures.

@iQQBot
Copy link
Contributor Author

iQQBot commented Oct 16, 2023

Could you clarify which URLs?

image

Also do you really want to log the entire workspace status? e.g. are you interested in ports? if you are interested only let's say in phase and conditions log only them? You don't need even deep scrubbing then?

Personally, the pod status update would be debug level, but the cc @WVerlaek

@akosyakov
Copy link
Member

akosyakov commented Oct 16, 2023

for status.url my understanding was

  • do deep scrubbing get a new structure
  • now get a value from status.url and replace with [redacted] or use string ?

Alternatively we add workspaceId in

RedactedValues = map[string]*regexp.Regexp{
? But it can make logging with strings slower. Redacting url actually sounds better. It should not have perf impact.

@WVerlaek
Copy link
Member

Also do you really want to log the entire workspace status? e.g. are you interested in ports?

if possible yes - it's been useful to debug workspace issues by having the full status. Lets you reconstruct a timeline of the workspace and its status changes

@WVerlaek
Copy link
Member

Is it possible to add a scrubbed tag on the status.URL field?

@iQQBot
Copy link
Contributor Author

iQQBot commented Oct 16, 2023

Is it possible to add a scrubbed tag on the status.URL field?

only if it's our control struct

@iQQBot
Copy link
Contributor Author

iQQBot commented Oct 16, 2023

Is it possible to add a scrubbed tag on the status.URL field?

I checked, we can do this

@iQQBot iQQBot force-pushed the pd/ws-man-2-redact-log branch from 68e87af to c5c7c5c Compare October 16, 2023 10:18
@iQQBot
Copy link
Contributor Author

iQQBot commented Oct 16, 2023

updated

Copy link
Member

@WVerlaek WVerlaek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@roboquat roboquat merged commit 81ff3d1 into main Oct 16, 2023
@roboquat roboquat deleted the pd/ws-man-2-redact-log branch October 16, 2023 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants