Skip to content

Commit 53d2c06

Browse files
author
Sherin Thomas
authored
Pick queue type only if specified (#15295)
Pick queue type only if specified (#15295)
1 parent 9c2164a commit 53d2c06

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

src/lightning_app/core/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_lightning_cloud_url() -> str:
2222
APP_SERVER_PORT = 7501
2323
APP_STATE_MAX_SIZE_BYTES = 1024 * 1024 # 1 MB
2424

25-
CLOUD_QUEUE_TYPE = os.getenv("LIGHTNING_CLOUD_QUEUE_TYPE", "redis")
25+
CLOUD_QUEUE_TYPE = os.getenv("LIGHTNING_CLOUD_QUEUE_TYPE", None)
2626
WARNING_QUEUE_SIZE = 1000
2727
# different flag because queue debug can be very noisy, and almost always not useful unless debugging the queue itself.
2828
QUEUE_DEBUG_ENABLED = bool(int(os.getenv("LIGHTNING_QUEUE_DEBUG_ENABLED", "0")))

src/lightning_app/runners/cloud.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,13 @@ def dispatch(
289289
find_instances_resp = self.backend.client.lightningapp_instance_service_list_lightningapp_instances(
290290
project_id=project.project_id, app_id=lit_app.id
291291
)
292-
queue_server_type = V1QueueServerType.REDIS if CLOUD_QUEUE_TYPE == "redis" else V1QueueServerType.HTTP
292+
293+
queue_server_type = V1QueueServerType.UNSPECIFIED
294+
if CLOUD_QUEUE_TYPE == "http":
295+
queue_server_type = V1QueueServerType.HTTP
296+
elif CLOUD_QUEUE_TYPE == "redis":
297+
queue_server_type = V1QueueServerType.REDIS
298+
293299
if find_instances_resp.lightningapps:
294300
existing_instance = find_instances_resp.lightningapps[0]
295301
if existing_instance.status.phase != V1LightningappInstanceState.STOPPED:

tests/tests_app/core/test_lightning_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ async def test_health_endpoint_success():
330330
@pytest.mark.anyio
331331
async def test_health_endpoint_failure(monkeypatch):
332332
monkeypatch.setenv("LIGHTNING_APP_STATE_URL", "http://someurl") # adding this to make is_running_in_cloud pass
333+
monkeypatch.setattr(api, "CLOUD_QUEUE_TYPE", "redis")
333334
async with AsyncClient(app=fastapi_service, base_url="http://test") as client:
334335
# will respond 503 if redis is not running
335336
response = await client.get("/healthz")

tests/tests_app/runners/test_cloud.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from lightning_cloud.openapi import (
99
Body8,
1010
Gridv1ImageSpec,
11+
IdGetBody,
1112
V1BuildSpec,
1213
V1DependencyFileInfo,
1314
V1Drive,
@@ -25,6 +26,7 @@
2526
V1PackageManager,
2627
V1ProjectClusterBinding,
2728
V1PythonDependencyInfo,
29+
V1QueueServerType,
2830
V1SourceType,
2931
V1UserRequestedComputeConfig,
3032
V1Work,
@@ -304,6 +306,62 @@ def test_call_with_work_app(self, lightningapps, monkeypatch, tmpdir):
304306
project_id="test-project-id", app_id=mock.ANY, id=mock.ANY, body=mock.ANY
305307
)
306308

309+
@mock.patch("lightning_app.runners.backends.cloud.LightningClient", mock.MagicMock())
310+
@pytest.mark.parametrize("lightningapps", [[], [MagicMock()]])
311+
def test_call_with_queue_server_type_specified(self, lightningapps, monkeypatch, tmpdir):
312+
mock_client = mock.MagicMock()
313+
mock_client.projects_service_list_memberships.return_value = V1ListMembershipsResponse(
314+
memberships=[V1Membership(name="test-project", project_id="test-project-id")]
315+
)
316+
mock_client.lightningapp_instance_service_list_lightningapp_instances.return_value = (
317+
V1ListLightningappInstancesResponse(lightningapps=[])
318+
)
319+
cloud_backend = mock.MagicMock()
320+
cloud_backend.client = mock_client
321+
monkeypatch.setattr(backends, "CloudBackend", mock.MagicMock(return_value=cloud_backend))
322+
monkeypatch.setattr(cloud, "LocalSourceCodeDir", mock.MagicMock())
323+
monkeypatch.setattr(cloud, "_prepare_lightning_wheels_and_requirements", mock.MagicMock())
324+
app = mock.MagicMock()
325+
app.flows = []
326+
app.frontend = {}
327+
cloud_runtime = cloud.CloudRuntime(app=app, entrypoint_file="entrypoint.py")
328+
cloud_runtime._check_uploaded_folder = mock.MagicMock()
329+
330+
# without requirements file
331+
# setting is_file to False so requirements.txt existence check will return False
332+
monkeypatch.setattr(Path, "is_file", lambda *args, **kwargs: False)
333+
monkeypatch.setattr(cloud, "Path", Path)
334+
cloud_runtime.dispatch()
335+
336+
# calling with no env variable set
337+
body = IdGetBody(
338+
cluster_id=None,
339+
desired_state=V1LightningappInstanceState.STOPPED,
340+
env=[],
341+
name=mock.ANY,
342+
queue_server_type=V1QueueServerType.UNSPECIFIED,
343+
)
344+
client = cloud_runtime.backend.client
345+
client.lightningapp_v2_service_create_lightningapp_release_instance.assert_called_once_with(
346+
project_id="test-project-id", app_id=mock.ANY, id=mock.ANY, body=body
347+
)
348+
349+
# calling with env variable set to http
350+
monkeypatch.setattr(cloud, "CLOUD_QUEUE_TYPE", "http")
351+
cloud_runtime.backend.client.reset_mock()
352+
cloud_runtime.dispatch()
353+
body = IdGetBody(
354+
cluster_id=None,
355+
desired_state=V1LightningappInstanceState.STOPPED,
356+
env=[],
357+
name=mock.ANY,
358+
queue_server_type=V1QueueServerType.HTTP,
359+
)
360+
client = cloud_runtime.backend.client
361+
client.lightningapp_v2_service_create_lightningapp_release_instance.assert_called_once_with(
362+
project_id="test-project-id", app_id=mock.ANY, id=mock.ANY, body=body
363+
)
364+
307365
@mock.patch("lightning_app.runners.backends.cloud.LightningClient", mock.MagicMock())
308366
@pytest.mark.parametrize("lightningapps", [[], [MagicMock()]])
309367
def test_call_with_work_app_and_attached_drives(self, lightningapps, monkeypatch, tmpdir):

tests/tests_app_examples/custom_work_dependencies/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class WorkWithCustomBaseImage(LightningWork):
2424
def __init__(self, cloud_compute: CloudCompute = CloudCompute(), **kwargs):
2525
# this image has been created from ghcr.io/gridai/base-images:v1.8-cpu
2626
# by just adding an empty file at /content/.e2e_test
27-
custom_image = "ghcr.io/gridai/image-for-testing-custom-images-in-e2e:v0.0.1"
27+
custom_image = "ghcr.io/gridai/image-for-testing-custom-images-in-e2e:v1.12"
2828
build_config = BuildConfig(image=custom_image)
2929
super().__init__(parallel=True, **kwargs, cloud_compute=cloud_compute, cloud_build_config=build_config)
3030

0 commit comments

Comments
 (0)