Skip to content
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

Wire up debug events #3645

Merged
merged 6 commits into from
Feb 28, 2020

Conversation

briandealwis
Copy link
Member

Relates to #3122 (#3564, #3609)
Fixes #2211

Description

This PR wires up the new DebuggingContainerEvent (#3609) to be fired by Skaffold when observing a debuggable container starting or terminating. These debugging containers are exposed via the Skaffold state object. With this PR, the IDEs can monitor for events to populate UIs.

User facing changes

New events and addition to the Skaffold state.

There are no changes to the log. Although some logging may be useful for users seeking to configure their debuggers manually, I figured the port-forwarding messages would usually be sufficient.

`/v1/events` stream of `skaffold debug` within `examples/jib`

In this example, we do a skaffold debug, and then kill the deployed pod. The deployment starts a new pod. We get a terminated event for the container for the killed pod.

{
  "result": {
    "timestamp": "2020-02-05T03:27:30.114354Z",
    "event": {
      "debuggingContainerEvent": {
        "status": "Started",
        "podName": "web-f6d56bcc5-6csgs",
        "containerName": "web",
        "namespace": "default",
        "artifact": "skaffold-jib",
        "runtime": "jvm",
        "debugPorts": {
          "jdwp": 5005
        }
      }
    },
    "entry": "Debuggable container started pod/web-f6d56bcc5-6csgs:web (default)"
  }
}
The `/v1/state` listing debugging containers
{
  "buildState": {
    "artifacts": {
      "skaffold-jib": "Complete"
    }
  },
  "deployState": {
    "status": "Complete"
  },
  "forwardedPorts": {
    "5005": {
      "localPort": 5005,
      "remotePort": 5005,
      "podName": "web-f6d56bcc5-6csgs",
      "containerName": "web",
      "namespace": "default",
      "portName": "jdwp",
      "resourceType": "pod",
      "resourceName": "web-f6d56bcc5-6csgs",
      "address": "127.0.0.1"
    },
    "8080": {
      "localPort": 8080,
      "remotePort": 8080,
      "namespace": "default",
      "resourceType": "service",
      "resourceName": "web",
      "address": "127.0.0.1"
    },
    "8081": {
      "localPort": 8081,
      "remotePort": 8080,
      "podName": "web-f6d56bcc5-6csgs",
      "containerName": "web",
      "namespace": "default",
      "resourceType": "pod",
      "resourceName": "web-f6d56bcc5-6csgs",
      "address": "127.0.0.1"
    }
  },
  "statusCheckState": {
    "status": "Not Started"
  },
  "fileSyncState": {
    "status": "Not Started"
  },
  "debuggingContainers": [
    {
      "status": "Started",
      "podName": "web-f6d56bcc5-6csgs",
      "containerName": "web",
      "namespace": "default",
      "artifact": "skaffold-jib",
      "runtime": "jvm",
      "debugPorts": {
        "jdwp": 5005
      }
    }
  ]
}

Next PRs.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Mentions any output changes.
  • Adds documentation as needed: user docs, YAML reference, CLI reference. already done
  • Adds integration tests if needed.

Reviewer Notes

  • The code flow looks good.
  • Unit test added.
  • User facing changes look good.

Release Notes

- New events emitted when debuggable containers are started and terminated

- adds SkaffoldRunner.isDebugMode()
@codecov
Copy link

codecov bot commented Feb 5, 2020

Codecov Report

Merging #3645 into master will increase coverage by 0.08%.
The diff coverage is 67.39%.

Impacted Files Coverage Δ
...skaffold/kubernetes/debugging/container_manager.go 48.33% <ø> (+1.55%) ⬆️
cmd/skaffold/app/cmd/flags.go 100% <ø> (ø) ⬆️
pkg/skaffold/deploy/helm.go 77.18% <67.39%> (+2.52%) ⬆️
pkg/skaffold/sync/sync.go 72.57% <0%> (+0.31%) ⬆️

Comment on lines 26 to 29
// isDebugMode returns true if we're running for debugging.
func (r *SkaffoldRunner) isDebugMode() bool {
return r.runCtx.Opts.Command == "debug"
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I introduced this function to test whether Skaffold was launched as skaffold debug. This works for debug, but it doesn't seem a great pattern — for example, debug effectively invokes dev under the hood.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we already have a runContext.DevMode that serves a similar purpose. Can we make this similar? I don't have a preference towards either, I just don't want inconsistency.

Comment on lines 90 to 96
// Notify only when a container is Running or Terminated (not Waiting)
// "ADDED" is never interesting since no containers are Running yet
// "MODIFIED" may now have containers in Running or Terminated
// "DELETED" if the pod is deleted
if evt.Type != watch.Modified && evt.Type != watch.Deleted {
continue
}
Copy link
Member Author

Choose a reason for hiding this comment

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

What I observed when prototyping this functionality that I couldn't rely on the pod status. Rather I had to check on pod MODIFIED and DELETED events and then look at and track the individual container status (see below in checkPod()). I would get spurious debug events otherwise.

@balopat balopat self-assigned this Feb 10, 2020
@tejal29 tejal29 assigned tejal29 and unassigned tejal29 Feb 19, 2020
balopat
balopat previously approved these changes Feb 27, 2020
Copy link
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

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

LGTM, tried it and works

@balopat
Copy link
Contributor

balopat commented Feb 27, 2020

Hmm...the new test just flaked:

time="2020-02-27T20:10:21Z" level=info msg="Ran in 9.814053538s"
--- FAIL: TestDebugEventsRPC (13.69s)
    rpc_test.go:376: waiting for connection...
    rpc_test.go:376: waiting for connection...
    debug_test.go:126: int differ (-got, +want):   int(
        - 	0,
        + 	1,
          )

@balopat balopat dismissed their stale review February 27, 2020 23:44

I'm worried about the flake of TestDebugEventsRPC

Copy link
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

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

we need to figure out what broke with --status-check=true that just got merged to be the default.

integration/debug_test.go Outdated Show resolved Hide resolved
@briandealwis
Copy link
Member Author

briandealwis commented Feb 28, 2020

So the cause is that I deviate from port-forwarding's watch event filtering, which looks at ADDED and MODIFIED events, whereas the container manager only looks at MODIFIED and DELETED watch events. Prior to the status checks, ADDED events seemed spurious as they had no ContainerStatus items — the real changes came through MODIFIED events.

Removing this watch event filtering and using only the container status makes everything work again.

@briandealwis
Copy link
Member Author

PTAL @balopat

@balopat balopat merged commit 8a99280 into GoogleContainerTools:master Feb 28, 2020
@briandealwis briandealwis deleted the wire-debug-events branch April 3, 2020 20:40
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.

skaffold debug should issue event with artifact debug configuration details
4 participants