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

Merged
merged 10 commits into from
Jul 31, 2024
Merged

Conversation

mickmister
Copy link
Contributor

@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
Contributor 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
Contributor 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
Contributor 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?

Copy link

github-actions bot commented Jul 1, 2024

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

@mickmister
Copy link
Contributor Author

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

@azigler Yes they need to be added to the repos as .vscode/launch.json files https://learn.microsoft.com/en-us/microsoft-edge/visual-studio-code/microsoft-edge-devtools-extension/launch-json

@azigler
Copy link
Contributor

azigler commented Jul 2, 2024

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

@azigler Yes they need to be added to the repos as .vscode/launch.json files https://learn.microsoft.com/en-us/microsoft-edge/visual-studio-code/microsoft-edge-devtools-extension/launch-json

Could we provide an example file inline in this docs PR?

Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

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

Awesome 🚀

Copy link

github-actions bot commented Jul 4, 2024

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

Copy link

github-actions bot commented Jul 4, 2024

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

@mickmister
Copy link
Contributor Author

Could we provide an example file inline in this docs PR?

@azigler Yeah there's an example launch.json config included in the docs here

Include this configuration in your VSCode instance's `launch.json`:
```json
{
"name": "Attach to Mattermost plugin",
"type": "go",
"request": "attach",
"mode": "remote",
"port": 2346,
"host": "127.0.0.1",
"apiVersion": 2
}
```

Copy link

Newest code from cwarnermm has been published to preview environment for Git SHA 4fa21ac

@hanzei hanzei requested a review from cwarnermm July 31, 2024 12:23
@hanzei hanzei self-assigned this Jul 31, 2024
@hanzei hanzei added the 2: Editor Review Requires review by an editor label Jul 31, 2024
Copy link

Newest code from hanzei has been published to preview environment for Git SHA 4fa21ac

@hanzei
Copy link
Contributor

hanzei commented Jul 31, 2024

@cwarnermm We got two dev approvals; I think that is enough to hand the PR to you.

Copy link

Newest code from hanzei has been published to preview environment for Git SHA 4fa21ac

Copy link

Newest code from cwarnermm has been published to preview environment for Git SHA ad54f9e

Copy link
Member

@cwarnermm cwarnermm left a comment

Choose a reason for hiding this comment

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

Fantastic dev docs update!

@cwarnermm cwarnermm added 4: Reviews Complete All reviewers have approved the pull request and removed 1: Dev Review Requires review by a core commiter 2: Editor Review Requires review by an editor preview-environment Allow the preview environment to be generated for Pull Requests coming from fork repositories labels Jul 31, 2024
@cwarnermm cwarnermm merged commit 6a57252 into master Jul 31, 2024
5 checks passed
@cwarnermm cwarnermm deleted the debug-server-plugins branch July 31, 2024 13:22
@hanzei hanzei removed their assignment Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
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
4 participants