-
Notifications
You must be signed in to change notification settings - Fork 4.5k
protoc-gen-go-grpc support split single proto file gen to diffrent package #8233
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
Comments
Hi @qianlongzt, I was going though the linked issue but I don't completely understand how the proposed change addresses the issue. I found this comment that summarises the change: open-telemetry/opentelemetry-go#2579 (comment) Can you elaborate how your proposed solution will solve the problem of splitting gRPC client/server code and protobuf request/response messages into two separate packages? |
@arjan-bal #8245 I created a pr. |
@qianlongzt I tried running the changed from #8245 using the following command: protoc \
--go-grpc_out="${TEMPDIR}" \
--go-grpc_opt=paths=source_relative,use_generic_streams_experimental=true,grpc_mapping='examples/route_guide/routeguide/route_guide.proto=google.golang.org/grpc/examples/route_guide/routeguidegrpc' \
"examples/route_guide/routeguide/route_guide.proto" The go package name was still import (
// Omitted
routeguide "google.golang.org/grpc/examples/route_guide/routeguide" Where does the new package name show up? It would be helpful if you could share an example using the |
The output is correct. The user does not need to use
|
I was trying to see if we can have two packages for the same proto file, one for grpc service code and one for messages without any code changes or splitting the proto file. There is a protoc \
--go_out=Mroute_guide.proto=example.com/message:. \
--go-grpc_out=Mroute_guide.proto=example.com/service:. \
route_guide.proto This seems to be the reason we need to change the grpc codegen code. I'm still trying to understand the grpc codegen code. |
I think I understand the proposed changes better now. Here we don't really need a mapping like the filename := file.GeneratedFilenamePrefix + "_grpc.pb.go"
importPath := file.GoImportPath
if *useSeparateServicePackage {
importPath = file.GoImportPath + "_" + protogen.GoImportPath("grpc")
}
g := gen.NewGeneratedFile(filename, importPath) The effect is that the symbols from the generated message code use qualified names (eg: However, since the package name at the top of the generated message and service code is the same, and both the files are in the same directory, the code will not compile complaining that the grpc code imports its own package causing a cycle. To get separate packages, users will need to specify the |
Use a mapping to let the user switch to a different package. For OpenTelemetry-Go, I'm not sure which package will be used.
This error is expected and acceptable. |
Can you give me a real world example where the values in the mapping will matter? IIUC, service code will import message code, but
This means that the import path of the service code doesn't really get used anywhere. |
You are right—the |
I want to ensure that the usage of the flag is easy for users to understand. I was wondering why OpenTelemetry-Go needs to copy the generated file. Is there something preventing them from using |
We are using I am not sure if it was called out anywhere but this issue is a workaround/mitigation for https://protobuf.dev/reference/go/faq/#namespace-conflict. Related issue that I see as the root cause: golang/protobuf#1122 |
Maybe reading from here: open-telemetry/opentelemetry-go#2579 (comment) will also be helpful. |
I'm discussing the addition of a new flag with other maintainers. |
There weren't any objections to this change. We need to implement the following:
|
@qianlongzt will you be willing to work on a PR for this? |
@arjan-bal #8280 I created a pr |
Use case(s) - what problem will this feature solve?
opentelemetry-go1 supports protobuf over gRPC and over HTTP, but its proto file defines both the service and related messages in the same file.
When using protobuf over HTTP, it's necessary to remove the gRPC dependency to reduce the binary size.
Proposed Solution
Add an option to rename grpc file.GoImportPath 5
Alternatives Considered
Additional Context
open-telemetry/opentelemetry-go#2579
The text was updated successfully, but these errors were encountered: