Skip to content

Conversation

@Nymphium
Copy link
Contributor

@Nymphium Nymphium commented Nov 10, 2025

This PR adds Metainfo module to each generated files.
That module has information to implement gRPC reflection API:

  • file name: its source proto file name path
  • file descriptor: protobuf binary format of the file
  • service list: list of services of the file

Copy link
Owner

@andersfugmann andersfugmann left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM. I've have one question on naming though.

Also before we merge, could you give a simple example of all the metadata created around service endpoints for gRPC? I'd like to understand if more fields could be moved into this structure to clean up and hopefully it would also be easier to add additional fields going forward.

| Bytes -> Bytes.create 0
| Enum (module Enum) -> Enum.from_int_exn 0

module type Metainfo = sig
Copy link
Owner

Choose a reason for hiding this comment

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

Does metainfo have a special definition in the gRPC standard? If not, then I think it would be better to call it something like Service_info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it may not be a standard. I agree with Service_info 👍

@Nymphium
Copy link
Contributor Author

@andersfugmann
Copy link
Owner

Thanks for providing examples.
file_descriptor proto can be quite large, and is only needed for gRPC. I dont think that should be included by default. Would it make sense to add a flag to the generation to enable gRPC relevant fields when needed?

Would it be possible to make the list of endpoints be a list of modules instead to avoid string duplication?
So instead have

let package_service_names = 
[ (module Grpc.Reflection.V1.ServerReflection : Rpc); ... ]

Should hold the same (if not more) information and avoid string duplication.

Btw. Since this information is only needed for gRPC, maybe call the module Grpc_info.

@Nymphium
Copy link
Contributor Author

@andersfugmann I've applied the changes in 4fb8d6e.

Would it make sense to add a flag to the generation to enable gRPC relevant fields when needed?

I addeed service_info flag and false by default 👍

Would it be possible to make the list of endpoints be a list of modules instead to avoid string duplication?

It's difficult to achieve that in some cases. protoc invokes plugins multiple times with different target protos, and these plugin processes run independently.
That said, it might be possible if we split the service info and other specs into separate files.

Copy link
Owner

@andersfugmann andersfugmann left a comment

Choose a reason for hiding this comment

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

Looks very good. Thanks for making the updates.

(* Code.emit implementation `None "%s" (Code.append_deprecaton_if ~deprecated `Floating ""); *)
()

let emit_metainfo implementation fd file_name package_service_names =
Copy link
Owner

Choose a reason for hiding this comment

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

This should be called emit_service_info

| Bytes -> Bytes.create 0
| Enum (module Enum) -> Enum.from_int_exn 0

module type Service_info = sig
Copy link
Owner

Choose a reason for hiding this comment

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

The declaration of the Service_info should be moved to the Service module.

@andersfugmann
Copy link
Owner

andersfugmann commented Dec 11, 2025

It's difficult to achieve that in some cases. protoc invokes plugins multiple times with different target protos, and these plugin processes run independently. That said, it might be possible if we split the service info and other specs into separate files.

I'm not sure I follow. The service names are already collected as part of emitting the signature and implementation of all messages and services defined in the proto file.

I may take a stab at implementing that, but I would prefer to the two other comments + tests addressed first.

Again, Thanks for doing this work. Really appreciated!

@andersfugmann andersfugmann self-assigned this Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants