Skip to content

Commit

Permalink
reportportal: add logfile size upload limit
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaarreell committed Sep 9, 2024
1 parent 7b16db6 commit 10aded9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tmt/steps/report/reportportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ def _filter_invalid_chars(data: str) -> str:
'',
data)

def _filter_log_per_size(data: str, limit: int) -> str:
size = len(log)
if size > limit:
return (f"Log file was not uploaded to ReportPortal because its size {size} bytes"
f"exceeds {self.data.log_size_limit} bytes.")
return log

@dataclasses.dataclass
class ReportReportPortalData(tmt.steps.report.ReportStepData):
Expand Down Expand Up @@ -142,6 +148,14 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
(e.g. 'Idle'). 'To Investigate' is used by default.
""")

log_size_limit: Optional[str] = field(
option="--log-size-limit",
metavar="LOG_SIZE_LIMIT",
default=_str_env_to_default('log_size_limit', '1048576'),
help="""
Size limit in bytes for log upload to ReportPortal. The default is 1048576 bytes (1 MB).
""")

exclude_variables: str = field(
option="--exclude-variables",
metavar="PATTERN",
Expand Down Expand Up @@ -590,15 +604,20 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
response = self.rp_api_post(
session=session,
path="log/entry",
json={"message": _filter_invalid_chars(log),
json={"message": _filter_invalid_chars(
_filter_log_per_size(log,
int(self.data.log_size_limit))),
"itemUuid": item_uuid,
"launchUuid": launch_uuid,
"level": level,
"time": result.end_time})

# Write out failures
failures = result.failures(log)
if index == 0 and status == "FAILED":
message = _filter_invalid_chars(result.failures(log))
message = _filter_invalid_chars(
_filter_log_per_size(result.failures(log),
int(self.data.log_size_limit)))
response = self.rp_api_post(
session=session,
path="log/entry",
Expand Down

0 comments on commit 10aded9

Please sign in to comment.