-
Notifications
You must be signed in to change notification settings - Fork 849
[JSONRPC] - Introduce TS Plugin API - Proposal #8630
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
Conversation
dce1e5a to
bafb3f0
Compare
|
@jrushford is going to take a look at this |
|
[approve ci autest] |
bafb3f0 to
5312a04
Compare
|
[approve ci autest rocky] |
5312a04 to
b77bc65
Compare
|
[approve ci autest] |
|
This pull request has been automatically marked as stale because it has not had recent activity. Marking it stale to flag it for further consideration by the community. |
b77bc65 to
179bc12
Compare
|
This pull request has been automatically marked as stale because it has not had recent activity. Marking it stale to flag it for further consideration by the community. |
7201109 to
8584c30
Compare
|
[approve ci autest] |
| if (!rpc::add_method_handler_from_plugin( | ||
| name, | ||
| [callback](std::string_view const &id, const YAML::Node ¶ms) -> void { | ||
| std::string msgId{id.data(), id.size()}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For instance, here you need to create a std::string and potentially allocate memory because the view can't be easily passed through. This is why we want to have a consistent view based API.
This commit extends the existing TS API to allow plugins to register and interact with the JSONRPC server.
The idea is to remove this from the code and make it defined by the automake scripts. Eventually the version could be read from the yaml source when added. This is needed to validate the YAML version used by plugins when registering to the JSONRPC manager to avoid ABI compatibility issues.
8584c30 to
35465a9
Compare
35465a9 to
3efe1af
Compare
|
[approve ci autest] |
|
[approve ci autest 3of4] |
|
[approve ci autest] |
JSONRPC TS API proposal
This draft is based on #7478 which holds the JSONRPC 2.0 implementation for ATS.
Current state
Currently If a plugin wants to handle external messages they need to implement the
TS_EVENT_LIFECYCLE_MSGhook. This provides a one way only message system for plugins, plugins can only receive the message but cannot respond to them directly.Proposal
As a part of #6633 we have introduced #7478 (merged in 10-Dev branch) which let traffic_server to receive and respond to external messages using JSON as standard text-based format, following the JSONRPC 2.0 standard.
The goal of this proposal is to take advantage of this implementation and let plugins be able to expose JSONRPC nodes(handlers) to the exterior and also be able to respond directly to exterior clients(currently not possible).
To achieve this we are proposing to introduce a new set of API:
JSONRPC callback signature for method calls.
JSONRPC callback signature for notification calls
Method to perform a registration and validation when a plugin is expected to handle JSONRPC calls.
param provider_name: a string with the Plugin's description.param yamlcpp_lib_version: a string with the yamlcpp library version. A null terminated string is expected. Why do we need this? check Binary compatibility with YAMLCPP down below.This function returns a new
TSRPCProviderHandleornullptrif theyamlcpp_lib_versionwas not set or the yamlcpp version does not match with the one used internally in TS. The returnedTSRPCProviderHandlewill be set with the passed provider's name. The caller should pass the returnedTSRPCProviderHandleobject to each subsequentTSRPCRegisterMethod/Notificationcall.Add a new registered method handler to the JSON RPC server.
param name: Call name to be exposed by the JSONRPC server.param callback: The function to be registered.param info:TSRPCProviderHandlepointer, this will be used to provide more context information about this call. This objectparam opt: Pointer toTSRPCHandlerOptionsobject. This will be used to store specifics about a particular call, the rpcmanager will use this object to perform certain actions. A copy of this object wil be stored by the rpc manager.
Function to notify the JSONRPC server that the current handler is done working.
This function must be used only when implementing a
methodJSONRPC handler. Once the work is done and the response is ready to be sent back to the client, this function should be called. Is expected to set the YAML node as response. If the response is empty asuccessmessage will be added to the client's response.This function returns
TS_SUCCESSif there are no issues.TS_ERRORotherwise.Function to notify the JSONRPC server that the current handler is done working and an error has arisen.
This should not be used if you registered your handler as a notification: TSRPCNotificationCb call.
param code: Error code.param descr: A text with a description of the error.This function returns
TS_SUCCESSif there are no issues.TS_ERRORotherwise.Internals
This JSONRPC implementation is based on an iterative server(his own thread) which handles a single request at a time, this blocks till the response is handed back to the rpc server. For plugins this is a bit different as they need the asynchronous style to deal with some specifics tasks, plugins needs to be able to run tasks possibly on different thread and at a different time that they get called to handle the JSONRPC call, so to achieve this the JSONRPC server implements a notification mechanism(
TSRPCHandlerDone,TSRPCHandlerError) which will let the JSONRPC server that the plugin handling is complete, either with an error or with a particular content. Plugins will be able to reschedule the JSONRPC handling work as they see fit. You can find examples in this PR.To be added into apidefs.h.in
Binary compatibility with YAMLCPP
Having plugins with different version of YAMLCPP could be an issue, so as with plugins, we cannot guarantee that a will be compatible across major versions, so It would be feasible to only provide binary compatibility within the lifespan of a major release, no new version of YAMLCPP should be introduced in minor versions. Eventually plugins will need to recompile/link
YAMLCPP version check
To help the plugin developers to spot issues, plugins should check-in (using
TSRPCRegister) with TS before registering any handler and validate that theiryamlcppversion is the same as used internally in TS. Plugins will inform which version they have and internally we will compare this against the one used in ATS (this could be an issue as we can use an external version of YAMLCPP and not the one shipped with ATS)See examples in this Draft PR.
You can find this Docs online here and here