Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Feature: plugin debugging #1716

Merged
merged 10 commits into from
Jul 13, 2021
Merged

Feature: plugin debugging #1716

merged 10 commits into from
Jul 13, 2021

Conversation

izaaklauer
Copy link
Contributor

@izaaklauer izaaklauer commented Jun 25, 2021

It is currently difficult to debug the builtin plugins, as waypoint itself launches plugin processes as it requires them. Debugging is easiest when you can use a debugger to launch the process of interest.

This experimental change allows Waypoint to launch builtin plugins in debug mode, and connect to and use an existing plugin processes. It is dependent on these waypoint-plugin-sdk changes: hashicorp/waypoint-plugin-sdk#39

These changes are inspired by (and in many cases copied from) Terraform's plugin debug mode. I've tried to keep the user facing side (flag/env var names, workflow, etc) as similar to Terraform as possible for consistency.

Debugging workflow

Step 1: Launch a plugin process of interest (via delve or goland debug) with the new debug flag (i.e. waypoint plugin -debug pack). The plugin will launch, print reconnection info to the console (example below), then wait for core to attach.

Plugin started, to attach Waypoint set the WP_REATTACH_PLUGINS env var:

        WP_REATTACH_PLUGINS='{"pack":{"Protocol":"grpc","ProtocolVersion":1,"Pid":38972,"Test":true,"Addr":{"Network":"unix","String":"/var/folders/ns/grk8kk196_106v37w9hk8hxm0000gq/T/plugin864517971"}}}'

Step 2: Export that environment variable, then run a core command that will require that plugin (i.e. waypoint build). When initializing plugins, core will unmarshall and inspect the contents of the WP_REATTACH_PLUGINS env var. If it finds that a requested plugin is in that map, it will attempt to reconnect to it, rather than launching it itself.

The flow is a little clunky for me - if you're iterating fast and relaunching the plugin process frequently, you have to do a lot of env var copying and pasting. It would be nice if the plugin could use a consistent socket path on every launch. I think this is good enough for now though, and consistency with Terraform is nice.

Documentation

My intent is to use this feature myself for this cycle, and document it next cycle once it's been hardened.

go.mod Outdated
@@ -49,7 +49,7 @@ require (
github.com/hashicorp/go-hclog v0.14.1
github.com/hashicorp/go-memdb v1.3.2
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-plugin v1.3.0
github.com/hashicorp/go-plugin v1.4.2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upgrading to get the ProtocolVersion field on ReattachConfig, which we need to know which VersionedPlugins to use.

internal/plugin/factory.go Outdated Show resolved Hide resolved
internal/runner/operation.go Outdated Show resolved Hide resolved
@@ -93,7 +94,7 @@ func (c *Project) initLocalServer(ctx context.Context) (*grpc.ClientConn, error)
Timeout: 1 * time.Second,
})
if err != nil {
return nil, err
return nil, fmt.Errorf("failed opening boltdb path %s. Is another server already running against this db?: %w", path, err)
Copy link
Contributor Author

@izaaklauer izaaklauer Jun 25, 2021

Choose a reason for hiding this comment

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

This is mostly unrelated, but I spent a good long while trying to get to the bottom of why this change was breaking waypoint's local server mode. It turns out I wasn't initializing the plugin command with the WithNoAutoServer() option, so the plugin was trying to spool up another server, and timing out on opening bolt's data.db file. The only thing I had to go on from the logs was this:

! Unrecognized remote plugin message: ! failed to create client: timeout

So i'm enhancing that log message here.

Also, hurray for the integration test! I would not have caught this otherwise.

@izaaklauer izaaklauer marked this pull request as ready for review June 25, 2021 22:43
@izaaklauer izaaklauer requested a review from a team June 25, 2021 22:43
@krantzinator krantzinator modified the milestones: 0.5.0, 0.4.x Jun 30, 2021
@izaaklauer izaaklauer requested a review from mitchellh July 8, 2021 17:58
I'm not sure if this is the _right_ place to be parsing out unmanaged plugins though.
This manifested as a bug that broke local server mode. The plugin command would try to open the server's boltdb file, timeout, and crash.

I'm also making the error message a bit friendlier here, for the next person to have this category of problem.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
core enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants