Skip to content

Commit 92974f2

Browse files
Add substring util (#806)
2 parents 2f3c48a + bc578ec commit 92974f2

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

ads/aqua/deployment.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
UNKNOWN_DICT,
2323
get_resource_name,
2424
get_model_by_reference_paths,
25+
get_ocid_substring,
2526
)
2627
from ads.aqua.finetune import FineTuneCustomMetadata
2728
from ads.aqua.data import AquaResourceIdentifier
@@ -393,9 +394,9 @@ def create(
393394

394395
model_type = "custom" if is_fine_tuned_model else "service"
395396
deployment_id = deployment.dsc_model_deployment.id
396-
telemetry_kwargs = (
397-
{"ocid": deployment_id[-8:]} if len(deployment_id) > 8 else {}
398-
)
397+
# we arbitrarily choose last 8 characters of OCID to identify MD in telemetry
398+
telemetry_kwargs = {"ocid": get_ocid_substring(deployment_id, key_len=8)}
399+
399400
# tracks unique deployments that were created in the user compartment
400401
self.telemetry.record_event_async(
401402
category=f"aqua/{model_type}/deployment",
@@ -461,10 +462,11 @@ def list(self, **kwargs) -> List["AquaDeployment"]:
461462
state = model_deployment.lifecycle_state.upper()
462463
if state in ["ACTIVE", "FAILED"]:
463464
# tracks unique deployments that were listed in the user compartment
465+
# we arbitrarily choose last 8 characters of OCID to identify MD in telemetry
464466
self.telemetry.record_event_async(
465467
category=f"aqua/deployment",
466468
action="list",
467-
detail=deployment_id[-8:] if len(deployment_id) > 8 else "",
469+
detail=get_ocid_substring(deployment_id, key_len=8),
468470
value=state,
469471
)
470472

ads/aqua/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,3 +741,9 @@ def known_realm():
741741
742742
"""
743743
return os.environ.get("CONDA_BUCKET_NS") in AQUA_GA_LIST
744+
745+
746+
def get_ocid_substring(ocid: str, key_len: int) -> str:
747+
"""This helper function returns the last n characters of the ocid specified by key_len parameter.
748+
If ocid is None or length is less than key_len, it returns an empty string."""
749+
return ocid[-key_len:] if ocid and len(ocid) > key_len else ""

0 commit comments

Comments
 (0)