Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

NarekA
Copy link
Contributor

@NarekA NarekA commented Dec 7, 2023

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:

  • Add tests
  • Add documentation

@@ -53,6 +53,7 @@
__args_executor_func__ = {
'docs',
'parameters',
'metadata',
Copy link
Contributor Author

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @JoanFM

Copy link
Member

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

@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will update this comment

Copy link
Member

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.

Copy link
Contributor Author

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"})
Copy link
Contributor Author

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):
Copy link

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?

Copy link

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.

@JoanFM

Copy link
Contributor Author

@NarekA NarekA Dec 7, 2023

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.

Copy link
Member

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

@NarekA NarekA requested a review from hanxiao as a code owner December 7, 2023 22:19
@NarekA NarekA force-pushed the feat-pass-headers-as-metadata-6049 branch from 0fb78c9 to d1450b0 Compare December 7, 2023 22:21
Copy link

codecov bot commented Dec 7, 2023

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (9eb4d09) 72.61% compared to head (2856423) 49.55%.
Report is 2 commits behind head on master.

Files Patch % Lines
jina/serve/runtimes/gateway/streamer.py 0.00% 8 Missing ⚠️
jina/serve/runtimes/worker/http_fastapi_app.py 0.00% 4 Missing ⚠️
...ve/runtimes/gateway/http_fastapi_app_docarrayv2.py 0.00% 2 Missing ⚠️
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     
Flag Coverage Δ
jina 49.55% <12.50%> (-23.06%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@JoanFM JoanFM left a 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.

@@ -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
Copy link
Member

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.

@@ -53,6 +53,7 @@
__args_executor_func__ = {
'docs',
'parameters',
'metadata',
Copy link
Member

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'
Copy link
Member

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.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

same here

@@ -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
Copy link
Member

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):
Copy link
Member

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

@NarekA
Copy link
Contributor Author

NarekA commented Dec 12, 2023

@JoanFM I'm happy to change the parameter to headers, but I'm afraid it's too close to header which I've noticed is used for passing request_id during orchestration. How about request_headers?

@JoanFM
Copy link
Member

JoanFM commented Dec 12, 2023

@JoanFM I'm happy to change the parameter to headers, but I'm afraid it's too close to header which I've noticed is used for passing request_id during orchestration. How about request_headers?

it does not matter, header is something that is quite hidden from the Executor developer. I would still use headers

@NarekA NarekA force-pushed the feat-pass-headers-as-metadata-6049 branch from 40f0c60 to e0b54de Compare December 13, 2023 13:50
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.

Best Way to Pass Request Headers to Executor
3 participants