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

Enable go plugins to send events #2692

Merged
merged 1 commit into from
Jul 29, 2021

Conversation

GuessWhoSamFoo
Copy link
Contributor

What this PR does / why we need it:
Javascript plugins have a SendEvent method that is currently not possible with go plugins.

see https://github.com/vmware-tanzu/octant/blob/447171cf3ac3c520c3ad3bbe839f8affc6b61cc3/pkg/plugin/javascript/dashboard_send_event.go

This PR allows plugin authors to do the same via:
request.DashboardClient.SendEvent(request.Context(),request.ClientState.ClientID(), event.EventTypeMyEvent, action.Payload{})

cc @liamrathke

Copy link
Contributor

@wwitzel3 wwitzel3 left a comment

Choose a reason for hiding this comment

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

Lets update SendAlert to wrap SendEvent and we can later talk about removing SendAlert

pkg/plugin/api/server.go Outdated Show resolved Hide resolved
pkg/plugin/api/client.go Show resolved Hide resolved
Signed-off-by: Sam Foo <[email protected]>
Co-authored-by: Liam Rathke <[email protected]>
@@ -379,14 +380,18 @@ func (c *grpcServer) ForceFrontendUpdate(ctx context.Context, _ *proto.Empty) (*
return &proto.Empty{}, nil
}

// SendAlert sends an alert
// SendAlert sends an alert. This method is deprecated and will be removed in a future release
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be clear, we'd just need to deprecate it from the server side, right? As in, we could modify SendAlert() in client.go to call client.SendEvent(), so that plugins sending alerts won't need to be rewritten. I feel like SendAlert() is a good utility to have client-side, since it's widely usable. Were it removed, any plugins would need to re-implement the same code, and it would look almost identical to what we have already anyways.

https://github.com/vmware-tanzu/octant/blob/f2b531ca649e23e711f9118019ea185e8412626f/pkg/plugin/api/client.go#L242-L255

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is to remove it entirely because it is redundant (and we can do so relatively safely as it is pre 1.0). Otherwise one could argue one should have similar methods for each event type.

The tradeoff is abstracting away knowledge of the required action.Payload keys which is something that could be addressed by creating payload helpers for various events.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, some sort of action/event helpers would be super useful for plugins

@GuessWhoSamFoo GuessWhoSamFoo merged commit 83f18fc into vmware-archive:master Jul 29, 2021
@GuessWhoSamFoo GuessWhoSamFoo deleted the send-event branch July 29, 2021 16:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants