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

Rework standalone API #703

Merged
merged 10 commits into from
Jun 16, 2023
Merged

Rework standalone API #703

merged 10 commits into from
Jun 16, 2023

Conversation

wbrowne
Copy link
Member

@wbrowne wbrowne commented Jun 13, 2023

What this PR does / why we need it:
This PR attempts to simplify how the standalone package works by refactor into a client/server pattern. I found it quite difficult to navigate as we historically have combined both standalone and locator functionality in the same code path, which makes it tricky to know what information is needed and where.

Compatibility changes:

# github.com/grafana/grafana-plugin-sdk-go/backend
## incompatible changes
GracefulStandaloneServe: changed from func(ServeOpts, github.com/grafana/grafana-plugin-sdk-go/internal/standalone.Args) error to func(ServeOpts, github.com/grafana/grafana-plugin-sdk-go/internal/standalone.ServerSettings) error
StandaloneServe: removed

Special notes for your reviewer:

  • This PR removes the need for a -debug flag as standalone/server mode will now always generate a standalone.txt and pid.txt.
  • GF_PLUGIN_GRPC_ADDRESS_<PLUGIN_ID> is an existing env var, but now both client and server will use this as the primary source of truth for creating or connecting to the standalone server. The pre-existing generation of the address and reading from file still exists, but are treated as fallbacks in their respective modes.

@wbrowne wbrowne self-assigned this Jun 13, 2023
@wbrowne wbrowne marked this pull request as ready for review June 14, 2023 09:55
@wbrowne wbrowne requested a review from a team as a code owner June 14, 2023 09:55
@wbrowne wbrowne requested review from marefr, andresmgot and xnyo and removed request for a team June 14, 2023 09:55
@andresmgot
Copy link
Contributor

I tried this PR and was not able to run a plugin with vscode debugger. I have also set the variable GF_PLUGIN_GRPC_STANDALONE_<PLUGIN_ID>="true", which I don't know if it's needded.

There is no error in the plugin logs though:

with this changes:

Detaching and terminating target process
dlv dap (37840) exited with code: 0
Starting: /home/andres/go/bin/dlv dap --listen=127.0.0.1:39521 --log-dest=3 from .../pkg
DAP server listening at: 127.0.0.1:39521
Type 'dlv help' for list of commands.
{"@level":"debug","@message":"Profiler","@timestamp":"2023-06-14T13:33:17.341648+02:00","enabled":false}
{"@level":"debug","@message":"Tracing","@timestamp":"2023-06-14T13:33:17.341701+02:00","enabled":false,"propagation":""}
{"@level":"debug","@message":"Standalone plugin server","@timestamp":"2023-06-14T13:33:17.342686+02:00","capabilities":["diagnostics","resources","data","stream"]}

This is using main:

Detaching and terminating target process
connection error: Error: read ECONNRESET
dlv dap (41046) exited with code: 0
Starting: /home/andres/go/bin/dlv dap --listen=127.0.0.1:40495 --log-dest=3 from .../pkg
DAP server listening at: 127.0.0.1:40495
Type 'dlv help' for list of commands.
{"@level":"debug","@message":"Profiler","@timestamp":"2023-06-14T13:41:10.963160+02:00","enabled":false}
{"@level":"debug","@message":"Tracing","@timestamp":"2023-06-14T13:41:10.963222+02:00","enabled":false,"propagation":""}
{"@level":"info","@message":"Creating standalone address and pid files","@timestamp":"2023-06-14T13:41:14.229516+02:00"}
2023/06/14 13:41:14 Killing process: 39246
{"@level":"debug","@message":"Standalone plugin server","@timestamp":"2023-06-14T13:41:14.241631+02:00","capabilities":["diagnostics","resources","data","stream"]}

Is there something that I am missing?

@wbrowne
Copy link
Member Author

wbrowne commented Jun 14, 2023

I tried this PR and was not able to run a plugin with vscode debugger. I have also set the variable GF_PLUGIN_GRPC_STANDALONE_<PLUGIN_ID>="true", which I don't know if it's needded.

There is no error in the plugin logs though:

with this changes:

Detaching and terminating target process
dlv dap (37840) exited with code: 0
Starting: /home/andres/go/bin/dlv dap --listen=127.0.0.1:39521 --log-dest=3 from .../pkg
DAP server listening at: 127.0.0.1:39521
Type 'dlv help' for list of commands.
{"@level":"debug","@message":"Profiler","@timestamp":"2023-06-14T13:33:17.341648+02:00","enabled":false}
{"@level":"debug","@message":"Tracing","@timestamp":"2023-06-14T13:33:17.341701+02:00","enabled":false,"propagation":""}
{"@level":"debug","@message":"Standalone plugin server","@timestamp":"2023-06-14T13:33:17.342686+02:00","capabilities":["diagnostics","resources","data","stream"]}

This is using main:

Detaching and terminating target process
connection error: Error: read ECONNRESET
dlv dap (41046) exited with code: 0
Starting: /home/andres/go/bin/dlv dap --listen=127.0.0.1:40495 --log-dest=3 from .../pkg
DAP server listening at: 127.0.0.1:40495
Type 'dlv help' for list of commands.
{"@level":"debug","@message":"Profiler","@timestamp":"2023-06-14T13:41:10.963160+02:00","enabled":false}
{"@level":"debug","@message":"Tracing","@timestamp":"2023-06-14T13:41:10.963222+02:00","enabled":false,"propagation":""}
{"@level":"info","@message":"Creating standalone address and pid files","@timestamp":"2023-06-14T13:41:14.229516+02:00"}
2023/06/14 13:41:14 Killing process: 39246
{"@level":"debug","@message":"Standalone plugin server","@timestamp":"2023-06-14T13:41:14.241631+02:00","capabilities":["diagnostics","resources","data","stream"]}

Is there something that I am missing?

Should be okay now @andresmgot - thanks for checking. Had fudged the paths a bit, but should be okay now

@marefr
Copy link
Member

marefr commented Jun 15, 2023

What kind of tests do you have in mind, manual or unit/integration tests? Trying to understand why this is needed, sorry if I'm stupid/tired 😄

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

FWIW it works fine for me now

@wbrowne
Copy link
Member Author

wbrowne commented Jun 15, 2023

What kind of tests do you have in mind, manual or unit/integration tests? Trying to understand why this is needed, sorry if I'm stupid/tired 😄

No longer relevant for now @marefr. This PR is just a refactoring. Let me know if it makes things clearer

Copy link
Member

@marefr marefr left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@xnyo xnyo left a comment

Choose a reason for hiding this comment

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

Amazing work 🙏!! Love this. I took it for a spin and it works perfectly.

I only have left a couple of optional nits in case you want to address them.

We also have to update the docs for "other ide" section:
https://grafana.com/docs/grafana/latest/developers/plugins/development-with-local-grafana/#other-ides

because the -debug flag is technically not required anymore.

🎉

internal/standalone/standalone.go Show resolved Hide resolved
internal/standalone/standalone.go Show resolved Hide resolved
internal/standalone/standalone.go Show resolved Hide resolved
@wbrowne wbrowne merged commit d40c8ed into main Jun 16, 2023
2 checks passed
@wbrowne wbrowne deleted the standalone-refactor branch June 16, 2023 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants