Skip to content

Commit 9140431

Browse files
authored
Fix resource processor porter install logs truncation (#4048)
1 parent 216003e commit 9140431

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
FEATURES:
77

88
ENHANCEMENTS:
9+
* Split log entries with [Log chunk X of Y] for better readability. ([[#3992](https://github.com/microsoft/AzureTRE/issues/3992)
910
* Expose APP_SERVICE_SKU build variable to allow enablement of App Gateway WAF ([#4111](https://github.com/microsoft/AzureTRE/pull/4111))
1011
* Update Terraform to use Azure AD authentication rather than storage account keys ([#4103](https://github.com/microsoft/AzureTRE/issues/4103))
1112

resource_processor/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.9.2"
1+
__version__ = "0.9.3"

resource_processor/shared/logging.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ def initialize_logging() -> logging.Logger:
9595
return logger
9696

9797

98+
def chunk_log_output(output: str, chunk_size: int = 30000):
99+
"""
100+
Split the log output into smaller chunks and prefix each chunk with [Log chunk X of Y].
101+
"""
102+
total_chunks = (len(output) + chunk_size - 1) // chunk_size # Calculate total number of chunks
103+
for i in range(0, len(output), chunk_size):
104+
current_chunk = i // chunk_size + 1
105+
prefix = f"[Log chunk {current_chunk} of {total_chunks}] "
106+
yield prefix + output[i:i + chunk_size]
107+
108+
98109
def shell_output_logger(console_output: str, prefix_item: str, logging_level: int):
99110
if not console_output:
100111
logger.debug("shell console output is empty.")
@@ -118,4 +129,5 @@ def shell_output_logger(console_output: str, prefix_item: str, logging_level: in
118129
console_output = console_output.strip()
119130

120131
if console_output:
121-
logger.log(logging_level, f"{prefix_item} {console_output}")
132+
for chunk in chunk_log_output(console_output):
133+
logger.log(logging_level, f"{prefix_item} {chunk}")

resource_processor/tests_rp/test_logging.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from mock import patch
22
import logging
3-
from shared.logging import shell_output_logger
3+
from shared.logging import shell_output_logger, chunk_log_output
44

55

66
@patch("shared.logging.logger")
@@ -29,3 +29,20 @@ def test_shell_output_logger_normal_case(mock_logger):
2929
console_output = "Some logs"
3030
shell_output_logger(console_output, "prefix", logging.DEBUG)
3131
mock_logger.log.assert_called_with(logging.DEBUG, "prefix Some logs")
32+
33+
34+
@patch("shared.logging.logger")
35+
def test_shell_output_logger_chunked_logging(mock_logger):
36+
console_output = "A" * 60000 # 60,000 characters long
37+
shell_output_logger(console_output, "prefix", logging.DEBUG)
38+
assert mock_logger.log.call_count == 2
39+
mock_logger.log.assert_any_call(logging.DEBUG, f"prefix [Log chunk 1 of 2] {'A' * 30000}")
40+
mock_logger.log.assert_any_call(logging.DEBUG, f"prefix [Log chunk 2 of 2] {'A' * 30000}")
41+
42+
43+
def test_chunk_log_output():
44+
output = "A" * 60000 # 60,000 characters long
45+
chunks = list(chunk_log_output(output, chunk_size=30000))
46+
assert len(chunks) == 2
47+
assert chunks[0] == "[Log chunk 1 of 2] " + "A" * 30000
48+
assert chunks[1] == "[Log chunk 2 of 2] " + "A" * 30000

0 commit comments

Comments
 (0)