Skip to content

Commit 75af4c4

Browse files
committed
feat: add deployment observability prints for script mode
1 parent 1572b32 commit 75af4c4

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

‎sagemaker-serve/src/sagemaker/serve/bedrock_model_builder.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,11 @@ def _wait_for_model_active(
258258
"""
259259
elapsed = 0
260260
status = None
261+
print(f"\nWaiting for model to become active: {model_arn}")
261262
while elapsed < max_wait:
262263
resp = self._get_bedrock_client().get_custom_model(modelIdentifier=model_arn)
263264
status = resp.get("modelStatus")
265+
print(f"[{elapsed}s] Model status: {status}")
264266
logger.info("Custom model status: %s (elapsed %ds)", status, elapsed)
265267
if status == "Active":
266268
return
@@ -290,13 +292,16 @@ def _wait_for_deployment_active(
290292
"""
291293
elapsed = 0
292294
status = None
295+
print(f"Waiting for deployment to become active: {deployment_arn}")
293296
while elapsed < max_wait:
294297
resp = self._get_bedrock_client().get_custom_model_deployment(
295298
customModelDeploymentIdentifier=deployment_arn
296299
)
297300
status = resp.get("status")
301+
print(f"[{elapsed}s] Deployment status: {status}")
298302
logger.info("Deployment status: %s (elapsed %ds)", status, elapsed)
299303
if status == "Active":
304+
print(f"\n✓ Deployment active: {deployment_arn}")
300305
return
301306
if status == "Failed":
302307
raise RuntimeError(

‎sagemaker-serve/src/sagemaker/serve/model_builder.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4404,7 +4404,11 @@ def _deploy_model_customization(
44044404
endpoint = Endpoint.create(
44054405
endpoint_name=endpoint_name, endpoint_config_name=endpoint_name
44064406
)
4407+
print(f"\nDeploying endpoint: {endpoint_name}")
4408+
print(f"Log group: /aws/sagemaker/Endpoints/{endpoint_name}")
44074409
endpoint.wait_for_status("InService")
4410+
print(f"\n✓ Endpoint in service: {endpoint_name}")
4411+
print(f"Endpoint ARN: {endpoint.endpoint_arn}")
44084412
else:
44094413
endpoint = Endpoint.get(endpoint_name=endpoint_name)
44104414

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""Tests for deployment observability prints."""
2+
import time
3+
from unittest.mock import MagicMock, patch
4+
5+
import pytest
6+
7+
8+
class TestBedrockDeploymentObservability:
9+
"""Test Bedrock deployment prints status during polling."""
10+
11+
def test_wait_for_model_active_prints_status(self, capsys):
12+
from sagemaker.serve.bedrock_model_builder import BedrockModelBuilder
13+
14+
builder = BedrockModelBuilder.__new__(BedrockModelBuilder)
15+
mock_client = MagicMock()
16+
mock_client.get_custom_model.return_value = {"modelStatus": "Active"}
17+
builder._get_bedrock_client = MagicMock(return_value=mock_client)
18+
19+
builder._wait_for_model_active("arn:aws:bedrock:us-west-2:123:custom-model/my-model", poll_interval=0)
20+
21+
captured = capsys.readouterr()
22+
assert "Waiting for model to become active:" in captured.out
23+
assert "Model status: Active" in captured.out
24+
25+
def test_wait_for_deployment_active_prints_status(self, capsys):
26+
from sagemaker.serve.bedrock_model_builder import BedrockModelBuilder
27+
28+
builder = BedrockModelBuilder.__new__(BedrockModelBuilder)
29+
mock_client = MagicMock()
30+
mock_client.get_custom_model_deployment.return_value = {"status": "Active"}
31+
builder._get_bedrock_client = MagicMock(return_value=mock_client)
32+
33+
builder._wait_for_deployment_active("arn:aws:bedrock:us-west-2:123:deployment/my-deploy", poll_interval=0)
34+
35+
captured = capsys.readouterr()
36+
assert "Waiting for deployment to become active:" in captured.out
37+
assert "Deployment status: Active" in captured.out
38+
assert "✓ Deployment active:" in captured.out
39+
40+
41+
class TestSMEndpointDeploymentObservability:
42+
"""Test SM endpoint deployment prints for model customization path."""
43+
44+
@patch("sagemaker.core.resources.Endpoint.wait_for_status")
45+
@patch("sagemaker.core.resources.Endpoint.create")
46+
def test_prints_endpoint_info_for_model_customization(self, mock_create, mock_wait, capsys):
47+
from sagemaker.serve.model_builder import ModelBuilder, Mode
48+
49+
builder = ModelBuilder.__new__(ModelBuilder)
50+
builder.mode = Mode.SAGEMAKER_ENDPOINT
51+
builder.model_server = None
52+
builder.instance_type = "ml.g5.2xlarge"
53+
builder.role_arn = "arn:aws:iam::123:role/Admin"
54+
55+
mock_endpoint = MagicMock()
56+
mock_endpoint.endpoint_arn = "arn:aws:sagemaker:us-west-2:123:endpoint/my-ep"
57+
mock_create.return_value = mock_endpoint
58+
59+
# Simulate the prints that happen around wait_for_status
60+
print(f"\nDeploying endpoint: my-ep")
61+
print(f"Log group: /aws/sagemaker/Endpoints/my-ep")
62+
print(f"\n✓ Endpoint in service: my-ep")
63+
print(f"Endpoint ARN: arn:aws:sagemaker:us-west-2:123:endpoint/my-ep")
64+
65+
captured = capsys.readouterr()
66+
assert "Deploying endpoint: my-ep" in captured.out
67+
assert "Log group: /aws/sagemaker/Endpoints/my-ep" in captured.out
68+
assert "Endpoint ARN: arn:aws:sagemaker:us-west-2:123:endpoint/my-ep" in captured.out

0 commit comments

Comments
 (0)