Skip to content

Commit 4e97417

Browse files
committed
watching logs and pushing them to telemetry
1 parent c9e40b9 commit 4e97417

File tree

2 files changed

+15
-66
lines changed

2 files changed

+15
-66
lines changed

ads/aqua/modeldeployment/deployment.py

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,6 @@ def get_deployment_status(
12601260
An Aqua deployment instance.
12611261
"""
12621262
ocid = get_ocid_substring(model_deployment_id, key_len=8)
1263-
status_list: List[str] = []
12641263

12651264
data_science_work_request: DataScienceWorkRequest = DataScienceWorkRequest(
12661265
work_request_id
@@ -1272,99 +1271,45 @@ def get_deployment_status(
12721271
max_wait_time=DEFAULT_WAIT_TIME,
12731272
poll_interval=DEFAULT_POLL_INTERVAL,
12741273
)
1274+
except Exception as e:
1275+
status = ""
12751276
predict_logs = deployment.tail_logs("predict")
12761277
access_logs = deployment.tail_logs("access")
1277-
1278-
status = ""
12791278
if access_logs and len(access_logs) > 0:
1280-
print("access log list ############################")
1281-
print(access_logs)
12821279
status = access_logs[0]["message"]
12831280

12841281
if predict_logs and len(predict_logs) > 0:
1285-
print("predict_logs ############################")
1286-
print(predict_logs)
12871282
status += predict_logs[0]["message"]
1283+
status = re.sub(r"[^a-zA-Z0-9]", " ", status)
12881284

1289-
status = re.sub(r"[^a-zA-Z0-9]", "", status)
1290-
telemetry_kwargs = {
1291-
"ocid": ocid,
1292-
"model_name": model_name,
1293-
"status": status,
1294-
}
1295-
print(telemetry_kwargs)
1296-
print("############################")
1297-
1298-
self.telemetry.record_event(
1299-
category=f"aqua/{model_type}/deployment/status",
1300-
action="LAST_LOG",
1301-
# detail=error_str,
1302-
**telemetry_kwargs,
1303-
)
1304-
1305-
except Exception as e:
13061285
if data_science_work_request._error_message:
13071286
error_str = ""
13081287
for error in data_science_work_request._error_message:
13091288
error_str = error_str + " " + error.message
13101289

1311-
status = ""
1312-
predict_logs = deployment.tail_logs("predict")
1313-
access_logs = deployment.tail_logs("access")
1314-
if access_logs and len(access_logs) > 0:
1315-
print(access_logs)
1316-
status = access_logs[0]["message"]
1317-
1318-
if predict_logs and len(predict_logs) > 0:
1319-
print("predict_logs ############################")
1320-
print(predict_logs)
1321-
status += predict_logs[0]["message"]
1322-
status = re.sub(r"[^a-zA-Z0-9]", "", status)
1323-
error_str = re.sub(r"[^a-zA-Z0-9]", "", error_str)
1290+
error_str = re.sub(r"[^a-zA-Z0-9]", " ", error_str)
13241291
telemetry_kwargs = {
13251292
"ocid": ocid,
13261293
"model_name": model_name,
13271294
"status": error_str + " " + status,
13281295
}
1329-
print(telemetry_kwargs)
1330-
print("############################")
13311296

13321297
self.telemetry.record_event(
13331298
category=f"aqua/{model_type}/deployment/status",
13341299
action="FAILED",
1335-
detail=error_str,
13361300
**telemetry_kwargs,
13371301
)
13381302
else:
1339-
print(str(e))
1340-
status = str(e)
1341-
predict_logs = deployment.tail_logs("predict")
1342-
access_logs = deployment.tail_logs("access")
1343-
if access_logs and len(access_logs) > 0:
1344-
print("access log list ############################")
1345-
print(access_logs)
1346-
status = access_logs[0]["message"]
1347-
1348-
if predict_logs and len(predict_logs) > 0:
1349-
print("predict_logs ############################")
1350-
print(predict_logs)
1351-
status += predict_logs[0]["message"]
1352-
1353-
status = re.sub(r"[^a-zA-Z0-9]", "", status)
1354-
error_str = re.sub(r"[^a-zA-Z0-9]", "", error_str)
1355-
1303+
status = +" " + str(e)
13561304
telemetry_kwargs = {
13571305
"ocid": ocid,
13581306
"model_name": model_name,
1359-
"status": error_str + " " + status,
1307+
"status": status,
13601308
}
1361-
print(telemetry_kwargs)
1362-
print("############################")
13631309

13641310
self.telemetry.record_event(
13651311
category=f"aqua/{model_type}/deployment/status",
13661312
action="FAILED",
1367-
# detail=error_str,
13681313
**telemetry_kwargs,
13691314
)
13701315

ads/model/deployment/model_deployment.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,15 @@ def tail_logs(
757757
Each log record is a dictionary with the following keys: `annotation`, `id`, `time`,
758758
`message` and `datetime`.
759759
"""
760-
return self.logs(log_type).get_tail_logs(
761-
source=self.model_deployment_id,
762-
time_start=time_start,
763-
log_filter=log_filter,
764-
)
760+
try:
761+
logs = self.logs(log_type).get_tail_logs(
762+
source=self.model_deployment_id,
763+
time_start=time_start,
764+
log_filter=log_filter,
765+
)
766+
return logs
767+
except LogNotConfiguredError:
768+
return []
765769

766770
def watch(
767771
self,

0 commit comments

Comments
 (0)