This is an automated email from the ASF dual-hosted git repository.
Gabriel39 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 4be1be8a454 [chore](ci) Add a static build report for community
pipelines (#70949)
4be1be8a454 is described below
commit 4be1be8a454fe5af0612628e96814eeff48755aa
Author: shuke <[email protected]>
AuthorDate: Wed Nov 25 09:28:11 2026 +0800
[chore](ci) Add a static build report for community pipelines (#70949)
### Background
Contributors investigating a Doris CI failure use TeamCity for the
failed build step, case details, and diagnostic downloads. If TeamCity
becomes private, a public PR still needs a way to show those results.
### What problem does this PR solve?
Issue Number: None
Related PR: None
PR Type: Build/CI/Chore
Problem Summary:
Add a standalone Python command that turns a finished build into one
shareable HTML report. It preserves TeamCity's failure messages and case
counts and links the full build log, Doris log archive, and core when
supplied. A debugger backtrace lets contributors see the crash frames
and source lines before downloading the core.
### Details
- **Change map:** 623 lines implement the renderer and publisher. Input
validation and HTML rendering associate failures with the selected
build. Attachment handling preserves downloads and publishes the entry
page last. The other 382 lines contain tests. There are no generated
files or documentation changes.
- **Affected:** The shared Python tooling in
`regression-test/pipeline/common`. Local rendering uses the Python
standard library. An explicit `--upload` uses `ossutil` and the agent's
ECS role.
- **Developer and release impact:** Developers can preview a report
locally. Production pipeline adoption and changes to GitHub status links
are separate rollout steps.
- **License and third-party:** Both files use the ASF license header. No
new third-party dependency.
- **Rollback:** Revert the two added files.
### Testing
- Ran `python3 -m unittest discover -s scripts -p
test_render_ci_report.py` on macOS with Python 3.12.3 before placing the
two files in the Doris tree. All 23 tests passed. In the repository, use
`regression-test/pipeline/common` as the discovery directory. Coverage
includes build identity, HTML escaping, signed download origins, core
frames, attachment publication order, and conflicting uploads.
- Rendered two historical builds locally. The P0 report contained all 81
failure entries, including the muted entry. The Compile report retained
the failed step's original Java error.
### Release note
None
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Partially verified: local rendering and unit
tests passed. Upload from a real agent and anonymous retrieval of its
published report remain to be tested.
### AI Disclosure
- Tool: OpenAI Codex (GPT-6)
- Generated: Report renderer, unit tests, and PR description.
- Human review: The contributor specified the report fields, download
behavior, and staged rollout. Line-by-line human review has not been
confirmed.
---
.../pipeline/common/render_ci_report.py | 623 +++++++++++++++++++++
.../pipeline/common/test_render_ci_report.py | 382 +++++++++++++
2 files changed, 1005 insertions(+)
diff --git a/regression-test/pipeline/common/render_ci_report.py
b/regression-test/pipeline/common/render_ci_report.py
new file mode 100644
index 00000000000..8e3c84aab02
--- /dev/null
+++ b/regression-test/pipeline/common/render_ci_report.py
@@ -0,0 +1,623 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Render one terminal Doris CI result. Pass --upload on a publisher agent to
copy it to OSS."""
+import argparse
+import base64
+import gzip
+import hashlib
+import json
+import os
+import re
+import subprocess
+import tempfile
+import xml.etree.ElementTree as ET
+from collections import Counter, deque
+from datetime import datetime, timedelta, timezone
+from html import escape
+from pathlib import Path
+from urllib.parse import parse_qsl, urlsplit
+from urllib.request import urlopen
+
+PIPELINES = {
+ "compile": "Compile", "p0": "P0", "cloud_p0": "Cloud P0", "vault_p0":
"Vault P0",
+ "feut": "FE UT", "beut": "BE UT", "cloudut": "Cloud UT", "external":
"External",
+ "nonconcurrent": "NonConcurrent", "performance": "Performance",
+}
+RESULTS = {"success": "Passed", "failure": "Failed", "error": "Build error",
"canceled": "Canceled"}
+STEPS = {
+ "precheck": "Environment check", "checkout": "Checkout and merge",
"binary": "Binary compilation",
+ "cases": "Test case packaging", "setup": "Test setup", "tests": "Tests",
+ "benchmark": "Benchmarks", "upload": "Artifact upload", "cleanup":
"Cleanup",
+}
+TC_STAGE = re.compile(r"^\[[\d:]+\][ EiW]:\s*Step (\d+)/(\d+): (.*?) \(Command
Line\)(?: \(([0-9hms: ]+)\))?\s*$")
+BUCKET = "doris-pipelines"
+REGION = "cn-hongkong"
+ENDPOINT = f"oss-{REGION}-internal.aliyuncs.com"
+
+
+def count(value):
+ if not re.fullmatch(r"[0-9]{1,18}", value):
+ raise argparse.ArgumentTypeError("expected a non-negative integer of
up to 18 digits")
+ return int(value)
+
+
+def sha(value):
+ if not re.fullmatch(r"[a-f0-9]{40}", value):
+ raise argparse.ArgumentTypeError("expected a full lowercase Git SHA")
+ return value
+
+
+def target_branch(value):
+ if not re.fullmatch(r"master|branch-\d{1,2}\.\d{1,2}", value):
+ raise argparse.ArgumentTypeError("expected a public Doris target
branch")
+ return value
+
+
+def time_with_offset(value):
+ try:
+ parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
+ except ValueError:
+ parsed = None
+ if not parsed or parsed.utcoffset() is None:
+ raise argparse.ArgumentTypeError("expected an ISO timestamp with a UTC
offset")
+ return parsed.astimezone(timezone(timedelta(hours=8)))
+
+
+# Escape at the HTML boundary. Do not reinterpret failure text as HTML or
rewrite its diagnosis.
+KEY =
r"(?:[\w.-]*[._-])?(?:access[_-]?key(?:[_-]?id)?|api[_-]?key|secret(?:[_-]?access)?[_-]?key|accesskeysecret|client[_-]?secret|secret|passw(?:or)?d|pwd|(?:[a-z]+[_-]?)?token|signature|credential)"
+SECRET_VALUE = re.compile(
+ rf"""(?ix)(?P<prefix>(?<![\w])["']?{KEY}["']?\s*[:=]\s*)
+
(?:"(?P<double>(?:\\.|[^"\\])*)"|'(?P<single>(?:\\.|[^'\\])*)'|(?P<bare>\[redacted\]|[^\s,;&)\]}}]+))""")
+PEM = re.compile(r"-----BEGIN ([A-Z ]*PRIVATE KEY)-----.*?(?:-----END
\1-----|\Z)", re.S)
+TOKEN =
re.compile(r"\b(?:LTAI[A-Za-z0-9]{12,}|(?:AKIA|ASIA)[A-Z0-9]{16}|(?:gh[pousr]_|github_pat_)[A-Za-z0-9_]{12,}|eyJ[\w-]+\.eyJ[\w-]+\.[\w-]+)\b")
+SIGNED_URL =
re.compile(r"""(?i)https?://[^\s<>"']*[?&](?:x-(?:oss|amz)-(?:credential|signature)|signature|ossaccesskeyid)=[^\s<>"']*""")
+PRIVATE_IP =
re.compile(r"(?<![\w.])(?:(?:10|127)\.(?:\d{1,3}\.){2}|(?:192\.168|172\.(?:1[6-9]|2\d|3[01])|169\.254)\.\d{1,3}\.)\d{1,3}(?![\w.])")
+INTERNAL_HOST =
re.compile(r"(?i)(?<=://)(?:[a-z0-9-]+\.)+(?:internal|local|svc\.cluster\.local)(?=[:/\s]|$)|(?<=://)(?:[a-z0-9-]+\.)*oss-[a-z0-9-]+-internal\.aliyuncs\.com\b")
+
+
+def redact(value):
+ if not isinstance(value, str):
+ raise ValueError("Expected a text field")
+ value = PEM.sub("[redacted]", value)
+ value = SIGNED_URL.sub("[redacted URL]", value)
+ value =
re.sub(r"(?im)(\b(?:Authorization\s*[:=]\s*(?:(?:Bearer|Basic)\s+)?|Bearer\s+))[^\s,;\"']+",
+ r"\1[redacted]", value)
+ value = re.sub(r"(?im)^([ \t]*(?:Set-Cookie|Cookie)\s*:)[^\r\n]*", r"\1
[redacted]", value)
+ value = re.sub(r"(?i)(\b[\w+.-]+://)[^/\s@]+:[^/\s@]+@", r"\1[redacted]@",
value)
+ def mask(m):
+ delimiter = '"' if m["double"] is not None else "'" if m["single"] is
not None else ""
+ return m["prefix"] + delimiter + "[redacted]" + delimiter
+ value = SECRET_VALUE.sub(mask, value)
+ return PRIVATE_IP.sub("[private address]", INTERNAL_HOST.sub("[private
host]", TOKEN.sub("[redacted]", value)))
+
+
+def display(value):
+ return escape(redact(value))
+
+
+BUILD_TYPES = {
+ "compile": "Doris_Compile", "p0": "Doris_P0", "cloud_p0": "Doris_CloudP0",
"vault_p0": "Doris_VaultP0",
+ "feut": "Doris_FEUT", "beut": "Doris_BEUT", "cloudut": "Doris_CloudUT",
"external": "Doris_External",
+ "nonconcurrent": "Doris_NonConcurrent", "performance": "Doris_Performance",
+}
+TC_OUTPUT = re.compile(r"^\[[\d:]+\]([ EiW]):\s*\[Step (\d+)/\d+\] (.*)$")
+
+
+def read_teamcity(args):
+ if not args.teamcity:
+ return {}
+ build = json.loads(args.teamcity.read_text(encoding="utf-8"))
+ if (not isinstance(build, dict) or type(build.get("id")) is not int or
build["id"] != args.build_id
+ or build.get("buildTypeId") != args.build_type_id or
build.get("state") != "finished"):
+ raise ValueError("Expected a terminal TeamCity Build for this build ID
and pipeline")
+ status = "canceled" if build.get("canceledInfo") is not None else
str(build.get("status", "")).lower()
+ if status.replace("cancelled", "canceled") != args.status:
+ raise ValueError("TeamCity result does not match --status")
+ for field, singular in (("testOccurrences", "testOccurrence"),
("problemOccurrences", "problemOccurrence")):
+ collection = build.get(field, {})
+ records = collection.get(singular, [])
+ if (collection.get("nextHref") or collection.get("count",
len(records)) != len(records)):
+ raise ValueError(f"Supply all pages of {field} before rendering")
+ if any("build" in row and str(row["build"].get("id")) !=
str(args.build_id) for row in records):
+ raise ValueError(f"{field} contains a record from another build")
+ return build
+
+
+def log_lines(stream):
+ """Skip pathological lines whole so partial secret values never pass
through."""
+ while raw := stream.readline(65537):
+ if len(raw) > 65536:
+ while raw and not raw.endswith("\n"):
+ raw = stream.readline(65537)
+ yield "[oversized line omitted]\n"
+ else:
+ yield raw
+
+
+def log_sections(path):
+ """Show TeamCity's own step labels/errors and the last runtime lines of
failed steps."""
+ stages, errors, tails = {}, {}, {}
+ with path.open(encoding="utf-8-sig", errors="replace") as stream:
+ if not stream.readline(128).startswith("Build '"):
+ stream.seek(0)
+ excerpt = stream.read(262145)
+ if len(excerpt) > 262144:
+ excerpt = excerpt[:262144].rpartition("\n")[0] + "\n[excerpt
truncated]"
+ return stages, [("Failure log", excerpt)]
+ stream.seek(0)
+ for number, raw in enumerate(log_lines(stream), 1):
+ line = raw.rstrip("\r\n")
+ header = TC_STAGE.match(line)
+ if header:
+ step, _, label, duration = header.groups()
+ stages[step] = [label, "Not recorded", duration]
+ continue
+ match = TC_OUTPUT.match(line)
+ if not match or match[2] not in stages:
+ continue
+ level, step, message = match.groups()
+ if level == "i": # TeamCity can log the generated shell script as
an information block.
+ continue
+ tail = tails.setdefault(step, deque(maxlen=16))
+ tail.append((number, line))
+ if level == "E":
+ first_errors = errors.setdefault(step, {})
+ if len(first_errors) < 100:
+ first_errors[number] = line
+ exit_code = re.match(r"Process exited with code (-?\d+)\b",
message)
+ if exit_code:
+ stages[step][1] = "Passed" if exit_code[1] == "0" else "Failed"
+ elif re.match(r"Build step .+ is skipped\b", message):
+ stages[step][1] = "Skipped"
+ elif level == "E" and re.search(r"\bfailed\s*$", message):
+ stages[step][1] = "Failed"
+ excerpts = []
+ for step, (label, state, _) in stages.items():
+ if state == "Failed":
+ lines = dict(tails.get(step, ()))
+ lines.update(errors.get(step, {}))
+ if lines:
+ ordered = sorted(lines)
+ excerpts.append((f"{label} · build log
L{ordered[0]:,}–L{ordered[-1]:,}",
+ "\n".join(lines[n] for n in ordered)))
+ return stages, excerpts
+
+
+def junit_results(path, counts):
+ with path.open("rb") as stream:
+ raw = stream.read(16 * 1024 * 1024 + 1)
+ if len(raw) > 16 * 1024 * 1024 or b"<!DOCTYPE" in raw.upper() or b"\0" in
raw:
+ raise ValueError("Expected a UTF-8 JUnit file up to 16 MiB without a
DTD")
+ root = ET.fromstring(raw.decode("utf-8-sig"))
+ for node in root.iter():
+ node.tag = node.tag.rsplit("}", 1)[-1]
+ if root.tag not in ("testsuites", "testsuite"):
+ raise ValueError("Expected a JUnit testsuite or testsuites")
+ # Reconcile nested suite totals with visible cases. Some producers retain
+ # only failing rows or omit case details for a whole shard.
+ totals = {}
+ for suite in reversed(list(root.iter())):
+ if suite.tag not in ("testsuites", "testsuite"):
+ continue
+ result = Counter()
+ for child in suite:
+ if child in totals:
+ result.update(totals.pop(child))
+ elif child.tag == "testcase":
+ failed = child.find("failure") is not None or
child.find("error") is not None
+ state = "failed" if failed else ("ignored" if
child.find("skipped") is not None else "passed")
+ result[state] += 1
+ result["total"] += 1
+ if "tests" in suite.attrib:
+ total = count(suite.get("tests"))
+ failed = (count(suite.get("failures")) + count(suite.get("errors",
"0"))
+ if "failures" in suite.attrib else result["failed"])
+ skipped = count(suite.get("skipped", str(result["ignored"])))
+ if (total < result["total"] or failed < result["failed"] or
skipped < result["ignored"]
+ or total - failed - skipped < result["passed"]):
+ raise ValueError("Inconsistent JUnit counters")
+ remaining = total - failed - skipped - result["passed"]
+ # Without aggregate failure/skip counts, omitted cases have no
known outcome.
+ if "failures" in suite.attrib and ("skipped" in suite.attrib or
result["total"] == total):
+ result["passed"] += remaining
+ remaining = 0
+ result["total"], result["failed"], result["ignored"],
result["unknown"] = total, failed, skipped, remaining
+ totals[suite] = result
+ counts.update(totals[root])
+ for case in root.iter("testcase"):
+ failures = [child for child in case if child.tag in ("failure",
"error")]
+ if not failures:
+ continue
+ name = case.get("name", "")
+ fields = [value for failure in failures for value in
+ (failure.get("type"), failure.get("message"),
"".join(failure.itertext()))]
+ yield name, case.get("classname", ""), "\n".join(v for v in fields if
v is not None), False
+
+
+DOWNLOAD_NAMES = {"build": "Build log", "cluster": "Doris logs", "core":
"Coredump"}
+# A broker URL is a scoped grant for one artifact. Never accept an arbitrary
+# URL from a build, or copy the redirect destination's cloud credentials.
+BROKER_PATH = re.compile(r"/_ci/diagnostics/d/[0-9a-f]{32}")
+CORE_NAME =
re.compile(r"(?:core(?:[._-](?:\d+|doris[_-](?:be|fe)|be|gz|zst|lz4|tar|dump|pair)(?:[._-][\w.-]+)*)?|"
+
r"(?:[\w.-]+[._-])?coredump(?:[._-][\w.-]+)?|[\w.-]+\.core(?:\.(?:gz|zst|lz4))?)",
re.I)
+CORE_EXCLUDE =
re.compile(r"(?:binary|executable|symbols?|backtrace|stacktrace|\.profraw|\.json|\.txt|\.log|\.sha256)",
re.I)
+FRAME = re.compile(r"^\s*(?:#\s*\d+\s|(?:\*\s*)?frame #\d+:|Program terminated
with signal\b|"
+ r"Thread \d+ .* received signal\b|\[Current thread is |\*
thread #\d+)")
+# Static OSS pages must continue to reflect expiry without changing their
bytes on a publisher retry.
+EXPIRY_JS = """function expireLinks() {
+ for (const link of document.querySelectorAll('a[data-expires]')) {
+ if (Number(link.dataset.expires) <= Date.now() / 1000) {
+ link.replaceWith(document.createTextNode(link.textContent + '
(expired)'));
+ }
+ }
+}
+expireLinks();
+window.addEventListener('pageshow', expireLinks);
+document.addEventListener('click', event => {
+ const link = event.target.closest('a[data-expires]');
+ if (link && Number(link.dataset.expires) <= Date.now() / 1000) {
+ event.preventDefault();
+ expireLinks();
+ }
+}, true);"""
+EXPIRY_HASH =
base64.b64encode(hashlib.sha256(EXPIRY_JS.encode()).digest()).decode()
+
+
+def is_core(name):
+ return not CORE_EXCLUDE.search(name) and CORE_NAME.fullmatch(name) is not
None
+
+
+def download_kinds(obj):
+ name, group = obj["name"], obj["group"]
+ if not isinstance(name, str) or not re.fullmatch(r"[\w.-]+", name):
+ return []
+ kinds = []
+ if group in ("build-log", "build") and
re.fullmatch(r"build[-.]log(?:\.safe-v1)?\.(?:gz|zip)", name):
+ kinds.append("build")
+ if group in ("cluster", "doris-logs", "ut") and name.endswith((".tar.gz",
".tgz", ".zip", ".tar.zst")):
+ kinds.append("cluster")
+ if ((group in ("core", "coredump", "core-file", "core-pair", "large-file")
and is_core(name))
+ or (obj.get("archive") is True and any(is_core(Path(src).name) for
src in obj.get("sources", [])
+ if isinstance(src, str)))):
+ kinds.append("core")
+ return kinds
+
+
+def broker_link(obj, origin):
+ if not origin:
+ raise ValueError("Set TEAMCITY_CURRENT_URL to the trusted HTTPS origin
for diagnostic links")
+ url, expires = obj.get("url"), obj.get("expires")
+ if not isinstance(url, str) or not url.isascii() or re.search(r"[\s\\#]",
url):
+ raise ValueError("Invalid diagnostics download URL")
+ parsed = urlsplit(url)
+ if parsed.scheme != "https" or parsed.netloc != urlsplit(origin).netloc or
not BROKER_PATH.fullmatch(parsed.path):
+ raise ValueError("Unexpected diagnostics download host or path")
+ params = dict(parse_qsl(parsed.query, strict_parsing=True))
+ if (type(expires) is not int or not 0 < expires < 2**34 or
parsed.query.count("&") != 1 or
+ set(params) != {"expires", "signature"} or params["expires"] !=
str(expires) or
+ not re.fullmatch(r"[0-9a-fA-F]{64}", params["signature"])):
+ raise ValueError("Invalid or inconsistent diagnostics download grant")
+ return url, expires
+
+
+def stack_preview(text):
+ if "\x00" in text or text.startswith("\x7fELF"):
+ raise ValueError("Supply a text backtrace instead of a binary core")
+ frames = []
+ for line in text.splitlines():
+ if FRAME.match(line):
+ frames.append(line[:2048])
+ if len(frames) == 80:
+ break
+ return "\n".join(frames)
+
+
+def download_section(args, build):
+ links = {kind: [] for kind in DOWNLOAD_NAMES}
+ expected = args.build_type_id
+ core_state = "No core archive supplied"
+ if args.artifact_index:
+ index = json.loads(args.artifact_index.read_text(encoding="utf-8"))
+ if str(index.get("buildId")) != str(args.build_id) or
index.get("pipeline") != expected:
+ raise ValueError("Artifact receipt must match this build ID and
configuration")
+ if index.get("state") == "EXPORTED":
+ core_state = "No core archive listed"
+ for obj in index["objects"]:
+ kinds = download_kinds(obj)
+ if kinds:
+ url, expires = broker_link(obj, args.teamcity_origin)
+ for kind in kinds:
+ links[kind].append((obj["name"], url, expires))
+ for kind, filename in args.local_downloads.items():
+ links[kind] = [(f"Download {DOWNLOAD_NAMES[kind].lower()}", filename,
None)]
+ if build and args.teamcity_origin and not links["build"]:
+ links["build"].append(("Download from TeamCity (requires access)",
+
f"{args.teamcity_origin}/downloadBuildLog.html?buildId={args.build_id}&archived=true",
None))
+ stacks = []
+ if args.core_diagnostics:
+ receipt = json.loads(args.core_diagnostics.read_text(encoding="utf-8"))
+ if (str(receipt.get("build", receipt.get("buildId"))) !=
str(args.build_id)
+ or receipt.get("pipeline", expected) != expected):
+ raise ValueError("Core diagnostics must match this build ID and
configuration")
+ pairs = receipt.get("core_pairs", receipt.get("pairs"))
+ if isinstance(pairs, list):
+ if not receipt.get("errors"):
+ core_state = "Core recorded, no downloadable archive listed"
if pairs else "No core recorded"
+ else:
+ core_state = "Core collection reported errors"
+ for pair in pairs:
+ trace = pair.get("backtrace") if isinstance(pair, dict) else
None
+ if isinstance(trace, str) and (stack :=
stack_preview(trace[:1048576])):
+ stacks.append(stack)
+ if args.core_backtrace:
+ with args.core_backtrace.open("rb") as stream:
+ stack = stack_preview(stream.read(1048576).decode("utf-8-sig",
errors="replace"))
+ if stack and stack not in stacks:
+ stacks.append(stack)
+ if stack and core_state == "No core recorded" and not links["core"]:
+ core_state = "Backtrace supplied, no downloadable archive listed"
+ items = []
+ for kind, name in DOWNLOAD_NAMES.items():
+ anchors = []
+ for label, url, expires in links[kind]:
+ expiration, attr = "", ""
+ if expires:
+ dt = datetime.fromtimestamp(expires, timezone.utc)
+ expiration = f' <small>Valid until {dt:%Y-%m-%d %H:%M
UTC}</small>'
+ attr = f' data-expires="{expires}"'
+ anchors.append(f'<a{attr} href="{escape(url, quote=True)}"
rel="noreferrer">{escape(label)}</a>{expiration}')
+ unavailable = core_state if kind == "core" else "No archive supplied"
+ items.append(f'<div><dt>{name}</dt><dd>{"<br>".join(anchors) or
unavailable}</dd></div>')
+ section = '<h2>Downloads</h2><dl>' + "".join(items) + '</dl>'
+ if stacks:
+ section += '<h2>Core backtrace</h2>' +
"".join(f'<pre><code>{display(stack)}</code></pre>' for stack in stacks)
+ elif links["core"] or args.core_backtrace or core_state.startswith("Core
recorded"):
+ section += '<p>No debugger backtrace available for this build.</p>'
+ if any(expires for entries in links.values() for _, _, expires in entries):
+ section += f'<script type="text/javascript">{EXPIRY_JS}</script>'
+ return section
+
+
+def report(args):
+ build = read_teamcity(args)
+ tests = build.get("testOccurrences", {})
+ counters = tests.get("testCounters", {})
+ cases = []
+ for row in tests.get("testOccurrence", []):
+ if row.get("status") in ("FAILURE", "ERROR"):
+ cases.append((row["name"], "", row.get("details", ""),
row.get("muted", False)))
+ junit = Counter()
+ for path in args.junit:
+ cases.extend(junit_results(path, junit))
+ stages, excerpts = log_sections(args.failure_log) if args.failure_log else
({}, [])
+ problems = build.get("problemOccurrences", {}).get("problemOccurrence", [])
+ title, result = PIPELINES[args.pipeline], RESULTS[args.status]
+ def facts(items):
+ return "".join(f"<div><dt>{key}</dt><dd>{display(str(v))}</dd></div>"
for key,v in items if v is not None)
+ rows = []
+ for label, key, override in (("Total", "all", None), ("Passed", "success",
args.passed),
+ ("Failed", "failed", args.failed), ("Muted",
"muted", None),
+ ("Ignored", "ignored", args.ignored)):
+ value = counters.get(key, override)
+ if value is not None and (type(value) is not int or value < 0 or
override not in (None, value)):
+ raise ValueError(f"Invalid or conflicting {key} counter")
+ rows.append((label, value))
+ if args.unmuted_failed is not None:
+ rows.append(("Unmuted failures", args.unmuted_failed))
+ sections = [download_section(args, build)]
+ if any(v is not None for _,v in rows):
+ sections.append(f'<h2>Test results</h2><dl>{facts(rows)}</dl>')
+ elif args.pipeline != "compile" and not args.junit and not build:
+ sections.append('<h2>Test results</h2><p>Case counts were not recorded
in this snapshot.</p>')
+ if args.junit:
+ sections.append(f'<p>Supplied JUnit files: {junit["total"]} test
executions · {junit["failed"]} failed · '
+ f'{junit["passed"]} passed · {junit["ignored"]}
skipped'
+ + (f' · {junit["unknown"]} without recorded outcome'
if junit["unknown"] else '') + '.</p>')
+ if problems:
+ sections.append('<h2>Build problems</h2>')
+ for item in problems:
+ sections.append(f'<pre><code>{display(item.get("details",
""))}</code></pre>')
+ if cases:
+ sections.append('<h2>Failed tests</h2>')
+ if args.junit:
+ sections.append(f'<p>{len(cases)} of {junit["failed"]} failures in
supplied JUnit files have case details.</p>')
+ for idx,(name,classname,details,muted) in enumerate(cases):
+ badge = ' <small>Muted</small>' if muted else ''
+ scope = f'<p>{display(classname)}</p>' if classname else ''
+ sections.append(f'<details{" open" if idx == 0 else
""}><summary>{display(name)}{badge}</summary>'
+
f'{scope}<pre><code>{display(details)}</code></pre></details>')
+ elif (args.junit and junit["failed"]) or (not args.junit and
(counters.get("failed") or args.failed or args.unmuted_failed)):
+ sections.append('<p>The supplied results contain failure counts
without individual case details.</p>')
+ if stages:
+ rows_html = "".join(f'<tr><th
scope="row">{display(name)}</th><td>{state}</td><td>{elapsed or "—"}</td></tr>'
+ for name,state,elapsed in stages.values())
+ sections.append('<h2>Build
steps</h2><table><thead><tr><th>Step</th><th>Result</th><th>Duration</th></tr>'
+ f'</thead><tbody>{rows_html}</tbody></table>')
+ for label, text in excerpts:
+
sections.append(f'<h2>{display(label)}</h2><pre><code>{display(text)}</code></pre>')
+ def tc_time(field):
+ value = build.get(field)
+ return datetime.strptime(value,
"%Y%m%dT%H%M%S%z").astimezone(timezone(timedelta(hours=8))) if value else None
+ start, finish = args.started_at or tc_time("startDate"), args.finished_at
or tc_time("finishDate")
+ info = [("Build ID", f"#{args.build_id}"), ("Build number",
build.get("number")),
+ ("Target branch", args.target_branch), ("PR head SHA", args.sha),
("Tested SHA", args.tested_sha)]
+ if args.failed_step and not problems and not stages:
+ info.append(("Failed step", STEPS[args.failed_step]))
+ for key,value in (("Started (UTC+08:00)", start), ("Finished (UTC+08:00)",
finish)):
+ if value:
+ info.append((key,value.strftime("%Y-%m-%d %H:%M:%S")))
+ if start and finish:
+ seconds = int((finish - start).total_seconds())
+ if seconds < 0:
+ raise ValueError("Finish time precedes start time")
+ info.append(("Duration", f"{seconds // 60}m {seconds % 60:02d}s"))
+ pr = f'<div><dt>Pull request</dt><dd><a
href="https://github.com/apache/doris/pull/{args.pr}">#{args.pr}</a></dd></div>'
if args.pr else ""
+ sections.append(f'<h2>Build details</h2><dl>{facts(info)}{pr}</dl>')
+ status_text = f'<pre class="status">{display(build["statusText"])}</pre>'
if build.get("statusText") else ""
+ return f"""<!doctype html>
+<html lang="en"><head><meta charset="utf-8"><meta name="viewport"
content="width=device-width,initial-scale=1">
+<meta http-equiv="Content-Security-Policy" content="default-src 'none';
style-src 'unsafe-inline'; script-src 'sha256-{EXPIRY_HASH}'; base-uri 'none';
form-action 'none'">
+<title>{title} · {result} · #{args.build_id}</title><style>
+*{{box-sizing:border-box}}body{{margin:0;background:#f6f8f7;color:#162b32;font:1rem/1.5
system-ui,sans-serif}}
+main{{max-width:64rem;margin:auto;padding:clamp(1rem,4vw,3rem)}}h1{{margin:.3rem
0;font-size:2.6rem}}
+header{{border-bottom:1px solid
#bdcfca;padding-bottom:1rem}}h2{{font-size:1.15rem;margin:1.7rem 0 .5rem}}
+strong{{color:#913827}}strong.success{{color:#236044}}strong.canceled,small,dt{{color:#536962}}
+dl,table,details,pre{{background:#fff;border:1px solid
#d2dfdb;border-radius:.4rem}}
+dl{{display:grid;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));gap:1rem;padding:1rem}}
+dd{{margin:0;overflow-wrap:anywhere}}pre{{padding:.9rem;white-space:pre-wrap;overflow-wrap:anywhere;font:
.86rem/1.55 ui-monospace,monospace}}
+details{{padding:.6rem .9rem;margin:.4rem
0}}summary{{cursor:pointer;overflow-wrap:anywhere;white-space:pre-wrap}}details
pre,.status{{border:0;margin:.4rem 0 0}}
+table{{width:100%;border-collapse:collapse}}td,th{{text-align:left;padding:.5rem;border-bottom:1px
solid #d2dfdb}}a{{color:#165b64}}
+</style></head><body><main><header><div>Apache Doris · Community
CI</div><h1>{title}</h1>
+<strong class="{args.status}">{result}</strong> · Build
#{args.build_id}{status_text}</header>{"".join(sections)}</main></body></html>
+""".encode("utf-8")
+
+
+def prepare_public_log(source, folder):
+ output = folder / "build-log.gz"
+ private_key = False
+ with source.open(encoding="utf-8-sig") as src, output.open("wb") as dst:
+ with gzip.GzipFile(filename="", fileobj=dst, mode="wb", mtime=0) as
compressed:
+ while line := src.readline(65537):
+ if "\x00" in line or len(line) > 65536:
+ raise ValueError("--public-build-log expects UTF-8 text
with lines up to 64 Ki characters")
+ if re.search(r"-----BEGIN [A-Z ]*PRIVATE KEY-----", line):
+ private_key = True
+ compressed.write(b"[redacted]\n")
+ if private_key:
+ if re.search(r"-----END [A-Z ]*PRIVATE KEY-----", line):
+ private_key = False
+ continue
+ compressed.write(redact(line).encode("utf-8"))
+ digest = hashlib.sha256()
+ with output.open("rb") as stream:
+ for chunk in iter(lambda: stream.read(1048576), b""):
+ digest.update(chunk)
+ return output.rename(folder / f"build-log-{digest.hexdigest()}.txt.gz")
+
+
+def stage_diagnostic(kind, source, folder):
+ name, extension = ("coredump", ".core") if kind == "core" else
("doris-logs", ".tar.gz")
+ staged = folder / name
+ digest = hashlib.sha256()
+ with source.open("rb") as src, staged.open("wb") as dst:
+ header = src.read(20)
+ if kind == "core":
+ if (len(header) < 20 or header[:4] != b"\x7fELF" or header[4] not
in (1, 2) or
+ header[5] not in (1, 2) or int.from_bytes(header[16:18],
"little" if header[5] == 1 else "big") != 4):
+ raise ValueError("--public-core expects an ELF core file")
+ elif not header.startswith(b"\x1f\x8b\x08"):
+ raise ValueError("--public-doris-log expects a gzip-compressed log
archive")
+ src.seek(0)
+ for chunk in iter(lambda: src.read(1048576), b""):
+ digest.update(chunk)
+ dst.write(chunk)
+ return staged.rename(folder / f"{name}-{digest.hexdigest()}{extension}")
+
+
+def upload(file, key):
+ # Always use the agent role and the Hong Kong private endpoint.
+ attachment = file.suffix != ".html"
+ mime = {".gz": "application/gzip", ".core": "application/octet-stream",
".html": "text/html"}[file.suffix]
+ result = subprocess.run([
+ "ossutil", "api", "put-object", "--mode", "EcsRamRole", "--region",
REGION,
+ "--endpoint", f"https://{ENDPOINT}", "--bucket", BUCKET, "--key", key,
+ "--body", f"file://{file}", "--content-type", mime if attachment else
mime + "; charset=utf-8",
+ "--content-disposition", "attachment" if attachment else "inline",
"--forbid-overwrite",
+ ], capture_output=True, timeout=60)
+ if result.returncode:
+ if b"FileAlreadyExists" not in result.stderr + result.stdout:
+ raise ValueError("OSS upload failed; the same report can be
retried")
+ url = f"https://{BUCKET}.{ENDPOINT}/{key}"
+ with urlopen(url, timeout=15) as existing, file.open("rb") as staged:
+ if existing.geturl() != url or existing.status != 200 or
existing.headers.get_content_type() != mime:
+ raise ValueError("Unexpected object at the existing OSS key")
+ while chunk := staged.read(1048576):
+ if existing.read(len(chunk)) != chunk:
+ raise ValueError("The OSS key already contains different
content")
+ if existing.read(1):
+ raise ValueError("The OSS key already contains different
content")
+ print(f"oss://{BUCKET}/{key}")
+
+
+def main(argv=None):
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("pipeline", choices=PIPELINES)
+ parser.add_argument("--build-id", required=True, type=count)
+ parser.add_argument("--status", required=True, type=str.lower,
choices=RESULTS)
+ parser.add_argument("--pr", type=count)
+ parser.add_argument("--sha", type=sha, help="PR head")
+ parser.add_argument("--tested-sha", type=sha, help="commit actually
tested, when known")
+ parser.add_argument("--failed-step", choices=STEPS)
+ parser.add_argument("--target-branch", type=target_branch)
+ parser.add_argument("--started-at", type=time_with_offset)
+ parser.add_argument("--finished-at", type=time_with_offset)
+ for name in ("passed", "failed", "unmuted-failed", "ignored"):
+ parser.add_argument(f"--{name}", type=count)
+ parser.add_argument("--public-build-log", type=Path, help="trusted,
publication-ready full build log (UTF-8 text), stored beside the report as
gzip")
+ parser.add_argument("--public-doris-log", type=Path,
help="publication-ready Doris log archive (.tar.gz) from this build")
+ parser.add_argument("--public-core", type=Path, help="publication-approved
raw ELF core from this build")
+ parser.add_argument("--artifact-index", type=Path, help="this build's
native oss-artifacts.json download receipt")
+ parser.add_argument("--core-diagnostics", type=Path, help="this build's
native core-diagnostics.json or core-pairs.json")
+ parser.add_argument("--core-backtrace", type=Path, help="text output of a
debugger backtrace for this build")
+ parser.add_argument("--failure-log", type=Path, help="plain failure
excerpt or full TeamCity plain-text build log")
+ parser.add_argument("--junit", type=Path, action="append", default=[],
help="local JUnit XML (repeat for separate shards)")
+ parser.add_argument("--public-source", type=Path, help=argparse.SUPPRESS)
# compatibility with existing callers
+ parser.add_argument("--build-type-id", help="exact expected TeamCity
configuration ID for a pipeline copy")
+ parser.add_argument("--teamcity", "--diagnostics", type=Path,
help="TeamCity REST Build JSON including testOccurrences and
problemOccurrences")
+ parser.add_argument("--output-dir", type=Path, default=Path("."))
+ parser.add_argument("--upload", action="store_true", help="also publish to
the fixed OSS agent-test prefix")
+ args = parser.parse_args(argv)
+ args.build_type_id = args.build_type_id or BUILD_TYPES[args.pipeline]
+ args.teamcity_origin = os.environ.get("TEAMCITY_CURRENT_URL",
"").rstrip("/")
+ if args.teamcity_origin and not
re.fullmatch(r"https://[A-Za-z0-9.-]+(?::[0-9]+)?", args.teamcity_origin):
+ parser.error("TEAMCITY_CURRENT_URL must be a trusted HTTPS origin")
+ if args.teamcity and args.junit:
+ parser.error("Choose TeamCity or JUnit as the source of test results")
+ if len({p.resolve() for p in args.junit}) != len(args.junit):
+ parser.error("Each JUnit input must be supplied only once")
+ if not args.build_id or args.pr == 0:
+ parser.error("Build and PR IDs must be positive")
+ if args.failed_step and args.status not in ("failure", "error"):
+ parser.error("--failed-step requires a failed build")
+ key = f"builds/agent-test/{args.build_id}/index.html"
+ output = args.output_dir / key
+ try:
+ output.parent.mkdir(parents=True, exist_ok=True)
+ with tempfile.TemporaryDirectory(dir=output.parent) as staging:
+ folder = Path(staging).resolve()
+ files = []
+ args.local_downloads = {}
+ for kind, source in (("build", args.public_build_log), ("cluster",
args.public_doris_log), ("core", args.public_core)):
+ if source:
+ attachment = prepare_public_log(source, folder) if kind ==
"build" else stage_diagnostic(kind, source, folder)
+ args.local_downloads[kind] = attachment.name
+ files.append(attachment)
+ staged = folder / "index.html"
+ staged.write_bytes(report(args))
+ for file in [*files, staged]:
+ if args.upload:
+ upload(file, str(Path(key).with_name(file.name)))
+ os.replace(file, output.with_name(file.name))
+ print(output)
+ except (OSError, subprocess.SubprocessError, ValueError, KeyError,
TypeError, argparse.ArgumentTypeError, ET.ParseError) as exc:
+ parser.exit(1, f"{exc}\n")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/regression-test/pipeline/common/test_render_ci_report.py
b/regression-test/pipeline/common/test_render_ci_report.py
new file mode 100644
index 00000000000..abed54065c3
--- /dev/null
+++ b/regression-test/pipeline/common/test_render_ci_report.py
@@ -0,0 +1,382 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import contextlib
+import gzip
+from html import unescape
+import io
+import json
+from email.message import Message
+from pathlib import Path
+from tempfile import TemporaryDirectory
+from unittest import TestCase, main
+from unittest.mock import patch
+import subprocess
+
+import render_ci_report as ci
+
+
+TEST_ORIGIN = "https://ci.example.invalid"
+
+
+class ReportTest(TestCase):
+ def setUp(self):
+ temp = TemporaryDirectory()
+ self.addCleanup(temp.cleanup)
+ env = patch.dict(ci.os.environ, {"TEAMCITY_CURRENT_URL": TEST_ORIGIN})
+ env.start()
+ self.addCleanup(env.stop)
+ self.root = Path(temp.name)
+ self.key = "builds/agent-test/3817/index.html"
+ self.output = self.root / self.key
+
+ def generate(self, *args):
+ with contextlib.redirect_stdout(io.StringIO()),
contextlib.redirect_stderr(io.StringIO()):
+ ci.main([*args, "--build-id", "3817", "--output-dir",
str(self.root)])
+
+ def test_offline_for_each_pipeline(self):
+ with patch.object(ci.subprocess, "run",
side_effect=AssertionError("unexpected network client")):
+ for pipeline, label in ci.PIPELINES.items():
+ self.generate(pipeline, "--status", "SUCCESS")
+ page = self.output.read_text()
+ self.assertIn(f"<h1>{label}</h1>", page)
+ self.assertIn(">Passed</strong>", page)
+ if pipeline != "compile":
+ self.assertIn("Case counts were not recorded", page)
+ self.assertNotIn("0 failed", page)
+
+ def test_counts_and_revision(self):
+ self.generate("p0", "--status", "failure", "--unmuted-failed", "80",
"--passed", "0",
+ "--pr", "70580", "--sha", "a"*40, "--tested-sha", "b"*40)
+ page = self.output.read_text()
+ for field in ("Unmuted failures</dt><dd>80", "Passed</dt><dd>0",
"a"*40, "b"*40, "#70580"):
+ self.assertIn(field, page)
+ self.assertNotIn("Ignored", page)
+
+ def test_invalid_or_untrusted_values(self):
+ for args in (("--sha", "<svg>"), ("--status", "running"), ("--pr",
"0"), ("--failed", "-2"),
+ ("--failed-step", "binary"), ("--tested-sha",
"https://example.invalid")):
+ with self.subTest(args=args), self.assertRaises(SystemExit):
+ self.generate("compile", "--status", "success", *args)
+ self.assertFalse(self.output.exists())
+
+ def test_failed_step_log_excludes_scripts_and_passing_steps(self):
+ log = self.root / "build.log"
+ log.write_text("Build 'Example' #1\n"
+ "embedded_script_should_not_appear\n"
+ "[10:59:59] : Step 1/3: 1. 环境预检 (Command Line)\n"
+ "[11:00:00] : [Step 1/3] AssertionError
[email protected]\n"
+ "[11:00:01] : [Step 1/3] Process exited with code 0\n"
+ "[11:00:01]E: Step 2/3: 2. 包装 (Command Line)\n"
+ "[11:00:02] : [Step 2/3] OSError: [Errno 7] Argument
list too long: 'java'\n"
+ "[11:00:03]E: [Step 2/3] Process exited with code 1\n"
+ "[11:00:04] : [Step 3/3] Bearer test_secret_123
https://10.0.0.5/private\n")
+ self.generate("compile", "--status", "failure", "--failure-log",
str(log))
+ html = self.output.read_text()
+ self.assertIn("OSError: [Errno 7] Argument list too long: 'java'",
unescape(html))
+ self.assertNotIn("embedded_script_should_not_appear", html)
+ for private in ("private-user@", "test_secret_123", "10.0.0.5", "A
test assertion failed"):
+ self.assertNotIn(private, html)
+
+ def test_plain_failure_log_preserves_text_and_masks_authorization(self):
+ log = self.root / "compile.log"
+ log.write_text("starting\nERROR: Authorization=very-private-message\n")
+ self.generate("compile", "--status", "failure", "--failure-log",
str(log))
+ self.assertIn("starting\nERROR: Authorization=[redacted]\n",
self.output.read_text())
+ self.assertNotIn("very-private-message", self.output.read_text())
+
+ def test_junit_keeps_name_type_message_trace_and_escapes_markup(self):
+ xml = self.root / "junit.xml"
+ xml.write_text('<testsuite><testcase name="ok"/><testcase
classname="org.test.PlannerTest" '
+ 'name="testFilter[case1]"><failure
type="AssertionError" message="wrong row">'
+ 'expected: <3> but was: <2>\n at
testFilter:18\napi_token=very-private</failure>'
+ '<system-out>unrelated-output</system-out></testcase>'
+ '<testcase name="<script>"><error>new
exception</error></testcase></testsuite>')
+ self.generate("feut", "--status", "failure", "--junit", str(xml))
+ page = self.output.read_text()
+ for field in ("testFilter[case1]", "org.test.PlannerTest", "new
exception", "<script>",
+ "3 test executions · 2 failed · 1 passed · 0 skipped",
+ "AssertionError\nwrong row\nexpected: <3> but was:
<2>\n at testFilter:18"):
+ self.assertIn(field, page)
+ for secret in ("very-private", "unrelated-output", "<script>"):
+ self.assertNotIn(secret, page)
+
+ def test_junit_rejects_invalid_input_before_upload(self):
+ xml = self.root / "junit.xml"
+ for invalid in ("<testsuite>", '<!DOCTYPE x [<!ENTITY t
"private">]><testsuite/>', "<html/>"):
+ xml.write_text(invalid)
+ with self.assertRaises(SystemExit), patch.object(ci, "upload",
side_effect=AssertionError):
+ self.generate("p0", "--status", "failure", "--junit",
str(xml), "--upload")
+ self.assertFalse(self.output.exists())
+
+ def test_junit_shards_and_summary_only(self):
+ one, two = self.root / "1.xml", self.root / "2.xml"
+
one.write_text('<testsuite><testcase/><testcase><skipped/></testcase></testsuite>')
+ two.write_text('<testsuites><testsuite tests="5" failures="2"
errors="1" skipped="1"/></testsuites>')
+ self.generate("p0", "--status", "failure", "--unmuted-failed", "80",
"--junit", str(one), "--junit", str(two))
+ page = self.output.read_text()
+ self.assertIn("Unmuted failures</dt><dd>80", page)
+ self.assertIn("7 test executions · 3 failed · 2 passed · 2 skipped",
page)
+ self.assertIn("without individual case details", page)
+ with self.assertRaises(SystemExit):
+ self.generate("p0", "--status", "failure", "--junit", str(one),
"--junit", str(one))
+
+ def test_compile_error_and_timeline(self):
+ log = self.root / "build.log"
+ log.write_text("Build 'Community' #1\n"
+ "[08:00:00] : Step 1/2: 1. 环境预检 (Command Line) (5s)\n"
+ "[08:00:05] : [Step 1/2] Process exited with code 0\n"
+ "[08:00:05]E: Step 2/2: 2. Docker 编译 binary (Command
Line) (2s)\n"
+ "[08:00:06] : [Step 2/2] /private/be/a.cpp:42:3: error:
use of undeclared identifier 'secret_code'\n"
+ "[08:00:07]E: [Step 2/2] Process exited with code 1\n")
+ self.generate("compile", "--status", "failure", "--failure-log",
str(log),
+ "--started-at", "2026-11-24T00:00:00Z", "--finished-at",
"2026-11-24T08:00:07+08:00")
+ page = self.output.read_text()
+ self.assertIn("2. Docker 编译 binary</th><td>Failed</td><td>2s", page)
+ self.assertIn("error: use of undeclared identifier", page)
+ self.assertIn("build log L5", page)
+ self.assertIn("0m 07s", page)
+ self.assertIn("error: use of undeclared identifier 'secret_code'",
unescape(page))
+
+ def test_partial_junit_preserves_declared_totals_and_shows_one_row(self):
+ xml = self.root / "partial.xml"
+ xml.write_text('<testsuites tests="100" failures="5" errors="0"
skipped="2"><testsuite>'
+ '<testcase><failure type="AssertionError">expected:
<5> but was: <4></failure></testcase>'
+ '</testsuite></testsuites>')
+ self.generate("p0", "--status", "failure", "--junit", str(xml))
+ page = self.output.read_text()
+ self.assertIn("100 test executions · 5 failed · 93 passed · 2
skipped", page)
+ self.assertIn("1 of 5 failures", page)
+ self.assertIn("expected: <5> but was: <4>", unescape(page))
+
+ def
test_native_problems_and_occurrences_are_verbatim_and_bound_to_build(self):
+ path = self.root / "build.json"
+ error = "unrecognized error <expression>\n expected: x\nactual: y"
+ problem = "Process exited with code 1 (Step: 编译)"
+ record = {"id":3817, "state":"finished", "buildTypeId":"Doris_P0",
"status":"FAILURE",
+ "statusText":"Tests failed: 1, muted: 1",
"ignoredField":"private_env_dump",
+
"problemOccurrences":{"problemOccurrence":[{"details":problem}]},
+ "testOccurrences":{"testCounters":{"failed":1,"muted":1},
+
"testOccurrence":[{"name":"suite.Case[A]","status":"FAILURE","details":error},
+
{"name":"suite.Case[A]","status":"FAILURE","muted":True,"details":"different
trace"}]}}
+ path.write_text(json.dumps(record))
+ self.generate("p0", "--status", "failure", "--teamcity", str(path))
+ page = self.output.read_text()
+ self.assertIn(error, unescape(page))
+ self.assertIn(problem, page)
+ self.assertEqual(page.count("suite.Case[A]"), 2)
+ self.assertIn("different trace", page)
+ self.assertIn("<small>Muted</small>", page)
+ self.assertNotIn("private_env_dump", page)
+ self.assertNotIn("<expression>", page)
+ for field,value in (("id",24), ("buildTypeId","Doris_FEUT"),
("state","running"),("status","SUCCESS"),
+ ("testOccurrences",{"nextHref":"/another-page"})):
+ path.write_text(json.dumps(dict(record, **{field:value})))
+ with self.assertRaises(SystemExit):
+ self.generate("p0", "--status", "failure", "--teamcity",
str(path))
+
+ def test_redaction_preserves_sql_layout(self):
+ text = """ "s3.access_key" = "private-value",\n
's3.secret_key'='private-secret'\n at 10.0.0.4"""
+ masked = ci.redact(text)
+ self.assertEqual(masked,
text.replace("private-value","[redacted]").replace("private-secret","[redacted]").replace("10.0.0.4","[private
address]"))
+ self.assertEqual(ci.redact(masked), masked)
+
+ def test_upload_contract(self):
+ def put(argv, **options):
+ self.assertEqual(argv[0:3], ["ossutil", "api", "put-object"])
+ for flag, value in (("--mode","EcsRamRole"),
("--bucket","doris-pipelines"),
+
("--endpoint","https://oss-cn-hongkong-internal.aliyuncs.com"),
+ ("--key", self.key),
("--content-type","text/html; charset=utf-8"),
+ ("--content-disposition","inline")):
+ self.assertEqual(argv[argv.index(flag)+1], value)
+ self.assertIn("--forbid-overwrite", argv)
+ body_file =
Path(argv[argv.index("--body")+1].removeprefix("file://"))
+ self.assertIn(b"<h1>Compile</h1>", body_file.read_bytes())
+ return subprocess.CompletedProcess(argv, 0, b"", b"")
+ with patch.object(ci.subprocess, "run", side_effect=put) as client:
+ self.generate("compile", "--status", "failure", "--failed-step",
"checkout", "--upload")
+ self.assertEqual(client.call_count, 1)
+
+ def test_retry_requires_identical_bytes(self):
+ self.generate("p0", "--status", "success")
+ url = f"https://{ci.BUCKET}.{ci.ENDPOINT}/{self.key}"
+ for same in (True, False):
+ response = io.BytesIO(self.output.read_bytes() if same else
b"other report")
+ response.geturl = lambda: url
+ response.status = 200
+ response.headers = Message()
+ response.headers["Content-Type"] = "text/html; charset=utf-8"
+ result = subprocess.CompletedProcess([], 1, b"", b"409
FileAlreadyExists")
+ with patch.object(ci.subprocess, "run", return_value=result),
patch.object(ci, "urlopen", return_value=response):
+ if same:
+ self.generate("p0", "--status", "success", "--upload")
+ else:
+ with self.assertRaises(SystemExit):
+ self.generate("p0", "--status", "success", "--upload")
+
+ def test_status_is_not_inferred_from_counts(self):
+ for status in ("failure", "error", "canceled"):
+ self.generate("p0", "--status", status, "--failed", "0")
+ self.assertIn(f">{ci.RESULTS[status]}</strong>",
self.output.read_text())
+
+ def receipt(self, *objects, build="3817", pipeline="Doris_P0"):
+ path = self.root / "oss-artifacts.json"
+ path.write_text(json.dumps(dict(buildId=build, pipeline=pipeline,
state="EXPORTED", objects=objects)))
+ return str(path)
+
+ def obj(self, group, name, **attrs):
+ expires = 2000000000
+ return dict(group=group, name=name, expires=expires,
+
url=f"{TEST_ORIGIN}/_ci/diagnostics/d/{'a'*32}?expires={expires}&signature={'a'*64}",
**attrs)
+
+ def test_downloads_and_core_frames(self):
+ log = self.root / "full.log"
+ log.write_text("line one\naccess_key=classified\n-----BEGIN PRIVATE
KEY-----\n"
+ "private_payload\n-----END PRIVATE KEY-----\nlast
line\n")
+ backtrace = self.root / "bt.txt"
+ backtrace.write_text("Program terminated with signal SIGSEGV\n#0
f<Mutex> at be.cpp:42\n"
+ "#1 main () at main.cpp:8\nlocals and unrelated
output\n")
+ args = ["p0", "--status", "failure", "--public-build-log", str(log),
"--core-backtrace", str(backtrace),
+ "--artifact-index", self.receipt(self.obj("cluster",
"cluster-logs.safe-v1.tar.gz"),
+ self.obj("large-file",
"core.doris_be.123.gz"),
+ self.obj("large-file",
"doris_be.profraw"),
+ self.obj("core", "doris_be"))]
+ uploaded = []
+ def put(argv, **kwargs):
+ key = argv[argv.index("--key")+1]
+
uploaded.append((key,argv[argv.index("--content-type")+1],argv[argv.index("--content-disposition")+1]))
+ return subprocess.CompletedProcess(argv, 0, b"", b"")
+ with patch.object(ci.subprocess, "run", side_effect=put):
+ self.generate(*args, "--upload")
+ page = self.output.read_text()
+ self.assertEqual(len(uploaded), 2)
+ attachment = self.output.parent / Path(uploaded[0][0]).name
+ self.assertEqual(uploaded[0][1:], ("application/gzip", "attachment"))
+ self.assertEqual(uploaded[1][0], self.key)
+ self.assertEqual(gzip.decompress(attachment.read_bytes()).decode(),
+ "line one\naccess_key=[redacted]\n[redacted]\nlast
line\n")
+ self.assertIn(f'href="{attachment.name}"', page)
+ first = attachment.read_bytes()
+ self.generate(*args)
+ self.assertEqual(self.output.read_text(), page)
+ self.assertEqual(attachment.read_bytes(), first)
+ for expected in ("cluster-logs.safe-v1.tar.gz",
"core.doris_be.123.gz", "Core backtrace",
+ "signal SIGSEGV", "#0 f<Mutex> at be.cpp:42",
"Valid until", "data-expires="):
+ self.assertIn(expected, page)
+ for excluded in ("locals and unrelated", "doris_be.profraw",
">doris_be</a>"):
+ self.assertNotIn(excluded, page)
+
+ def test_native_core_pairs_and_archive_members(self):
+ core = self.root / "core-diagnostics.json"
+ core.write_text(json.dumps(dict(build="3817", core_pairs=[],
errors=[])))
+ self.generate("p0", "--status", "failure", "--core-diagnostics",
str(core))
+ self.assertIn("No core recorded", self.output.read_text())
+ core.write_text(json.dumps(dict(buildId="3817", pipeline="Doris_P0",
pairs=[{"backtrace":"#0 foo\n#1 bar"}])))
+ archive = self.obj("cluster", "cluster-logs.tar.gz", archive=True,
sources=["log/be/core.1473"])
+ self.generate("p0", "--status", "failure", "--artifact-index",
self.receipt(archive),
+ "--core-diagnostics", str(core))
+ page = self.output.read_text()
+ self.assertEqual(page.count(">cluster-logs.tar.gz</a>"), 2)
+ self.assertIn("#0 foo\n#1 bar", page)
+ for name in ("core-diagnostics.json", "core.1473.backtrace.txt",
"core.cpp", "unrelated.profraw"):
+ archive["sources"] = ["be/" + name]
+ self.assertEqual(ci.download_kinds(archive), ["cluster"])
+ core.write_text(json.dumps(dict(buildId=4000, pairs=[])))
+ with self.assertRaises(SystemExit):
+ self.generate("p0", "--status", "failure", "--core-diagnostics",
str(core))
+
+ def test_untrusted_or_mismatched_download_receipts_stop_publication(self):
+ original = self.obj("large-file", "core.1234")
+ url = original["url"]
+ invalid = [url.replace("https://", "http://"),
url.replace("ci.example.invalid", "[email protected]"),
+ url.replace("/_ci/", "/else/"), url + "#fragment", url +
"&next=else", url.replace("expires=", "bogus="),
+ url.replace("2000000000", "2000000001")]
+ for modified in invalid:
+ with self.subTest(url=modified), self.assertRaises(SystemExit),
patch.object(ci, "upload", side_effect=AssertionError):
+ self.generate("p0", "--status", "failure", "--artifact-index",
self.receipt(dict(original,url=modified)), "--upload")
+ for build, pipeline in (("4000", "Doris_P0"), ("3817", "Doris_FEUT")):
+ with self.assertRaises(SystemExit):
+ self.generate("p0", "--status", "failure", "--artifact-index",
self.receipt(original,build=build,pipeline=pipeline))
+ self.assertFalse(self.output.exists())
+
+ def test_attachment_upload_failure_does_not_publish_html(self):
+ path = self.root / "full.log"
+ path.write_text("test\n")
+ with patch.object(ci, "upload", side_effect=ValueError("upload
failed")) as client, self.assertRaises(SystemExit):
+ self.generate("p0", "--status", "failure", "--public-build-log",
str(path), "--upload")
+ self.assertEqual(client.call_count, 1)
+ self.assertTrue(client.call_args.args[1].endswith(".gz"))
+ self.assertFalse(self.output.exists())
+
+ def test_binary_core_never_read_as_text(self):
+ path = self.root / "core"
+ path.write_bytes(b"\x7fELF\x00private bytes")
+ with self.assertRaises(SystemExit):
+ self.generate("p0", "--status", "failure", "--core-backtrace",
str(path))
+
+ def
test_local_diagnostics_keep_bytes_and_require_matching_file_types(self):
+ archive = self.root / "cluster-logs.tar.gz"
+ archive.write_bytes(gzip.compress(b"archive test payload"))
+ core = self.root / "doris_be.core"
+ core.write_bytes(b"\x7fELF\x02\x01\x01" + bytes(9) + b"\x04\x00" +
bytes(160))
+ with patch.object(ci.subprocess, "run",
return_value=subprocess.CompletedProcess([], 0)) as client:
+ self.generate("p0", "--status", "failure", "--public-doris-log",
str(archive), "--public-core", str(core), "--upload")
+ page = self.output.read_text()
+ for source, prefix, mime, call in zip((archive, core), ("doris-logs-",
"coredump-"),
+ ("application/gzip",
"application/octet-stream"), client.call_args_list):
+ argv = call.args[0]
+ dest = self.output.with_name(Path(argv[argv.index("--key") +
1]).name)
+ self.assertTrue(dest.name.startswith(prefix))
+ self.assertIn(f'href="{dest.name}"', page)
+ self.assertEqual(dest.read_bytes(), source.read_bytes())
+ self.assertEqual(argv[argv.index("--content-type")+1], mime)
+ self.assertEqual(client.call_count, 3)
+ self.assertIn("No debugger backtrace available", page)
+ for option, wrong in (("--public-core", archive),
("--public-doris-log", core)):
+ with self.assertRaises(SystemExit), patch.object(ci, "upload",
side_effect=AssertionError):
+ self.generate("p0", "--status", "failure", option, str(wrong),
"--upload")
+
+ def test_configured_origin_and_build_copy(self):
+ path = self.root / "copy.json"
+ path.write_text(json.dumps(dict(id=3817, buildTypeId="Compile_Copy",
state="finished", status="SUCCESS")))
+ args = ["compile", "--status", "success", "--teamcity", str(path)]
+ with self.assertRaises(SystemExit):
+ self.generate(*args)
+ self.generate(*args, "--build-type-id", "Compile_Copy")
+ self.assertIn(TEST_ORIGIN + "/downloadBuildLog.html?",
self.output.read_text())
+ with patch.dict(ci.os.environ, {"TEAMCITY_CURRENT_URL": ""}):
+ self.generate(*args, "--build-type-id", "Compile_Copy")
+ self.assertNotIn("/downloadBuildLog", self.output.read_text())
+ with self.assertRaises(SystemExit):
+ self.generate("p0", "--status", "failure", "--artifact-index",
+ self.receipt(self.obj("large-file", "core.123")))
+ with patch.dict(ci.os.environ, {"TEAMCITY_CURRENT_URL":
"https://ci.example.invalid/path"}):
+ with self.assertRaises(SystemExit):
+ self.generate(*args, "--build-type-id", "Compile_Copy")
+
+ def test_truncated_or_cross_build_occurrences(self):
+ path = self.root / "build.json"
+ for occurrences in ({"count": 2, "testOccurrence": [{"name":"one"}]},
+ {"testOccurrence": [{"build":{"id":4000}}]}):
+ path.write_text(json.dumps(dict(id=3817, state="finished",
buildTypeId="Doris_P0", status="FAILURE",
+ testOccurrences=occurrences)))
+ with self.assertRaises(SystemExit):
+ self.generate("p0", "--status", "failure", "--teamcity",
str(path))
+
+
+if __name__ == "__main__":
+ main()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]