[PROPOSAL] Spec to Protobuf Conversion Rules and Tooling #677
Labels
enhancement
New feature or request
question
Further information is requested
Roadmap:Cost/Performance/Scale
Project-wide roadmap label
What/Why
A critical problem to be solved on the path for gRPC support in OpenSearch, is to have published Protobuf definitions, that are fully aligned with the spec. However, because of the many differences, converting an OpenAPI spec to Protobuf is not always straightforward. Often, it requires some manual intervention and careful consideration of how to best map REST concepts and data structures to the more constrained and different RPC-oriented protobuf/gRPC model. We hope to avoid tedious and error-prone manual conversions, and rather establish a standard set of conversion rules adhering to proto best practices, which can be integrated into automation and reused time after time.
What are you proposing?
Spec to Proto Conversion Rules
API Paths and Operations Translation (namespaces)
OpenAPI is meant only to support JSON/HTTP APIs, thus mappings to protobuf/gRPC ones will have some high-level differences:
rpc Search(..)
)Data Model Translation (schemas)
For translating the data models that describe the API inputs and output, besides following protobuf style guide and best practices, we additionally require some custom rules in order to address ambiguities and edge cases of OpenAPI to proto conversion, which are proposed below.
There are 4 main categories of custom proto conversion rules:
For more details, refer to the custom proto conversion rules doc.
Example
A simplified example for the IndexSearch endpoint (with some fields omitted for simplicity), using the proto conversion rules would look something like:
where field 1 is an HTTP endpoint parameter corresponding to the index in the endpoint
GET /{index}/_search
, fields 2-4 are URL parameters, and field 5 is the http request body.More comprehensive examples which leverage more of the proto conversion rules, can be expected be provided in a future PR that will be open to feedback or initial comments.
Tooling
The tooling to be built on a high-level should achieve the following:
There are no direct off-the-shelf solutions which can fulfill all our requirements, but to prevent fully reinventing the wheel, we propose to reuse the tool OpenAPI Generator as much as we can, and add custom improvements and contributions on top of it, as well as extra pre/post-processing steps. We propose to maintain a fork of this tool within the opensearch-project organization to start with, allowing a balance between flexibility of adding customizations/improvements on this tool as well as the potential to contribute back to its upstream project (the project uses an Apache license). Although its protobuf generator is in Beta version, today it is missing support for many common proto features (e.g. conversions of 'allof' or 'anyof' to protos, as well as avoiding circular dependencies in generated proto files).
Current steps in the tool look something like this:
We can additionally add pre-processing and post-processing steps, as well as introduce customizations to the tool itself in order to automate the proto conversion:
Other Considerations
Versioning: Protobuf versioning will follow the spec version, which until the spec is in a stable state, will be
0.[spec-major-version].[spec-minor-version]
. Only the major version will be put in the proto package name. The minor version will be included in the proto as annotations, carried forward from the spec.CI workflows for auto-conversion: GHA workflows can be built to run the tooling to automate the spec to proto conversion. More details to keep the core<>spec<>proobufs in sync will be detailed in a separate issue.
Planned Milestones / Next steps
With the goal of having a proto package version published along with its matching spec version in this repo in mind, planned steps to achieve that include:
The text was updated successfully, but these errors were encountered: