-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat: pass request-headers as metadata #6126
base: master
Are you sure you want to change the base?
Conversation
jina/constants.py
Outdated
@@ -53,6 +53,7 @@ | |||
__args_executor_func__ = { | |||
'docs', | |||
'parameters', | |||
'metadata', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you prefer metadata
or request_metadata
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @JoanFM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request_metadata or headers? I would say headers perhaps
jina/proto/docarray_v1/jina.proto
Outdated
@@ -122,6 +122,8 @@ message DataRequestProto { | |||
} | |||
|
|||
DataContentProto data = 4; // container for docs and groundtruths | |||
|
|||
google.protobuf.Struct metadata = 5; // extra kwargs that will be used in executor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not want to add this here. We decided that we wanted to pass as grpc-metadata
which is something that should not be shown in the protobuf
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove this and the proto changes that resulted from it.
|
||
req = DataRequest() | ||
if body.header is not None: | ||
req.header.request_id = body.header.request_id | ||
|
||
if body.parameters is not None: | ||
req.parameters = body.parameters | ||
req.metadata = dict(request.headers or {"no_headers": "true"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove this default value
@app.api_route(**app_kwargs) | ||
async def post(body: input_model, response: Response): | ||
async def post(body: input_model, response: Response, request: Request): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this means the header will only be available when gateway is enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway - having access to HTTP header is very important for our production application - we are an infra team supporting different businesses, and we use headers to communicate extra information like auth, tracing id, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should work for standalone-fast-api deployments too. See this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @cenhao ,
The feature should be available with and without gateway.
Btw, would be cool to know about ur usecase and how u use/plan to use Jina
0fb78c9
to
d1450b0
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #6126 +/- ##
===========================================
- Coverage 72.61% 49.55% -23.06%
===========================================
Files 152 150 -2
Lines 14061 14027 -34
===========================================
- Hits 10210 6951 -3259
- Misses 3851 7076 +3225
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name more headers
than metadata
.
jina/proto/docarray_v1/jina.proto
Outdated
@@ -122,6 +122,8 @@ message DataRequestProto { | |||
} | |||
|
|||
DataContentProto data = 4; // container for docs and groundtruths | |||
|
|||
google.protobuf.Struct metadata = 5; // extra kwargs that will be used in executor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not want to add this here. We decided that we wanted to pass as grpc-metadata
which is something that should not be shown in the protobuf
.
jina/constants.py
Outdated
@@ -53,6 +53,7 @@ | |||
__args_executor_func__ = { | |||
'docs', | |||
'parameters', | |||
'metadata', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request_metadata or headers? I would say headers perhaps
jina/__init__.py
Outdated
@@ -81,7 +81,7 @@ def _ignore_google_warnings(): | |||
|
|||
# do not change this line manually | |||
# this is managed by proto/build-proto.sh and updated on every execution | |||
__proto_version__ = '0.1.27' | |||
__proto_version__ = '0.1.28' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
related to the proto comment, should not be updated.
jina/proto/docarray_v1/jina.proto
Outdated
@@ -138,6 +140,8 @@ message SingleDocumentRequestProto { | |||
|
|||
docarray.DocumentProto document = 4; // the document in this request | |||
|
|||
google.protobuf.Struct metadata = 5; // extra kwargs that will be used in executor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
jina/proto/docarray_v1/jina.proto
Outdated
@@ -148,6 +152,8 @@ message DataRequestProtoWoData { | |||
|
|||
repeated RouteProto routes = 3; // status info on every routes | |||
|
|||
google.protobuf.Struct metadata = 4; // extra kwargs that will be used in executor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@app.api_route(**app_kwargs) | ||
async def post(body: input_model, response: Response): | ||
async def post(body: input_model, response: Response, request: Request): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @cenhao ,
The feature should be available with and without gateway.
Btw, would be cool to know about ur usecase and how u use/plan to use Jina
@JoanFM I'm happy to change the parameter to headers, but I'm afraid it's too close to |
it does not matter, header is something that is quite hidden from the Executor developer. I would still use |
40f0c60
to
e0b54de
Compare
This PR is attempts to implement the solution in the discussion of #6049. It adds a new parameter
metadata
for jina endpoints which can be used to pass in http headers or GRPC metadata.This PR only implements the http headers, GRPC metadata will have to be done in a separate PR
Goals:
TODO: