-
Notifications
You must be signed in to change notification settings - Fork 123
petri: add and publish log viewer web tool #1413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Petri test results</title> | ||
<style type="text/css"> | ||
body { | ||
font-family: monospace; | ||
font-size: 14px; | ||
} | ||
</style> | ||
<script> | ||
const baseUrl = "https://openvmmghtestresults.blob.core.windows.net/results"; | ||
|
||
const cross = "❌"; // Cross for failed tests | ||
const check = "✅"; // Check for passed tests | ||
|
||
function parseBlobs(xmlText) { | ||
const parser = new DOMParser(); | ||
const xmlDoc = parser.parseFromString(xmlText, "text/xml"); | ||
const blobs = xmlDoc.getElementsByTagName("Blob"); | ||
let blobNames = []; | ||
for (const blob of blobs) { | ||
const name = blob.getElementsByTagName("Name")[0].textContent; | ||
const date = new Date(blob.getElementsByTagName("Creation-Time")[0].textContent); | ||
let metadata = {}; | ||
for (const meta of blob.getElementsByTagName("Metadata")) { | ||
const child = meta.children[0]; | ||
metadata[child.tagName] = child.textContent; | ||
} | ||
blobNames.push({ | ||
name: name, | ||
creationTime: date, | ||
metadata: metadata, | ||
}); | ||
} | ||
return blobNames; | ||
} | ||
|
||
// Get the blob list, which is in XML via a GET request. | ||
function getTestList(runName) { | ||
const url = `${baseUrl}?restype=container&comp=list&showonly=files&prefix=${encodeURIComponent(runName)}`; | ||
fetch(url) | ||
.then(response => response.text()) | ||
.then(data => { | ||
let blobs = parseBlobs(data); | ||
let run = {}; | ||
for (const blob of blobs) { | ||
const nameParts = blob.name.split("/"); | ||
let fileName = nameParts[nameParts.length - 1]; | ||
let failed; | ||
if (fileName === "petri.passed") { | ||
failed = false; | ||
} else if (fileName === "petri.failed") { | ||
failed = true; | ||
} else { | ||
continue; // Not a test result file. | ||
} | ||
const testName = nameParts[nameParts.length - 2]; | ||
const jobName = nameParts[nameParts.length - 3]; | ||
const path = nameParts.slice(0, -3).join("/"); | ||
const url = `test.html?run=${path}&job=${jobName}&test=${testName}`; | ||
if (!run[jobName]) { | ||
run[jobName] = { | ||
failed: false, | ||
tests: [], | ||
}; | ||
} | ||
let job = run[jobName]; | ||
job.failed |= failed; | ||
job.tests.push({ | ||
name: testName, | ||
url: url, | ||
failed: failed, | ||
}); | ||
} | ||
|
||
let failedHtml = ""; | ||
let passingHtml = ""; | ||
|
||
for (const job in run) { | ||
run[job].tests.sort((a, b) => { | ||
if (a.failed !== b.failed) { | ||
return a.failed ? -1 : 1; // Failed tests first. | ||
} | ||
return a.name.localeCompare(b.name); // Then by name. | ||
}); | ||
let thisHtml = `<li>${job}<ul>`; | ||
for (const test of run[job].tests) { | ||
let icon = test.failed ? cross : check; | ||
thisHtml += `<li><a href="${test.url}">${icon} ${test.name}</a></li>`; | ||
} | ||
thisHtml += "</ul></li>"; | ||
if (run[job].failed) { | ||
failedHtml += thisHtml; | ||
} else { | ||
passingHtml += thisHtml; | ||
} | ||
} | ||
|
||
let html = `<h2>Failed jobs</h2> | ||
<ul>${failedHtml}</ul> | ||
<h2>Passing jobs</h2> | ||
<ul>${passingHtml}</ul>`; | ||
|
||
document.getElementById("runList").innerHTML = html; | ||
}) | ||
.catch(error => console.error('Error fetching blob list:', error)); | ||
} | ||
|
||
function getRunList() { | ||
const url = `${baseUrl}?restype=container&comp=list&showonly=files&include=metadata&prefix=runs/`; | ||
fetch(url) | ||
.then(response => response.text()) | ||
.then(data => { | ||
const blobs = parseBlobs(data); | ||
const runs = blobs.map(blob => { | ||
// Remove runs/ prefix. | ||
return { | ||
name: blob.name.replace(/^runs\//, ''), | ||
creationTime: blob.creationTime, | ||
failed: blob.metadata["petrifailed"], | ||
}; | ||
}); | ||
runs.sort((a, b) => b.creationTime - a.creationTime); // Sort by creation time, newest first. | ||
let html = `<table> | ||
<thead> | ||
<tr> | ||
<th>Time</th> | ||
<th>Run</th> | ||
<th>Failed</th> | ||
</tr> | ||
</thead> | ||
<tbody>`; | ||
for (const run of runs) { | ||
const marker = run.failed > 0 ? cross : check; | ||
html += `<tr> | ||
<td>${run.creationTime.toLocaleString()}</td> | ||
<td><a href="?run=${encodeURIComponent(run.name)}">${run.name} ${marker}</a></td> | ||
<td>${run.failed}</td> | ||
</tr>`; | ||
} | ||
html += "</table>"; | ||
if (runs.length === 0) { | ||
html = "No runs found."; | ||
} | ||
document.getElementById("runList").innerHTML = html; | ||
}) | ||
.catch(error => console.error('Error fetching run list:', error)); | ||
} | ||
|
||
window.onload = function () { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const run = urlParams.get('run'); | ||
document.getElementById("runList").innerText = "Loading..."; | ||
if (run) { | ||
document.getElementById("runName").innerText = run; | ||
document.getElementById("backToRuns").innerHTML = `<a href="?">All runs</a>`; | ||
getTestList(run); | ||
} else { | ||
document.getElementById("runName").innerText = "Runs"; | ||
getRunList(); | ||
} | ||
}; | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<h1 id="runName">Loading</h1> | ||
<div id="backToRuns"></div> | ||
<div id="runList"></div> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's time for a 'landing page', or at least a page very early on in the guide with links to this and rustdoc? I think we have one in the guide right now but it's very far down the table of contents.