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

Removing field validator for resolving spacy and pydantic conflict. #2086

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, field_validator, NonNegativeInt, NonNegativeFloat
from pydantic import BaseModel, NonNegativeInt, NonNegativeFloat, validator


class AutoscalingPolicy(BaseModel):
Expand Down Expand Up @@ -70,9 +70,10 @@ class EWMPolicy(AutoscalingPolicy):
ub_threshold: NonNegativeFloat # recommended value: 0.5
lb_threshold: NonNegativeFloat # recommended value: 0.5

@field_validator("metric")
def validate_option(cls, v):
assert v in ["ewm_latency", "ewm_qps"]
@validator("metric")
def metric_match(cls, v) -> str:
if v not in ["ewm_latency", "ewm_qps"]:
raise ValueError("Wrong metric name.")
return v


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ def test_validate_scaling_bounds(self):

# Validate scale up.
scale_up = autoscaler.validate_scaling_bounds(ScaleOp.UP_OUT_OP, autoscaling_policy)
self.assertEquals(scale_up, ScaleOp.UP_OUT_OP)
self.assertEqual(scale_up, ScaleOp.UP_OUT_OP)

# Validate scale down.
scale_down = autoscaler.validate_scaling_bounds(ScaleOp.DOWN_IN_OP, autoscaling_policy)
self.assertEquals(scale_down, ScaleOp.DOWN_IN_OP)
self.assertEqual(scale_down, ScaleOp.DOWN_IN_OP)

# Validate max out-of-bounds.
autoscaling_policy.current_replicas = 3
scale_oob_max = autoscaler.validate_scaling_bounds(ScaleOp.UP_OUT_OP, autoscaling_policy)
self.assertEquals(scale_oob_max, ScaleOp.NO_OP)
self.assertEqual(scale_oob_max, ScaleOp.NO_OP)

# Validate min out-of-bounds.
autoscaling_policy.current_replicas = 1
scale_oob_min = autoscaler.validate_scaling_bounds(ScaleOp.DOWN_IN_OP, autoscaling_policy)
self.assertEquals(scale_oob_min, ScaleOp.NO_OP)
self.assertEqual(scale_oob_min, ScaleOp.NO_OP)

def test_enforce_scaling_down_delay_interval(self):
self.populate_redis_with_dummy_metrics()
Expand All @@ -140,15 +140,15 @@ def test_enforce_scaling_down_delay_interval(self):

autoscaling_policy.scaledown_delay_secs = 0.0
scale_down = autoscaler.enforce_scaling_down_delay_interval(ENV_ENDPOINT_ID_1, autoscaling_policy)
self.assertEquals(scale_down, ScaleOp.DOWN_IN_OP)
self.assertEqual(scale_down, ScaleOp.DOWN_IN_OP)

autoscaling_policy.scaledown_delay_secs = 1
scale_noop = autoscaler.enforce_scaling_down_delay_interval(ENV_ENDPOINT_ID_1, autoscaling_policy)
self.assertEquals(scale_noop, ScaleOp.NO_OP)
self.assertEqual(scale_noop, ScaleOp.NO_OP)

time.sleep(2)
scale_down = autoscaler.enforce_scaling_down_delay_interval(ENV_ENDPOINT_ID_1, autoscaling_policy)
self.assertEquals(scale_down, ScaleOp.DOWN_IN_OP)
self.assertEqual(scale_down, ScaleOp.DOWN_IN_OP)
self.clear_redis()


Expand Down
Loading