Skip to content

Commit 01fda0f

Browse files
committed
Exclude until_ready from requests when not set
Also make it optional in the configuration for more reliable detection of whether it is set.
1 parent 6452158 commit 01fda0f

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

src/dstack/_internal/core/compatibility/runs.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from typing import Optional
22

33
from dstack._internal.core.models.common import IncludeExcludeDictType, IncludeExcludeSetType
4+
from dstack._internal.core.models.configurations import ServiceConfiguration
45
from dstack._internal.core.models.runs import (
6+
DEFAULT_PROBE_UNTIL_READY,
57
DEFAULT_REPLICA_GROUP_NAME,
68
ApplyRunPlanInput,
79
JobSpec,
@@ -60,12 +62,12 @@ def get_run_spec_excludes(run_spec: RunSpec) -> IncludeExcludeDictType:
6062
configuration_excludes: IncludeExcludeDictType = {}
6163
profile_excludes: IncludeExcludeSetType = set()
6264

63-
# Add excludes like this:
64-
#
65-
# if run_spec.configuration.tags is None:
66-
# configuration_excludes["tags"] = True
67-
# if run_spec.profile is not None and run_spec.profile.tags is None:
68-
# profile_excludes.add("tags")
65+
if isinstance(run_spec.configuration, ServiceConfiguration):
66+
if run_spec.configuration.probes:
67+
probe_excludes: IncludeExcludeDictType = {}
68+
configuration_excludes["probes"] = {"__all__": probe_excludes}
69+
if all(p.until_ready is None for p in run_spec.configuration.probes):
70+
probe_excludes["until_ready"] = True
6971

7072
if configuration_excludes:
7173
spec_excludes["configuration"] = configuration_excludes
@@ -83,4 +85,10 @@ def get_job_spec_excludes(job_specs: list[JobSpec]) -> IncludeExcludeDictType:
8385
spec_excludes: IncludeExcludeDictType = {}
8486
if all(s.replica_group == DEFAULT_REPLICA_GROUP_NAME for s in job_specs):
8587
spec_excludes["replica_group"] = True
88+
89+
probe_excludes: IncludeExcludeDictType = {}
90+
spec_excludes["probes"] = {"__all__": probe_excludes}
91+
if all(all(p.until_ready == DEFAULT_PROBE_UNTIL_READY for p in s.probes) for s in job_specs):
92+
probe_excludes["until_ready"] = True
93+
8694
return spec_excludes

src/dstack/_internal/core/models/configurations.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
DEFAULT_PROBE_INTERVAL = 15
5555
DEFAULT_PROBE_READY_AFTER = 1
5656
DEFAULT_PROBE_METHOD = "get"
57+
DEFAULT_PROBE_UNTIL_READY = False
5758
MAX_PROBE_URL_LEN = 2048
5859
DEFAULT_REPLICA_GROUP_NAME = "0"
5960

@@ -373,15 +374,15 @@ class ProbeConfig(generate_dual_core_model(ProbeConfigConfig)):
373374
),
374375
] = None
375376
until_ready: Annotated[
376-
bool,
377+
Optional[bool],
377378
Field(
378379
description=(
379380
"If `true`, the probe will stop being executed as soon as it reaches the"
380381
" `ready_after` threshold of successful executions."
381-
" Defaults to `false`"
382+
f" Defaults to `{str(DEFAULT_PROBE_UNTIL_READY).lower()}`"
382383
),
383384
),
384-
] = False
385+
] = None
385386

386387
@validator("timeout", pre=True)
387388
def parse_timeout(cls, v: Optional[Union[int, str]]) -> Optional[int]:

src/dstack/_internal/core/models/runs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818
from dstack._internal.core.models.configurations import (
1919
DEFAULT_PROBE_METHOD,
20+
DEFAULT_PROBE_UNTIL_READY,
2021
DEFAULT_REPLICA_GROUP_NAME,
2122
LEGACY_REPO_DIR,
2223
AnyRunConfiguration,
@@ -247,7 +248,7 @@ class ProbeSpec(CoreModel):
247248
timeout: int
248249
interval: int
249250
ready_after: int
250-
until_ready: bool = False
251+
until_ready: bool = DEFAULT_PROBE_UNTIL_READY
251252

252253

253254
class JobSpec(CoreModel):

src/dstack/_internal/server/services/jobs/configurators/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
DEFAULT_PROBE_METHOD,
1616
DEFAULT_PROBE_READY_AFTER,
1717
DEFAULT_PROBE_TIMEOUT,
18+
DEFAULT_PROBE_UNTIL_READY,
1819
DEFAULT_PROBE_URL,
1920
DEFAULT_REPLICA_GROUP_NAME,
2021
LEGACY_REPO_DIR,
@@ -444,7 +445,7 @@ def _probe_config_to_spec(c: ProbeConfig) -> ProbeSpec:
444445
method=c.method if c.method is not None else DEFAULT_PROBE_METHOD,
445446
headers=c.headers,
446447
body=c.body,
447-
until_ready=c.until_ready,
448+
until_ready=c.until_ready if c.until_ready is not None else DEFAULT_PROBE_UNTIL_READY,
448449
)
449450

450451

0 commit comments

Comments
 (0)