|
10 | 10 | import re |
11 | 11 |
|
12 | 12 | import boto3 |
13 | | -from sagemaker.telemetry.constants import Feature, Status, Region |
14 | | -from sagemaker.telemetry.telemetry_logging import ( |
15 | | - FEATURE_TO_CODE, |
16 | | - STATUS_TO_CODE, |
17 | | - _requests_helper, |
18 | | - _construct_url, |
19 | | -) |
| 13 | +from sagemaker.hyperpod.common.telemetry.constants import Feature, Status, Region |
20 | 14 | import importlib.metadata |
21 | 15 |
|
22 | 16 | SDK_VERSION = importlib.metadata.version("sagemaker-hyperpod") |
|
28 | 22 | sys.version_info.major, sys.version_info.minor, sys.version_info.micro |
29 | 23 | ) |
30 | 24 |
|
| 25 | +FEATURE_TO_CODE = { |
| 26 | + str(Feature.SDK_DEFAULTS): 1, |
| 27 | + str(Feature.LOCAL_MODE): 2, |
| 28 | + str(Feature.REMOTE_FUNCTION): 3, |
| 29 | + str(Feature.MODEL_TRAINER): 4, |
| 30 | + str(Feature.ESTIMATOR): 5, |
| 31 | + str(Feature.HYPERPOD): 6, # Added to support telemetry in sagemaker-hyperpod-cli |
| 32 | +} |
| 33 | + |
| 34 | +STATUS_TO_CODE = { |
| 35 | + str(Status.SUCCESS): 1, |
| 36 | + str(Status.FAILURE): 0, |
| 37 | +} |
| 38 | + |
31 | 39 | logger = logging.getLogger(__name__) |
32 | 40 |
|
33 | 41 |
|
@@ -65,6 +73,43 @@ def get_region_and_account_from_current_context() -> Tuple[str, str]: |
65 | 73 | return DEFAULT_AWS_REGION, "unknown" |
66 | 74 |
|
67 | 75 |
|
| 76 | +def _requests_helper(url, timeout): |
| 77 | + """Make a GET request to the given URL""" |
| 78 | + |
| 79 | + response = None |
| 80 | + try: |
| 81 | + response = requests.get(url, timeout) |
| 82 | + except requests.exceptions.RequestException as e: |
| 83 | + logger.exception("Request exception: %s", str(e)) |
| 84 | + return response |
| 85 | + |
| 86 | + |
| 87 | +def _construct_url( |
| 88 | + accountId: str, |
| 89 | + region: str, |
| 90 | + status: str, |
| 91 | + feature: str, |
| 92 | + failure_reason: str, |
| 93 | + failure_type: str, |
| 94 | + extra_info: str, |
| 95 | +) -> str: |
| 96 | + """Construct the URL for the telemetry request""" |
| 97 | + |
| 98 | + base_url = ( |
| 99 | + f"https://sm-pysdk-t-{region}.s3.{region}.amazonaws.com/telemetry?" |
| 100 | + f"x-accountId={accountId}" |
| 101 | + f"&x-status={status}" |
| 102 | + f"&x-feature={feature}" |
| 103 | + ) |
| 104 | + logger.debug("Failure reason: %s", failure_reason) |
| 105 | + if failure_reason: |
| 106 | + base_url += f"&x-failureReason={failure_reason}" |
| 107 | + base_url += f"&x-failureType={failure_type}" |
| 108 | + if extra_info: |
| 109 | + base_url += f"&x-extra={extra_info}" |
| 110 | + return base_url |
| 111 | + |
| 112 | + |
68 | 113 | def _send_telemetry_request( |
69 | 114 | status: int, |
70 | 115 | feature_list: List[int], |
|
0 commit comments