-
Notifications
You must be signed in to change notification settings - Fork 797
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
Customize route of API endpoint #1334
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1334 +/- ##
==========================================
+ Coverage 67.72% 67.82% +0.09%
==========================================
Files 150 150
Lines 10017 10029 +12
==========================================
+ Hits 6784 6802 +18
+ Misses 3233 3227 -6
Continue to review full report at Codecov.
|
8788ebe
to
6f7a4b5
Compare
bentoml/service/__init__.py
Outdated
@@ -66,11 +66,23 @@ def validate_inference_api_name(api_name: str): | |||
) | |||
|
|||
|
|||
def validate_inference_api_route(route: str): | |||
if re.findall(r"[?#]+|^(//)|^:", route): |
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.
Let's add documentation for the regex.
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.
Should we also invalidate route input like abc/123/
with trailing '/'?
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.
The route with a trailing "/" also works.
@@ -106,6 +106,22 @@ async def test_api_server_json(host): | |||
await asyncio.gather(*tasks) | |||
|
|||
|
|||
@pytest.mark.asyncio | |||
async def test_api_server_json_with_customized_route(host): |
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 am getting errors when I run pytest on api_server. 429 'Too Many Requests'
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's normal. It happens when your test server is busy.
bentoml/saved_bundle/config.py
Outdated
@@ -206,6 +208,12 @@ def get_bento_service_metadata_pb(self): | |||
else: | |||
api_metadata.mb_max_batch_size = DEFAULT_MAX_BATCH_SIZE | |||
|
|||
# Supports customize route from 0.10.2 |
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.
Remove this comment? the next release will be 0.11.0
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.
done
# Supports customize route from 0.10.2 | ||
if 'route' in api_config: | ||
api_metadata.route = api_config["route"] | ||
else: |
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.
suggest adding a comment here Use API name as the URL route when route config is missing, this is for backward compatibility for BentoML version <= 0.10.1
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.
done
bentoml/service/inference_api.py
Outdated
): | ||
""" | ||
:param service: ref to service containing this API | ||
:param name: API name | ||
:param route: API path (by default the same as `name`) |
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.
Suggest update:
:param route: Specify HTTP URL route of this inference API. By default,
`api.name` is used as the route. This parameter can be used for customizing
the URL route, e.g. `route="/api/v2/model_a/predict"`
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.
And should we move the docstring order to match the order of the actual parameter list in this method?
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.
done
bentoml/service/__init__.py
Outdated
@@ -85,6 +100,8 @@ def api_decorator( | |||
:param output: OutputAdapter instance of the inference API | |||
:param api_name: API name, default to the user-defined callback function's function | |||
name | |||
:param route: to customize the route of API |
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 as the suggestion above
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.
done
2da2149
to
125ff8c
Compare
3090ba0
to
22f37bc
Compare
@parano ready |
conflict resolved |
@@ -86,6 +101,10 @@ def api_decorator( | |||
:param output: OutputAdapter instance of the inference API | |||
:param api_name: API name, default to the user-defined callback function's function | |||
name | |||
:param route: Specify HTTP URL route of this inference API. By default, |
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.
one minor issue here is that we want to enforce that all inference APIs in a BentoService must have distinct route. previously it was not an issue because Python enforces users to choose a different function name implicitly, but now we may want to do a validation somewhere
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.
maybe something we could do in _config_inference_apis
below?
@@ -64,6 +67,36 @@ async def assert_request( | |||
'columns', | |||
} | |||
|
|||
def _since_version(ver: str): |
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.
👍
* add test for customized route * customize route * fix * add route test * add url character test * add illegal url characters test * add unittest for customize route * review * gen proto * fix * fix 2 * [CI] add `since_bentoml_version` for itests * fix * fix * fix3 * without docker Co-authored-by: ruhan <[email protected]>
Description
Motivation and Context
How Has This Been Tested?
Provided integration tests.
It also passed the backward compatibility tests. See #1370
Types of changes
Component(s) if applicable
Checklist:
./dev/format.sh
and./dev/lint.sh
script have passed(instructions).