Skip to content

Commit 1036a7e

Browse files
committed
fix google batch logs
1 parent 2dbfec1 commit 1036a7e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

torchx/schedulers/gcp_batch_scheduler.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,10 @@ def log_iter(
412412
raise ValueError(f"app not found: {app_id}")
413413

414414
job_uid = job.uid
415-
filters = [f"labels.job_uid={job_uid}"]
416-
filters.append(f"resource.labels.task_id:task/{job_uid}-group0-{k}")
415+
filters = [
416+
f"labels.job_uid={job_uid}",
417+
f"labels.task_id:{job_uid}-group0-{k}",
418+
]
417419

418420
if since is not None:
419421
filters.append(f'timestamp>="{str(since.isoformat())}"')
@@ -434,7 +436,7 @@ def _batch_log_iter(self, filter: str) -> Iterable[str]:
434436

435437
logger = logging.Client().logger(BATCH_LOGGER_NAME)
436438
for entry in logger.list_entries(filter_=filter):
437-
yield entry.payload
439+
yield entry.payload + "\n"
438440

439441
def _job_full_name_to_app_id(self, job_full_name: str) -> str:
440442
"""

torchx/schedulers/test/gcp_batch_scheduler_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def test_batch_log_iter(self, mock_log_client: MagicMock) -> None:
245245
filter = "labels.job_uid=j-82c8495f-8cc9-443c-9e33-4904fcb1test"
246246
lines = scheduler._batch_log_iter(filter=filter)
247247
for l in lines:
248-
self.assertEqual(l, "log line")
248+
self.assertEqual(l, "log line\n")
249249
mock_log_client.assert_called()
250250
mock_logging_client.logger.assert_called_once_with("batch_task_logs")
251251
mock_logger.list_entries.assert_called_once_with(filter_=filter)
@@ -433,7 +433,7 @@ def test_log_iter_calls(self) -> None:
433433
)
434434
scheduler._batch_log_iter.assert_called_once_with(
435435
f'labels.job_uid=j-82c8495f-8cc9-443c-9e33-4904fcb1test \
436-
AND resource.labels.task_id:task/j-82c8495f-8cc9-443c-9e33-4904fcb1test-group0-1 \
436+
AND labels.task_id:j-82c8495f-8cc9-443c-9e33-4904fcb1test-group0-1 \
437437
AND timestamp>="{str(datetime.fromtimestamp(0).isoformat())}" \
438438
AND textPayload =~ "foo.*"'
439439
)
@@ -444,7 +444,7 @@ def test_log_iter_values(self) -> None:
444444
logs = scheduler.log_iter(app_id)
445445
scheduler._batch_log_iter.assert_called_once_with(
446446
f'labels.job_uid=j-82c8495f-8cc9-443c-9e33-4904fcb1test \
447-
AND resource.labels.task_id:task/j-82c8495f-8cc9-443c-9e33-4904fcb1test-group0-0 \
447+
AND labels.task_id:j-82c8495f-8cc9-443c-9e33-4904fcb1test-group0-0 \
448448
AND timestamp>="{str(datetime.fromtimestamp(0).isoformat())}"'
449449
)
450450
self.assertEqual(

0 commit comments

Comments
 (0)