Skip to content

Commit

Permalink
chore: add validation for limit value
Browse files Browse the repository at this point in the history
Signed-off-by: TomeHirata <tomu.hirata@gmail.com>
  • Loading branch information
TomeHirata committed Jan 18, 2024
1 parent 124d651 commit 7736327
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions mlflow/gateway/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pydantic
import yaml
from limits import parse
from packaging import version
from packaging.version import Version
from pydantic import ConfigDict, Field, ValidationError, root_validator, validator
Expand Down Expand Up @@ -398,6 +399,20 @@ def validate_route_type(cls, value):
return value
raise MlflowException.invalid_parameter_value(f"The route_type '{value}' is not supported.")

@validator("limit", pre=True)
def validate_limit(cls, value: Optional[Limit]):
if value:
try:
parse(f"{value.calls}/{value.renewal_period}")
except ValueError:
raise MlflowException.invalid_parameter_value(
"Failed to parse the rate limit configuration."
"Please make sure limit.calls is a positive number and"
"limit.renewal_period is a right granularity"
)

return value

def to_route(self) -> "Route":
return Route(
name=self.name,
Expand Down
2 changes: 1 addition & 1 deletion tests/gateway/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class UvicornGateway:
# this module which executes the uvicorn server through gunicorn as a process manager.
def __init__(self, config_path: Union[str, Path], *args, **kwargs):
self.port = get_safe_port()
self.host = "localhost"
self.host = "127.0.0.1"
self.url = f"http://{self.host}:{self.port}"
self.config_path = config_path
self.server = None
Expand Down

0 comments on commit 7736327

Please sign in to comment.