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

Fixed the YAML schema validation for replicas #1055

Merged
merged 2 commits into from
Apr 2, 2024

Conversation

peterschmidt85
Copy link
Contributor

Previously, the YAML schema showed errors if replicas was set to a str or int

Copy link
Collaborator

@jvstme jvstme left a comment

Choose a reason for hiding this comment

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

Apparently, to avoid the type checking and code duplication issues (see comments below), we manipulate the JSON schema directly in other places where Range is used, see ResourcesSpec. I'd suggest we try the same thing here with replicas. Or we can merge as is and come back to it later

replicas: Annotated[Range[int], Field(description="The range ")] = Range[int](min=1, max=1)
replicas: Annotated[
Union[conint(ge=1), constr(regex=r"^[0-9]+..[1-9][0-9]*$"), Range[int]],
Field(description="The range "),
Copy link
Collaborator

Choose a reason for hiding this comment

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

(off-topic) Not very descriptive

raise ValueError("The minimum number of replicas must be greater than or equal to 0")
if v.max < v.min:
raise ValueError(
"The maximum number of replicas must be greater than the minium number of replicas"
Copy link
Collaborator

Choose a reason for hiding this comment

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

(nit) Technically, greater than or equal

@@ -233,7 +233,10 @@ class ServiceConfiguration(BaseConfiguration):
Field(description="Mapping of the model for the OpenAI-compatible endpoint"),
] = None
auth: Annotated[bool, Field(description="Enable the authorization")] = True
replicas: Annotated[Range[int], Field(description="The range ")] = Range[int](min=1, max=1)
replicas: Annotated[
Union[conint(ge=1), constr(regex=r"^[0-9]+..[1-9][0-9]*$"), Range[int]],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm afraid this breaks type checking. The type checker sees replicas as Union[int, str, Range[int]], but we use it specifically as Range[int] (1, 2, 3, etc)

@@ -247,25 +250,30 @@ def convert_port(cls, v) -> PortMapping:
return v

@validator("replicas")
def convert_replicas(cls, v: Range[int]) -> Range[int]:
def convert_replicas(cls, v: Any) -> Range[int]:
if isinstance(v, str) and ".." in v:
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not perfect that we duplicate range parsing logic. It is already implemented in Range

@peterschmidt85
Copy link
Contributor Author

Apparently, to avoid the type checking and code duplication issues (see comments below), we manipulate the JSON schema directly in other places where Range is used, see ResourcesSpec. I'd suggest we try the same thing here with replicas. Or we can merge as is and come back to it later

Yeah, I was also thinking of it. The problem is we have a mess there already. Look at ResourcesSpec and ResourcesSpecSchema. I'd perhaps right now add a test, and leave it as is. And later, come back and fix the mess.

@peterschmidt85
Copy link
Contributor Author

@jvstme I've added the test. Let me know if it's OK to merge

).replicas == Range(min=0, max=10)
with pytest.raises(
ConfigurationError,
match="When you set `replicas` to a range, ensure to specify `scaling`",
Copy link
Collaborator

Choose a reason for hiding this comment

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

(nit) I think the primary error here is unexpected value; permitted: 'rps'. The ensure to specify scaling error also appears, but as a consequence of the primary error

@jvstme
Copy link
Collaborator

jvstme commented Apr 2, 2024

@peterschmidt85, thank you! I think it's ok to merge

@peterschmidt85 peterschmidt85 merged commit fbc737c into master Apr 2, 2024
15 checks passed
@jvstme jvstme deleted the improve-service-replicas-yaml-scheme branch April 4, 2024 09:31
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.

None yet

2 participants