英文:
Compiling Jaeger gRPC proto files with Python
问题
我目前正在尝试使用Jaeger Query并通过gRPC API访问其内容。我不熟悉gRPC,但我理解我需要在相关的proto文件上使用Python gRPC编译器(grpcio_tools.protoc)以获得有用的Python定义。我正在尝试的是找出通过API访问Jaeger Query的方法,而不使用前端UI。
目前,我在编译proto文件方面遇到了困难。每次尝试时,我都会遇到依赖问题(导入“fileNameHere”未找到或存在错误)。Jaeger的query.proto文件包含对存储库外部文件的导入引用。虽然我可以找到这些文件并手动收集它们,但它们也有依赖关系。我得到的印象是,逐个跟进并逐个收集这些文件并不是预期的做法。
我在这里做错了什么吗?Jaeger的直接文档在这方面的说明有限。以下是我的基本终端会话,还未包括任何手动找到的文件(它们本身也有依赖关系,我需要去找到这些文件)。
$ python -m grpc_tools.protoc --grcp_python_out=. --python_out=. --proto_path=. query.proto
model.proto: 文件未找到。
gogoproto/gogo.proto: 文件未找到。
google/api/annotations.proto: 文件未找到。
protoc-gen-swagger/options/annotations.proto: 文件未找到。
query.proto:20:1: 导入“model.proto”未找到或存在错误。
query.proto:21:1: 导入“gogoproto/gogo.proto”未找到或存在错误。
query.proto:22:1: 导入“google/api/annotations.proto”未找到或存在错误。
query.proto:25:1: 导入“protoc-gen-swagger/options/annotations.proto”未找到或存在错误。
query.proto:61:12: “jaeger.api_v2.Span”未定义。
query.proto:137:12: “jaeger.api_v2.DependencyLink”未定义。
感谢任何帮助。
英文:
I'm currently playing around with Jaeger Query and trying to access its content through the API, which uses gRPC. I'm not familiar with gRPC, but my understanding is that I need to use the Python gRPC compiler (grpcio_tools.protoc) on the relevant proto file to get useful Python definitions. What I'm trying to do is find out ways to access Jaeger Query by API, without the frontend UI.
Currently, I'm very stuck on compiling the proto files. Every time I try, I get dependency issues (Import "fileNameHere" was not found or has errors.). The Jaeger query.proto file contains import references to files outside the repo. Whilst I can find these and manually collect them, they also have dependencies. I get the impression that following through and collecting each of these one by one is not how this was intended to be done.
Am I doing something wrong here? The direct documentation through Jaeger is limited for this. The below is my basic terminal session, before including any manually found files (which themselves have dependencies I would have to go and find the files for).
$ python -m grpc_tools.protoc --grcp_python_out=. --python_out=. --proto_path=. query.proto
model.proto: File not found.
gogoproto/gogo.proto: File not found.
google/api/annotations.proto: File not found.
protoc-gen-swagger/options/annotations.proto: File not found.
query.proto:20:1: Import "model.proto" was not found or had errors.
query.proto:21:1: Import "gogoproto/gogo.proto" was not found or had errors.
query.proto:22:1: Import "google/api/annotations.proto" was not found or had errors.
query.proto:25:1: Import "protoc-gen-swagger/options/annotations.proto" was not found or had errors.
query.proto:61:12: "jaeger.api_v2.Span" is not defined.
query.proto:137:12: "jaeger.api_v2.DependencyLink" is not defined.
Thanks for any help.
答案1
得分: 2
我的一个同事提供了答案... 它藏在 Makefile 中,对我来说没有用,因为我不使用 Golang(而且它比只安装 Golang 和运行它要复杂得多,但我岔开话题了...)。
以下的 .sh 脚本将起到作用。这假设 query.proto 文件位于与下面的脚本相同的位置的子目录中,在 model/proto/api_v2/ 下(正如它出现在主 Jaeger 存储库中)。
#!/usr/bin/env sh
set +x
rm -rf ./js_out 2> /dev/null
mkdir ./js_out
PROTO_INCLUDES="
-I model/proto \
-I idl/proto \
-I vendor/github.com/grpc-ecosystem/grpc-gateway \
-I vendor/github.com/gogo/googleapis \
-I vendor/github.com/gogo/protobuf/protobuf \
-I vendor/github.com/gogo/protobuf";
python -m grpc_tools.protoc ${PROTO_INCLUDES} --grpc_python_out=./python_out --python_out=./python_out model/proto/api_v2/query.proto
这肯定会生成所需的 Python 文件,但仍然会缺少依赖项。
英文:
A colleague of mine provided the answer... It was hidden in the Makefile, which hadn't worked for me as I don't use Golang (and it had been more complex than just installing Golang and running it, but I digress...).
The following .sh will do the trick. This assumes the query.proto file is a subdirectory from the same location as the script below, under model/proto/api_v2/ (as it appears in the main Jaeger repo).
#!/usr/bin/env sh
set +x
rm -rf ./js_out 2> /dev/null
mkdir ./js_out
PROTO_INCLUDES="
-I model/proto \
-I idl/proto \
-I vendor/github.com/grpc-ecosystem/grpc-gateway \
-I vendor/github.com/gogo/googleapis \
-I vendor/github.com/gogo/protobuf/protobuf \
-I vendor/github.com/gogo/protobuf"
python -m grpc_tools.protoc ${PROTO_INCLUDES} --grpc_python_out=./python_out --python_out=./python_out model/proto/api_v2/query.proto
This will definitely generate the needed Python file, but it will still be missing dependencies.
答案2
得分: 1
我按照以下步骤获取了Jaeger的gRPC Python API:
git clone --recurse-submodules https://github.com/jaegertracing/jaeger-idl
cd jaeger-idl/
make proto
请使用proto-gen-python/
目录中的文件。
注意:
如果在导入生成的代码时遇到以下错误:
AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key'
请执行以下操作:
pip3 install --upgrade pip
pip3 install --upgrade protobuf
英文:
I did the following to get the Jaeger gRPC Python APIs:
git clone --recurse-submodules https://github.com/jaegertracing/jaeger-idl
cd jaeger-idl/
make proto
Use the files inside proto-gen-python/
.
Note:
While importing the generated code, if you face the error:
AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key'
Do:
pip3 install --upgrade pip
pip3 install --upgrade protobuf
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论