-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Telemetry metrics #4414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Telemetry metrics #4414
Changes from 2 commits
bdd6c63
641bb9d
6c43300
a616b6f
0fd6487
5a1992b
7d543a2
ab06892
4184df7
e161509
834a5a2
6a5504b
30169b3
0c7d876
1566935
44e08d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,11 @@ | |
import logging | ||
import requests | ||
|
||
from sagemaker import Session | ||
from sagemaker import Session, exceptions | ||
from sagemaker.serve.mode.function_pointers import Mode | ||
from sagemaker.serve.utils.exceptions import ModelBuilderException | ||
from sagemaker.serve.utils.types import ModelServer | ||
from sagemaker.utils import pysdk_version | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -63,11 +64,15 @@ def wrapper(self, *args, **kwargs): | |
f"{func_name}" | ||
f"&x-modelServer={MODEL_SERVER_TO_CODE[str(self.model_server)]}" | ||
f"&x-imageTag={image_uri_tail}" | ||
f"&x-pySdkVersion={pysdk_version()}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create the constant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will use the one from here sagemaker-python-sdk/src/sagemaker/user_agent.py |
||
) | ||
|
||
if self.model_server == ModelServer.DJL_SERVING or self.model_server == ModelServer.TGI: | ||
extra += f"&x-modelName={self.model}" | ||
|
||
if self.sagemaker_session.endpoint_arn: | ||
extra += f"&x-endpointArn={self.sagemaker_session.endpoint_arn}" | ||
|
||
try: | ||
response = func(self, *args, **kwargs) | ||
if not self.serve_settings.telemetry_opt_out: | ||
|
@@ -79,7 +84,11 @@ def wrapper(self, *args, **kwargs): | |
None, | ||
extra, | ||
) | ||
except ModelBuilderException as e: | ||
except ( | ||
makungaj1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ModelBuilderException, | ||
exceptions.CapacityError, | ||
makungaj1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exceptions.UnexpectedStatusException, | ||
) as e: | ||
if not self.serve_settings.telemetry_opt_out: | ||
_send_telemetry( | ||
"0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1489,3 +1489,10 @@ def format_tags(tags: Tags) -> List[TagsDict]: | |
return [{"Key": str(k), "Value": str(v)} for k, v in tags.items()] | ||
|
||
return tags | ||
|
||
|
||
def pysdk_version() -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this too as suggested above |
||
"""Returns the current Sagemaker Python SDK Version""" | ||
v_path = os.path.join(os.path.dirname(__file__), "image_uri_config", "pysdk_version.json") | ||
with open(v_path) as v: | ||
return json.load(v).get("version") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3192,7 +3192,9 @@ def test_create_model_from_job_with_vpc_config_override(sagemaker_session): | |
|
||
def test_endpoint_from_production_variants(sagemaker_session): | ||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Could we use a full ARN like |
||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.p2.xlarge"), | ||
sagemaker.production_variant("B", "p299.4096xlarge"), | ||
|
@@ -3487,7 +3489,7 @@ def test_endpoint_from_production_variants_with_sagemaker_config_injection( | |
sagemaker_session.sagemaker_config = SAGEMAKER_CONFIG_ENDPOINT_CONFIG | ||
|
||
sagemaker_session.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService"} | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.p2.xlarge"), | ||
|
@@ -3555,7 +3557,7 @@ def test_endpoint_from_production_variants_with_sagemaker_config_injection_parti | |
sagemaker_session.sagemaker_config = SAGEMAKER_CONFIG_ENDPOINT_CONFIG | ||
|
||
sagemaker_session.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService"} | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.g5.xlarge"), | ||
|
@@ -3619,7 +3621,7 @@ def test_endpoint_from_production_variants_with_sagemaker_config_injection_no_km | |
sagemaker_session.sagemaker_config = SAGEMAKER_CONFIG_ENDPOINT_CONFIG | ||
|
||
sagemaker_session.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService"} | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.g5.xlarge"), | ||
|
@@ -3726,7 +3728,9 @@ def test_create_endpoint_config_with_explainer_config(sagemaker_session): | |
|
||
def test_endpoint_from_production_variants_with_tags(sagemaker_session): | ||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.p2.xlarge"), | ||
sagemaker.production_variant("B", "p299.4096xlarge"), | ||
|
@@ -3757,7 +3761,9 @@ def test_endpoint_from_production_variants_with_combined_sagemaker_config_inject | |
sagemaker_session.sagemaker_config = SAGEMAKER_CONFIG_ENDPOINT_ENDPOINT_CONFIG_COMBINED | ||
|
||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.p2.xlarge"), | ||
sagemaker.production_variant("B", "p299.4096xlarge"), | ||
|
@@ -3801,7 +3807,9 @@ def test_endpoint_from_production_variants_with_sagemaker_config_injection_tags( | |
sagemaker_session.sagemaker_config = SAGEMAKER_CONFIG_ENDPOINT | ||
|
||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.p2.xlarge"), | ||
sagemaker.production_variant("B", "p299.4096xlarge"), | ||
|
@@ -3830,7 +3838,9 @@ def test_endpoint_from_production_variants_with_sagemaker_config_injection_tags( | |
|
||
def test_endpoint_from_production_variants_with_accelerator_type(sagemaker_session): | ||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.p2.xlarge", accelerator_type=ACCELERATOR_TYPE), | ||
sagemaker.production_variant("B", "p299.4096xlarge", accelerator_type=ACCELERATOR_TYPE), | ||
|
@@ -3861,7 +3871,9 @@ def test_endpoint_from_production_variants_with_accelerator_type_sagemaker_confi | |
sagemaker_session.sagemaker_config = SAGEMAKER_CONFIG_ENDPOINT | ||
|
||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.p2.xlarge", accelerator_type=ACCELERATOR_TYPE), | ||
sagemaker.production_variant("B", "p299.4096xlarge", accelerator_type=ACCELERATOR_TYPE), | ||
|
@@ -3892,7 +3904,9 @@ def test_endpoint_from_production_variants_with_serverless_inference_config( | |
sagemaker_session, | ||
): | ||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant( | ||
"A", "ml.p2.xlarge", serverless_inference_config=SERVERLESS_INFERENCE_CONFIG | ||
|
@@ -3929,7 +3943,9 @@ def test_endpoint_from_production_variants_with_serverless_inference_config_sage | |
sagemaker_session.sagemaker_config = SAGEMAKER_CONFIG_ENDPOINT | ||
|
||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant( | ||
"A", "ml.p2.xlarge", serverless_inference_config=SERVERLESS_INFERENCE_CONFIG | ||
|
@@ -3964,7 +3980,9 @@ def test_endpoint_from_production_variants_with_serverless_inference_config_sage | |
|
||
def test_endpoint_from_production_variants_with_async_config(sagemaker_session): | ||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.p2.xlarge"), | ||
sagemaker.production_variant("B", "p299.4096xlarge"), | ||
|
@@ -4000,7 +4018,9 @@ def test_endpoint_from_production_variants_with_async_config_sagemaker_config_in | |
sagemaker_session.sagemaker_config = SAGEMAKER_CONFIG_ENDPOINT | ||
|
||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.p2.xlarge"), | ||
sagemaker.production_variant("B", "p299.4096xlarge"), | ||
|
@@ -4037,7 +4057,9 @@ def test_endpoint_from_production_variants_with_clarify_explainer_config( | |
sagemaker_session, | ||
): | ||
ims = sagemaker_session | ||
ims.sagemaker_client.describe_endpoint = Mock(return_value={"EndpointStatus": "InService"}) | ||
ims.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
pvs = [ | ||
sagemaker.production_variant("A", "ml.p2.xlarge"), | ||
sagemaker.production_variant("B", "p299.4096xlarge"), | ||
|
@@ -4069,7 +4091,7 @@ def test_endpoint_from_production_variants_with_clarify_explainer_config( | |
|
||
def test_update_endpoint_succeed(sagemaker_session): | ||
sagemaker_session.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "InService"} | ||
return_value={"EndpointStatus": "InService", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
endpoint_name = "some-endpoint" | ||
endpoint_config = "some-endpoint-config" | ||
|
@@ -4079,7 +4101,7 @@ def test_update_endpoint_succeed(sagemaker_session): | |
|
||
def test_update_endpoint_no_wait(sagemaker_session): | ||
sagemaker_session.sagemaker_client.describe_endpoint = Mock( | ||
return_value={"EndpointStatus": "Updating"} | ||
return_value={"EndpointStatus": "Updating", "EndpointArn": "arn:aws:sagemaker:"} | ||
) | ||
endpoint_name = "some-endpoint" | ||
endpoint_config = "some-endpoint-config" | ||
|
@@ -6136,7 +6158,10 @@ def test_upload_data_default_bucket_and_prefix_combinations( | |
|
||
def test_is_inference_component_based_endpoint_affirmative(sagemaker_session): | ||
|
||
describe_endpoint_response = {"EndpointConfigName": "some-endpoint-config"} | ||
describe_endpoint_response = { | ||
"EndpointConfigName": "some-endpoint-config", | ||
"EndpointArn": "arn:aws:sagemaker:", | ||
} | ||
describe_endpoint_config_response = { | ||
"ExecutionRoleArn": "some-role-arn", | ||
"ProductionVariants": [{"VariantName": "AllTraffic"}], | ||
|
@@ -6160,7 +6185,10 @@ def test_is_inference_component_based_endpoint_affirmative(sagemaker_session): | |
|
||
def test_is_inference_component_based_endpoint_negative_no_role(sagemaker_session): | ||
|
||
describe_endpoint_response = {"EndpointConfigName": "some-endpoint-config"} | ||
describe_endpoint_response = { | ||
"EndpointConfigName": "some-endpoint-config", | ||
"EndpointArn": "arn:aws:sagemaker:", | ||
} | ||
describe_endpoint_config_response = { | ||
"ProductionVariants": [{"VariantName": "AllTraffic"}], | ||
} | ||
|
@@ -6183,7 +6211,10 @@ def test_is_inference_component_based_endpoint_negative_no_role(sagemaker_sessio | |
|
||
def test_is_inference_component_based_endpoint_positive_multiple_variants(sagemaker_session): | ||
|
||
describe_endpoint_response = {"EndpointConfigName": "some-endpoint-config"} | ||
describe_endpoint_response = { | ||
"EndpointConfigName": "some-endpoint-config", | ||
"EndpointArn": "arn:aws:sagemaker:", | ||
} | ||
describe_endpoint_config_response = { | ||
"ExecutionRoleArn": "some-role-arn", | ||
"ProductionVariants": [{"VariantName": "AllTraffic1"}, {"VariantName": "AllTraffic2"}], | ||
|
@@ -6207,7 +6238,10 @@ def test_is_inference_component_based_endpoint_positive_multiple_variants(sagema | |
|
||
def test_is_inference_component_based_endpoint_negative_no_variants(sagemaker_session): | ||
|
||
describe_endpoint_response = {"EndpointConfigName": "some-endpoint-config"} | ||
describe_endpoint_response = { | ||
"EndpointConfigName": "some-endpoint-config", | ||
"EndpointArn": "arn:aws:sagemaker:", | ||
} | ||
describe_endpoint_config_response = { | ||
"ExecutionRoleArn": "some-role-arn", | ||
"ProductionVariants": [], | ||
|
@@ -6231,7 +6265,10 @@ def test_is_inference_component_based_endpoint_negative_no_variants(sagemaker_se | |
|
||
def test_is_inference_component_based_endpoint_negative_model_name_present(sagemaker_session): | ||
|
||
describe_endpoint_response = {"EndpointConfigName": "some-endpoint-config"} | ||
describe_endpoint_response = { | ||
"EndpointConfigName": "some-endpoint-config", | ||
"EndpointArn": "arn:aws:sagemaker:", | ||
} | ||
describe_endpoint_config_response = { | ||
"ExecutionRoleArn": "some-role-arn", | ||
"ProductionVariants": [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little strange to include in the setup.py. Is this the best way to get the PySDK version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still looking for a better way. Any suggestion here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gwang111 and @makungaj1 We don't need to create a function to just get SDK version. We can do something like -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tagging @mohanasudhan to check if he approves to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could try this:
sagemaker-python-sdk/src/sagemaker/user_agent.py
Line 21 in 87d661a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, why do we need a function to pull the version? What is the problem with above listed option?