8000 feat(schema): generate pydantic based jsonschema for any jina proto by deepankarm · Pull Request #2121 · jina-ai/serve · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(schema): generate pydantic based jsonschema for any jina proto #2121

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

Merged
merged 6 commits into from
Mar 8, 2021

Conversation

deepankarm
Copy link
Contributor

No description provided.

@deepankarm deepankarm requested a review from a team as a code owner March 7, 2021 07:54
@jina-bot jina-bot added size/M area/core This issue/PR affects the core codebase area/network This issue/PR affects network functionality area/testing This issue/PR affects testing component/peapod labels Mar 7, 2021
@deepankarm deepankarm mentioned this pull request Mar 7, 2021
3 tasks
@github-actions
Copy link
github-actions bot commented Mar 7, 2021

Latency summary

Current PR yields:

  • 😶 index QPS at 1055, delta to last 3 avg.: +2%
  • 🐢🐢 query QPS at 14, delta to last 3 avg.: -9%

Breakdown

Version Index QPS Query QPS
current 1055 14
1.0.8 1016 15
1.0.7 1038 15

Backed by latency-tracking. Further commits will update this comment.

@deepankarm deepankarm force-pushed the feat-proto-to-pydantic-schema branch from 85c3ef6 to 2a5ae29 Compare March 7, 2021 08:12
@codecov
Copy link
codecov bot commented Mar 7, 2021

Codecov Report

Merging #2121 (bd2874b) into master (c258e4a) will increase coverage by 1.52%.
The diff coverage is 93.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2121      +/-   ##
==========================================
+ Coverage   88.34%   89.86%   +1.52%     
==========================================
  Files         211      211              
  Lines       11104    11154      +50     
==========================================
+ Hits         9810    10024     +214     
+ Misses       1294     1130     -164     
Flag Coverage Δ
daemon 50.67% <2.73%> (-0.17%) ⬇️
jina 90.34% <93.15%> (+1.64%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
jina/parsers/peapods/runtimes/distributed.py 100.00% <ø> (ø)
jina/peapods/runtimes/jinad/__init__.py 95.91% <ø> (+4.08%) ⬆️
jina/peapods/runtimes/asyncio/rest/app.py 77.69% <16.66%> (ø)
jina/__init__.py 73.49% <100.00%> (ø)
jina/peapods/runtimes/asyncio/rest/models.py 100.00% <100.00%> (ø)
jina/helper.py 83.44% <0.00%> (+0.86%) ⬆️
jina/drivers/control.py 95.08% <0.00%> (+1.63%) ⬆️
jina/clients/base.py 83.19% <0.00%> (+1.68%) ⬆️
jina/peapods/runtimes/jinad/client.py 82.48% <0.00%> (+2.18%) ⬆️
jina/types/message/__init__.py 88.20% <0.00%> (+2.56%) ⬆️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7dd876d...b44b470. Read the comment docs.

@florian-hoenicke
Copy link
Member

I like the conversion from protobuf to pydantic. It is more flexible in contrast to just adding the oneof-fields manually. Good work! @deepankarm

}


def protobuf_to_pydantic_model(
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to break this down in smaller functions?

elif f.message_type.name == 'Timestamp':
# Proto Field Type: google.protobuf.Timestamp
field_type = datetime
default_value = datetime.now()
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it better to put an stupid default value? Like this we can see if the timestamp is real or not? Normally timestamp is needed to measure some stuff about the presence of an object in a Pod, like this we try the "false positives" of seeing a meaningful timestamp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Timestamp field needs further polishing. google.protobuf.Timestamp describes time in seconds & nanos, where datetime.now() is in a different format. Since this schema is only exposed to the users for viewing, for now, I would prefer to keep it as-is for now and upgrade as and when required.

protobuf_fields = protobuf_model.DESCRIPTOR.fields

if model_name.endswith('Proto') and model_name in PROTO_TO_PYDANTIC_MODELS:
return PROTO_TO_PYDANTIC_MODELS[model_name]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this just an optimization?

Is it worth it the fact of introducing a global variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This helps us in 2 ways

  1. Keeping this global variable adds all schemas to openapi docs. Hence, auto-rendering of all Jina protos in jsonschema for both swagger & redoc
  2. Easier handling of recursive schemas.

@deepankarm deepankarm marked this pull request as draft March 8, 2021 05:35
@deepankarm deepankarm marked this pull request as ready for review March 8, 2021 06:04
@deepankarm deepankarm merged commit b429d22 into master Mar 8, 2021
@deepankarm deepankarm deleted the feat-proto-to-pydantic-schema branch March 8, 2021 08:30
@deepankarm deepankarm linked an issue Mar 10, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core This issue/PR affects the core codebase area/network This issue/PR affects network functionality area/testing This issue/PR affects testing component/peapod size/M
4CFE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto-generate Pydantic models from protos
4 participants
0