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

Update docs for debugging server plugins #1370

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mickmister
Copy link
Member

@mickmister mickmister commented May 21, 2024

Summary

Old docs
https://developers.mattermost.com/integrate/plugins/developer-workflow/#debug-server-side-plugins-using-delve

New docs
http://mattermost-dev-docs-preview-pulls.s3-website-us-east-1.amazonaws.com/1370/integrate/plugins/developer-workflow/#debug-server-side-plugins-using-delve

This PR updates the section on debugging server-side plugins on the Developer Workflow page. There are some changes due to previously having external libraries checked in a vendor folder, which now exist in Go modules.

The PR includes a script to automate modifying the rpc_client.go file in the go-plugin package, to allow for long pauses from the debugger. Note there is an open PR upstream to implement this into the package hashicorp/go-plugin#101, as well as an issue I had opened for this a while ago hashicorp/go-plugin#248. Patching the library locally for development purposes seems harmless to me. I'm wondering if there's a more appropriate way to do this.

Ticket Link

Fixes #1365

@mickmister mickmister added the 1: Dev Review Requires review by a core commiter label May 21, 2024
@mickmister mickmister added the preview-environment Allow the preview environment to be generated for Pull Requests coming from fork repositories label May 21, 2024
Copy link

Newest code from mickmister has been published to preview environment for Git SHA 055a148

1 similar comment
Copy link

Newest code from mickmister has been published to preview environment for Git SHA 055a148

@mickmister
Copy link
Member Author

mickmister commented May 21, 2024

If we want to debug the OnActivate function, I think we'll need to run the plugin in attach mode, which allows the plugin to run on its own, and attach itself to the running Mattermost instance. This way, we can attach a debugger to the running plugin before it's interacting with the Mattermost server. This is attach strategy is done in unit testing in other projects https://github.com/mattermost/mattermost-plugin-msteams/blob/fd8798ee2ec005f7de528067d6f1ec863f70ffff/server/helper_test.go#L61

make attach-headless
```

This starts a headless `delve` process for your IDE to connect to. The process listens on port `2346`, which is the port defined in our `launch.json` configuration. Somewhat related, the Mattermost server's `Makefile` has a command `debug-server-headless`, which starts a headless `delve` process for the Mattermost server, listening on port `2345`. So you can create a similar `launch.json` configuration in the server directory of the monorepo to connect to your server by using that port.
Copy link
Member Author

Choose a reason for hiding this comment

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

We should probably check in these launch.json files

Copy link
Contributor

Choose a reason for hiding this comment

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

Are they just missing? What would be needed to add them?


In the script below, we automatically modify the file located at `${GOPATH}/pkg/mod/github.com/hashicorp/go-plugin@${GO_PLUGIN_PACKAGE_VERSION}/rpc_client.go`, where `GO_PLUGIN_PACKAGE_VERSION` is the version of `go-plugin` that your Mattermost server is using. This can be found in your local copy of the monorepo at [server/go.mod](https://github.com/mattermost/mattermost/blob/4bdd8bb18e47d16f9680905972516526b6fd61d8/server/go.mod#L141).

This script essentially replaces the line in [go-plugin/rpc_client.go](https://github.com/hashicorp/go-plugin/blob/586d14f3dcef1eb42bfb7da4c7af102ec6638668/rpc_client.go#L66) to have a custom configuration for the RPC client connection, that disables the "keep alive" feature. This makes it so the debugger can be paused for long amounts of time, and the Mattermost server will keep the connection with the plugin open.
Copy link
Member Author

Choose a reason for hiding this comment

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

This section is wordy about describing the script. Also the section should probably contain instructions on how to do this manually, like the previous docs had

Copy link

Newest code from mickmister has been published to preview environment for Git SHA e763268

Copy link

github-actions bot commented Jun 7, 2024

Newest code from azigler has been published to preview environment for Git SHA 29bbb9b

Copy link
Contributor

@azigler azigler left a comment

Choose a reason for hiding this comment

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

Really fantastic update, @mickmister! 👍 💯 Thanks for taking the time to update this.

make attach-headless
```

This starts a headless `delve` process for your IDE to connect to. The process listens on port `2346`, which is the port defined in our `launch.json` configuration. Somewhat related, the Mattermost server's `Makefile` has a command `debug-server-headless`, which starts a headless `delve` process for the Mattermost server, listening on port `2345`. So you can create a similar `launch.json` configuration in the server directory of the monorepo to connect to your server by using that port.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are they just missing? What would be needed to add them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1: Dev Review Requires review by a core commiter preview-environment Allow the preview environment to be generated for Pull Requests coming from fork repositories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Debug server-side plugins using delve" section of plugin developer workflow guide needs revision for accuracy
2 participants