Skip to content

Commit

Permalink
Drop the PROXY feature flag (#1971)
Browse files Browse the repository at this point in the history
Also add a setting to forbid new services without
a gateway. This setting will likely be used in Sky
  • Loading branch information
jvstme authored Nov 7, 2024
1 parent 4bd8351 commit 8eb9b15
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 23 deletions.
1 change: 1 addition & 0 deletions docs/docs/reference/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ $ dstack pool delete --help
* `DSTACK_SERVER_CLOUDWATCH_LOG_GROUP` – (Optional) The CloudWatch Logs group for workloads logs. If not set, the default file-based log storage is used.
* `DSTACK_SERVER_CLOUDWATCH_LOG_REGION` — (Optional) The CloudWatch Logs region. Defaults to `None`.
* `DSTACK_DEFAULT_SERVICE_CLIENT_MAX_BODY_SIZE` – (Optional) Request body size limit for services, in bytes. Defaults to 64 MiB.
* `DSTACK_FORBID_SERVICES_WITHOUT_GATEWAY` - (Optional) Forbids registering new services without a gateway if set to any value.
* `DSTACK_SERVER_DIR` – (Optional) Sets path to store data and server configs. Defaults to `~/.dstack/server`.

??? info "Internal environment variables"
Expand Down
12 changes: 3 additions & 9 deletions src/dstack/_internal/core/models/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from dstack._internal.core.models.repos.virtual import VirtualRepo
from dstack._internal.core.models.resources import Range, ResourcesSpec
from dstack._internal.core.models.volumes import MountPoint, VolumeConfiguration, parse_mount_point
from dstack._internal.settings import FeatureFlags

CommandsList = List[str]
ValidPort = conint(gt=0, le=65536)
Expand Down Expand Up @@ -221,14 +220,9 @@ class ServiceConfigurationParams(CoreModel):
)
),
] = None
https: Annotated[
bool,
Field(
description="Enable HTTPS"
if not FeatureFlags.PROXY
else "Enable HTTPS if running with a gateway"
),
] = SERVICE_HTTPS_DEFAULT
https: Annotated[bool, Field(description="Enable HTTPS if running with a gateway")] = (
SERVICE_HTTPS_DEFAULT
)
auth: Annotated[bool, Field(description="Enable the authorization")] = True
replicas: Annotated[
Union[conint(ge=1), constr(regex=r"^[0-9]+..[1-9][0-9]*$"), Range[int]],
Expand Down
13 changes: 4 additions & 9 deletions src/dstack/_internal/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
error_detail,
get_server_client_error_details,
)
from dstack._internal.settings import DSTACK_VERSION, FeatureFlags
from dstack._internal.settings import DSTACK_VERSION
from dstack._internal.utils.logging import get_logger
from dstack._internal.utils.ssh import check_required_ssh_version

Expand Down Expand Up @@ -176,9 +176,8 @@ def register_routes(app: FastAPI, ui: bool = True):
app.include_router(gateways.router)
app.include_router(volumes.root_router)
app.include_router(volumes.project_router)
if FeatureFlags.PROXY:
app.include_router(service_proxy.router, prefix="/proxy/services", tags=["service-proxy"])
app.include_router(model_proxy.router, prefix="/proxy/models", tags=["model-proxy"])
app.include_router(service_proxy.router, prefix="/proxy/services", tags=["service-proxy"])
app.include_router(model_proxy.router, prefix="/proxy/models", tags=["model-proxy"])

@app.exception_handler(ForbiddenError)
async def forbidden_error_handler(request: Request, exc: ForbiddenError):
Expand Down Expand Up @@ -242,11 +241,7 @@ async def healthcheck():

@app.exception_handler(404)
async def custom_http_exception_handler(request, exc):
if (
request.url.path.startswith("/api")
or FeatureFlags.PROXY
and _is_proxy_request(request)
):
if request.url.path.startswith("/api") or _is_proxy_request(request):
return JSONResponse(
{"detail": exc.detail},
status_code=status.HTTP_404_NOT_FOUND,
Expand Down
8 changes: 5 additions & 3 deletions src/dstack/_internal/server/services/gateways/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
gather_map_async,
run_async,
)
from dstack._internal.settings import FeatureFlags
from dstack._internal.utils.common import get_current_datetime
from dstack._internal.utils.crypto import generate_rsa_key_pair_bytes
from dstack._internal.utils.logging import get_logger
Expand Down Expand Up @@ -361,10 +360,13 @@ async def register_service(session: AsyncSession, run_model: RunModel):
if gateway is not None:
service_spec = await _register_service_in_gateway(session, run_model, gateway)
run_model.gateway = gateway
elif FeatureFlags.PROXY:
elif not settings.FORBID_SERVICES_WITHOUT_GATEWAY:
service_spec = _register_service_in_server(run_model)
else:
raise ResourceNotExistsError("Default gateway is not set")
raise ResourceNotExistsError(
"This dstack-server installation forbids services without a gateway."
" Please configure a default gateway."
)
run_model.service_spec = service_spec.json()


Expand Down
1 change: 1 addition & 0 deletions src/dstack/_internal/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
)

USER_PROJECT_DEFAULT_QUOTA = int(os.getenv("DSTACK_USER_PROJECT_DEFAULT_QUOTA", 10))
FORBID_SERVICES_WITHOUT_GATEWAY = os.getenv("DSTACK_FORBID_SERVICES_WITHOUT_GATEWAY") is not None


# Development settings
Expand Down
2 changes: 0 additions & 2 deletions src/dstack/_internal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ class FeatureFlags:
large features. This class may be empty if there are no such features in
development. Feature flags are environment variables of the form DSTACK_FF_*
"""

PROXY = bool(os.getenv("DSTACK_FF_PROXY"))

0 comments on commit 8eb9b15

Please sign in to comment.