Skip to content

Commit beae48f

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Allow configuring container logging settings on models when deploying.
PiperOrigin-RevId: 588105589
1 parent 7938d48 commit beae48f

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

google/cloud/aiplatform/models.py

+27
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ def deploy(
782782
autoscaling_target_cpu_utilization: Optional[int] = None,
783783
autoscaling_target_accelerator_duty_cycle: Optional[int] = None,
784784
enable_access_logging=False,
785+
disable_container_logging: bool = False,
785786
) -> None:
786787
"""Deploys a Model to the Endpoint.
787788
@@ -864,6 +865,9 @@ def deploy(
864865
A default value of 60 will be used if not specified.
865866
enable_access_logging (bool):
866867
Whether to enable endpoint access logging. Defaults to False.
868+
disable_container_logging (bool):
869+
If True, container logs from the deployed model will not be
870+
written to Cloud Logging. Defaults to False.
867871
"""
868872
self._sync_gca_resource_if_skipped()
869873

@@ -899,6 +903,7 @@ def deploy(
899903
autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization,
900904
autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle,
901905
enable_access_logging=enable_access_logging,
906+
disable_container_logging=disable_container_logging,
902907
)
903908

904909
@base.optional_sync()
@@ -921,6 +926,7 @@ def _deploy(
921926
autoscaling_target_cpu_utilization: Optional[int] = None,
922927
autoscaling_target_accelerator_duty_cycle: Optional[int] = None,
923928
enable_access_logging=False,
929+
disable_container_logging: bool = False,
924930
) -> None:
925931
"""Deploys a Model to the Endpoint.
926932
@@ -997,6 +1003,9 @@ def _deploy(
9971003
A default value of 60 will be used if not specified.
9981004
enable_access_logging (bool):
9991005
Whether to enable endpoint access logging. Defaults to False.
1006+
disable_container_logging (bool):
1007+
If True, container logs from the deployed model will not be
1008+
written to Cloud Logging. Defaults to False.
10001009
"""
10011010
_LOGGER.log_action_start_against_resource(
10021011
f"Deploying Model {model.resource_name} to", "", self
@@ -1023,6 +1032,7 @@ def _deploy(
10231032
autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization,
10241033
autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle,
10251034
enable_access_logging=enable_access_logging,
1035+
disable_container_logging=disable_container_logging,
10261036
)
10271037

10281038
_LOGGER.log_action_completed_against_resource("model", "deployed", self)
@@ -1052,6 +1062,7 @@ def _deploy_call(
10521062
autoscaling_target_cpu_utilization: Optional[int] = None,
10531063
autoscaling_target_accelerator_duty_cycle: Optional[int] = None,
10541064
enable_access_logging=False,
1065+
disable_container_logging: bool = False,
10551066
) -> None:
10561067
"""Helper method to deploy model to endpoint.
10571068
@@ -1135,6 +1146,9 @@ def _deploy_call(
11351146
A default value of 60 will be used if not specified.
11361147
enable_access_logging (bool):
11371148
Whether to enable endpoint access logging. Defaults to False.
1149+
disable_container_logging (bool):
1150+
If True, container logs from the deployed model will not be
1151+
written to Cloud Logging. Defaults to False.
11381152
11391153
Raises:
11401154
ValueError: If only `accelerator_type` or `accelerator_count` is specified.
@@ -1165,6 +1179,7 @@ def _deploy_call(
11651179
display_name=deployed_model_display_name,
11661180
service_account=service_account,
11671181
enable_access_logging=enable_access_logging,
1182+
disable_container_logging=disable_container_logging,
11681183
)
11691184

11701185
supports_automatic_resources = (
@@ -2420,6 +2435,7 @@ def deploy(
24202435
] = None,
24212436
metadata: Optional[Sequence[Tuple[str, str]]] = (),
24222437
sync=True,
2438+
disable_container_logging: bool = False,
24232439
) -> None:
24242440
"""Deploys a Model to the PrivateEndpoint.
24252441
@@ -2510,6 +2526,7 @@ def deploy(
25102526
explanation_spec=explanation_spec,
25112527
metadata=metadata,
25122528
sync=sync,
2529+
disable_container_logging=disable_container_logging,
25132530
)
25142531

25152532
def undeploy(
@@ -3408,6 +3425,7 @@ def deploy(
34083425
autoscaling_target_cpu_utilization: Optional[int] = None,
34093426
autoscaling_target_accelerator_duty_cycle: Optional[int] = None,
34103427
enable_access_logging=False,
3428+
disable_container_logging: bool = False,
34113429
) -> Union[Endpoint, PrivateEndpoint]:
34123430
"""Deploys model to endpoint. Endpoint will be created if unspecified.
34133431
@@ -3508,6 +3526,9 @@ def deploy(
35083526
A default value of 60 will be used if not specified.
35093527
enable_access_logging (bool):
35103528
Whether to enable endpoint access logging. Defaults to False.
3529+
disable_container_logging (bool):
3530+
If True, container logs from the deployed model will not be
3531+
written to Cloud Logging. Defaults to False.
35113532
35123533
Returns:
35133534
endpoint (Union[Endpoint, PrivateEndpoint]):
@@ -3561,6 +3582,7 @@ def deploy(
35613582
autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization,
35623583
autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle,
35633584
enable_access_logging=enable_access_logging,
3585+
disable_container_logging=disable_container_logging,
35643586
)
35653587

35663588
@base.optional_sync(return_input_arg="endpoint", bind_future_to_self=False)
@@ -3585,6 +3607,7 @@ def _deploy(
35853607
autoscaling_target_cpu_utilization: Optional[int] = None,
35863608
autoscaling_target_accelerator_duty_cycle: Optional[int] = None,
35873609
enable_access_logging=False,
3610+
disable_container_logging: bool = False,
35883611
) -> Union[Endpoint, PrivateEndpoint]:
35893612
"""Deploys model to endpoint. Endpoint will be created if unspecified.
35903613
@@ -3678,6 +3701,9 @@ def _deploy(
36783701
A default value of 60 will be used if not specified.
36793702
enable_access_logging (bool):
36803703
Whether to enable endpoint access logging. Defaults to False.
3704+
disable_container_logging (bool):
3705+
If True, container logs from the deployed model will not be
3706+
written to Cloud Logging. Defaults to False.
36813707
36823708
Returns:
36833709
endpoint (Union[Endpoint, PrivateEndpoint]):
@@ -3728,6 +3754,7 @@ def _deploy(
37283754
autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization,
37293755
autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle,
37303756
enable_access_logging=enable_access_logging,
3757+
disable_container_logging=disable_container_logging,
37313758
)
37323759

37333760
_LOGGER.log_action_completed_against_resource("model", "deployed", endpoint)

google/cloud/aiplatform/preview/models.py

+28
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ def deploy(
578578
autoscaling_target_cpu_utilization: Optional[int] = None,
579579
autoscaling_target_accelerator_duty_cycle: Optional[int] = None,
580580
deployment_resource_pool: Optional[DeploymentResourcePool] = None,
581+
disable_container_logging: bool = False,
581582
) -> None:
582583
"""Deploys a Model to the Endpoint.
583584
@@ -656,6 +657,10 @@ def deploy(
656657
are deployed to the same DeploymentResourcePool will be hosted in
657658
a shared model server. If provided, will override replica count
658659
arguments.
660+
disable_container_logging (bool):
661+
If True, container logs from the deployed model will not be
662+
written to Cloud Logging. Defaults to False.
663+
659664
"""
660665
self._sync_gca_resource_if_skipped()
661666

@@ -692,6 +697,7 @@ def deploy(
692697
autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization,
693698
autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle,
694699
deployment_resource_pool=deployment_resource_pool,
700+
disable_container_logging=disable_container_logging,
695701
)
696702

697703
@base.optional_sync()
@@ -714,6 +720,7 @@ def _deploy(
714720
autoscaling_target_cpu_utilization: Optional[int] = None,
715721
autoscaling_target_accelerator_duty_cycle: Optional[int] = None,
716722
deployment_resource_pool: Optional[DeploymentResourcePool] = None,
723+
disable_container_logging: bool = False,
717724
) -> None:
718725
"""Deploys a Model to the Endpoint.
719726
@@ -786,6 +793,10 @@ def _deploy(
786793
are deployed to the same DeploymentResourcePool will be hosted in
787794
a shared model server. If provided, will override replica count
788795
arguments.
796+
disable_container_logging (bool):
797+
If True, container logs from the deployed model will not be
798+
written to Cloud Logging. Defaults to False.
799+
789800
"""
790801
_LOGGER.log_action_start_against_resource(
791802
f"Deploying Model {model.resource_name} to", "", self
@@ -812,6 +823,7 @@ def _deploy(
812823
autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization,
813824
autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle,
814825
deployment_resource_pool=deployment_resource_pool,
826+
disable_container_logging=disable_container_logging,
815827
)
816828

817829
_LOGGER.log_action_completed_against_resource("model", "deployed", self)
@@ -841,6 +853,7 @@ def _deploy_call(
841853
autoscaling_target_cpu_utilization: Optional[int] = None,
842854
autoscaling_target_accelerator_duty_cycle: Optional[int] = None,
843855
deployment_resource_pool: Optional[DeploymentResourcePool] = None,
856+
disable_container_logging: bool = False,
844857
) -> None:
845858
"""Helper method to deploy model to endpoint.
846859
@@ -920,6 +933,9 @@ def _deploy_call(
920933
are deployed to the same DeploymentResourcePool will be hosted in
921934
a shared model server. If provided, will override replica count
922935
arguments.
936+
disable_container_logging (bool):
937+
If True, container logs from the deployed model will not be
938+
written to Cloud Logging. Defaults to False.
923939
924940
Raises:
925941
ValueError: If only `accelerator_type` or `accelerator_count` is
@@ -953,12 +969,14 @@ def _deploy_call(
953969
deploy_request_timeout=deploy_request_timeout,
954970
autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization,
955971
autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle,
972+
disable_container_logging=disable_container_logging,
956973
)
957974

958975
deployed_model = gca_endpoint_compat.DeployedModel(
959976
model=model.versioned_resource_name,
960977
display_name=deployed_model_display_name,
961978
service_account=service_account,
979+
enable_container_logging=not disable_container_logging,
962980
)
963981

964982
_LOGGER.info(model.supported_deployment_resources_types)
@@ -1237,6 +1255,7 @@ def deploy(
12371255
autoscaling_target_cpu_utilization: Optional[int] = None,
12381256
autoscaling_target_accelerator_duty_cycle: Optional[int] = None,
12391257
deployment_resource_pool: Optional[DeploymentResourcePool] = None,
1258+
disable_container_logging: bool = False,
12401259
) -> Union[Endpoint, models.PrivateEndpoint]:
12411260
"""Deploys model to endpoint.
12421261
@@ -1336,6 +1355,9 @@ def deploy(
13361355
are deployed to the same DeploymentResourcePool will be hosted in
13371356
a shared model server. If provided, will override replica count
13381357
arguments.
1358+
disable_container_logging (bool):
1359+
If True, container logs from the deployed model will not be
1360+
written to Cloud Logging. Defaults to False.
13391361
13401362
Returns:
13411363
endpoint (Union[Endpoint, models.PrivateEndpoint]):
@@ -1390,6 +1412,7 @@ def deploy(
13901412
autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization,
13911413
autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle,
13921414
deployment_resource_pool=deployment_resource_pool,
1415+
disable_container_logging=disable_container_logging,
13931416
)
13941417

13951418
@base.optional_sync(return_input_arg="endpoint", bind_future_to_self=False)
@@ -1414,6 +1437,7 @@ def _deploy(
14141437
autoscaling_target_cpu_utilization: Optional[int] = None,
14151438
autoscaling_target_accelerator_duty_cycle: Optional[int] = None,
14161439
deployment_resource_pool: Optional[DeploymentResourcePool] = None,
1440+
disable_container_logging: bool = False,
14171441
) -> Union[Endpoint, models.PrivateEndpoint]:
14181442
"""Deploys model to endpoint.
14191443
@@ -1505,6 +1529,9 @@ def _deploy(
15051529
are deployed to the same DeploymentResourcePool will be hosted in
15061530
a shared model server. If provided, will override replica count
15071531
arguments.
1532+
disable_container_logging (bool):
1533+
If True, container logs from the deployed model will not be
1534+
written to Cloud Logging. Defaults to False.
15081535
15091536
Returns:
15101537
endpoint (Union[Endpoint, models.PrivateEndpoint]):
@@ -1555,6 +1582,7 @@ def _deploy(
15551582
autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization,
15561583
autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle,
15571584
deployment_resource_pool=deployment_resource_pool,
1585+
disable_container_logging=disable_container_logging,
15581586
)
15591587

15601588
_LOGGER.log_action_completed_against_resource("model", "deployed", endpoint)

tests/unit/aiplatform/test_endpoints.py

+37
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,42 @@ def test_deploy_with_max_replica_count(self, deploy_model_mock, sync):
16761676
timeout=None,
16771677
)
16781678

1679+
@pytest.mark.usefixtures("get_endpoint_mock", "get_model_mock")
1680+
@pytest.mark.parametrize("sync", [True, False])
1681+
def test_deploy_disable_container_logging(self, deploy_model_mock, sync):
1682+
test_endpoint = models.Endpoint(_TEST_ENDPOINT_NAME)
1683+
test_model = models.Model(_TEST_ID)
1684+
test_model._gca_resource.supported_deployment_resources_types.append(
1685+
aiplatform.gapic.Model.DeploymentResourcesType.AUTOMATIC_RESOURCES
1686+
)
1687+
test_endpoint.deploy(
1688+
test_model,
1689+
sync=sync,
1690+
deploy_request_timeout=None,
1691+
disable_container_logging=True,
1692+
)
1693+
1694+
if not sync:
1695+
test_endpoint.wait()
1696+
1697+
automatic_resources = gca_machine_resources.AutomaticResources(
1698+
min_replica_count=1,
1699+
max_replica_count=1,
1700+
)
1701+
deployed_model = gca_endpoint.DeployedModel(
1702+
automatic_resources=automatic_resources,
1703+
model=test_model.resource_name,
1704+
display_name=None,
1705+
disable_container_logging=True,
1706+
)
1707+
deploy_model_mock.assert_called_once_with(
1708+
endpoint=test_endpoint.resource_name,
1709+
deployed_model=deployed_model,
1710+
traffic_split={"0": 100},
1711+
metadata=(),
1712+
timeout=None,
1713+
)
1714+
16791715
@pytest.mark.usefixtures("get_endpoint_mock", "get_model_mock", "get_drp_mock")
16801716
@pytest.mark.parametrize("sync", [True, False])
16811717
def test_preview_deploy_with_deployment_resource_pool(
@@ -1701,6 +1737,7 @@ def test_preview_deploy_with_deployment_resource_pool(
17011737
shared_resources=_TEST_DRP_NAME,
17021738
model=test_model.resource_name,
17031739
display_name=None,
1740+
enable_container_logging=True,
17041741
)
17051742
preview_deploy_model_mock.assert_called_once_with(
17061743
endpoint=test_endpoint.resource_name,

tests/unit/aiplatform/test_models.py

+42
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,47 @@ def test_deploy_no_endpoint_with_network(self, deploy_model_mock):
21712171
timeout=None,
21722172
)
21732173

2174+
@pytest.mark.usefixtures("get_endpoint_mock", "get_model_mock")
2175+
@pytest.mark.parametrize("sync", [True, False])
2176+
def test_deploy_disable_container_logging(self, deploy_model_mock, sync):
2177+
2178+
test_model = models.Model(_TEST_ID)
2179+
test_model._gca_resource.supported_deployment_resources_types.append(
2180+
aiplatform.gapic.Model.DeploymentResourcesType.AUTOMATIC_RESOURCES
2181+
)
2182+
2183+
test_endpoint = models.Endpoint(_TEST_ID)
2184+
2185+
assert (
2186+
test_model.deploy(
2187+
test_endpoint,
2188+
disable_container_logging=True,
2189+
sync=sync,
2190+
)
2191+
== test_endpoint
2192+
)
2193+
2194+
if not sync:
2195+
test_endpoint.wait()
2196+
2197+
automatic_resources = gca_machine_resources.AutomaticResources(
2198+
min_replica_count=1,
2199+
max_replica_count=1,
2200+
)
2201+
deployed_model = gca_endpoint.DeployedModel(
2202+
automatic_resources=automatic_resources,
2203+
model=test_model.resource_name,
2204+
display_name=None,
2205+
disable_container_logging=True,
2206+
)
2207+
deploy_model_mock.assert_called_once_with(
2208+
endpoint=test_endpoint.resource_name,
2209+
deployed_model=deployed_model,
2210+
traffic_split={"0": 100},
2211+
metadata=(),
2212+
timeout=None,
2213+
)
2214+
21742215
@pytest.mark.usefixtures(
21752216
"get_model_mock", "get_drp_mock", "create_endpoint_mock", "get_endpoint_mock"
21762217
)
@@ -2196,6 +2237,7 @@ def test_preview_deploy_with_deployment_resource_pool(
21962237
shared_resources=_TEST_DRP_NAME,
21972238
model=test_model.resource_name,
21982239
display_name=None,
2240+
enable_container_logging=True,
21992241
)
22002242
preview_deploy_model_mock.assert_called_once_with(
22012243
endpoint=test_endpoint.resource_name,

0 commit comments

Comments
 (0)