Skip to content

Commit

Permalink
add html template for test case risk analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
xueqzhan committed Nov 7, 2022
1 parent 8451d66 commit d67f411
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 0 deletions.
108 changes: 108 additions & 0 deletions e2echart/test-risk-analysis.html
@@ -0,0 +1,108 @@
<html lang="en">
<head>
<title>Risk Analysis</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<meta name="description"
content="Risk analysis is performed by Sippy to attempt to determine if the failures in this job are
abnormal when compared to results for similar jobs over the past week, and amidst on-going incidents
in the CI infrastructure. Risk analysis API will not catch everything and is a relatively simple
implementation today, please reach out to the Technical Release Team if you spot abnormalities or
have suggestions.">
</head>
<body onLoad="buildTestCaseTable('#test_case_results')">
<h1>
</h1>
<p>
"<a href="TEST_RISK_ANALYSIS_SIPPY_URL_GOES_HERE">Link to Sippy</a>"
</p>

<table id="test_case_results" border="1" width="100%">
</table>

<script>
var testResult = TEST_RISK_ANALYSIS_JSON_GOES_HERE

function buildOpenBugs(openBugs) {
td$ = $('<td/>')
if (openBugs.length > 0) {
cell$ = $('<ul/>')
for (var i = 0; i < openBugs.length; i++) {
li$ = $('<li>')
bug = "<a href=" + openBugs[i].url + ">" + openBugs[i].id + "</a>: " + openBugs[i].summary
li$.append($('<li>').html(bug))
cell$.append(li$)
}
td$.append(cell$)
}
return td$
}

function buildRiskReasons(reasons) {
td$ = $('<td/>')
if (reasons.length > 0) {
cell$ = $('<ul/>')
for (var i = 0; i < reasons.length; i++) {
li$ = $('<li>')
li$.append($('<li>').html(reasons[i]))
cell$.append(li$)
}
td$.append(cell$)
}
return td$
}

function buildRiskLevel(level) {
td$ = $('<td/>')
if (level.Level >= 10) {
td$.css("background-color", "red");
} else if (level.Level >= 5) {
td$.css("background-color", "yellow");
} else {
td$.css("background-color", "green");
}
td$.append(level.Name)
return td$
}

// Build Test Case Table
function buildTestCaseTable(selector) {
$( "h1" ).append("Risk Analysis for: " + testResult.ProwJobName + " ID: " + testResult.ProwJobRunID)

// Add table headers
addColumnHeaders(selector);

// Build Overall Row
var row$ = $('<tr/>');
row$.append($('<td/>').html("Overall"));
row$.append(buildRiskLevel(testResult.OverallRisk.Level))
row$.append(buildRiskReasons(testResult.OverallRisk.Reasons))
row$.append(buildOpenBugs(testResult.OpenBugs))
$(selector).append(row$);

// First sort the tests by risk factor
testResult.Tests.sort(function(a, b){return b.Risk.Level.Level - a.Risk.Level.Level})
// Build rows for all tests
for (var i = 0; i < testResult.Tests.length; i++) {
var row$ = $('<tr/>');
row$.append($('<td/>').html(testResult.Tests[i].Name));
row$.append(buildRiskLevel(testResult.Tests[i].Risk.Level))
row$.append(buildRiskReasons(testResult.Tests[i].Risk.Reasons))
row$.append(buildOpenBugs(testResult.Tests[i].OpenBugs))
$(selector).append(row$);
}
}

function addColumnHeaders(selector) {
var headerTr$ = $('<tr/>');
headerTr$.append($('<th/>').html("Test Name"));
headerTr$.append($('<th/>').html("Risk Level"));
headerTr$.append($('<th/>').html("Risk Reason"));
headerTr$.append($('<th/>').html("Open Bugs"));

$(selector).append(headerTr$);
}

</script>

</body>
</html>
11 changes: 11 additions & 0 deletions pkg/riskanalysis/cmd.go
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"

"github.com/openshift/origin/test/extended/testdata"
"github.com/pkg/errors"
)

Expand All @@ -22,6 +23,7 @@ type Options struct {
}

const testFailureSummaryFilePrefix = "test-failures-summary"
const sippyURL = "https://sippy.dptools.openshift.org/sippy-ng/"

// Run performs the test risk analysis by reading the output files from the test run, submitting them to sippy,
// and writing out the analysis result as a new artifact.
Expand Down Expand Up @@ -91,5 +93,14 @@ func (opt *Options) Run() error {
}
fmt.Fprintf(opt.Out, "Successfully wrote: %s\n", outputFile)

// Write html file for spyglass
riskAnalysisHTMLTemplate := testdata.MustAsset("e2echart/test-risk-analysis.html")
html := bytes.ReplaceAll(riskAnalysisHTMLTemplate, []byte("TEST_RISK_ANALYSIS_SIPPY_URL_GOES_HERE"), []byte(sippyURL))
html = bytes.ReplaceAll(html, []byte("TEST_RISK_ANALYSIS_JSON_GOES_HERE"), riskAnalysisBytes)
path := filepath.Join(opt.JUnitDir, fmt.Sprintf("%s.html", "test-risk-analysis"))
if err := ioutil.WriteFile(path, html, 0644); err != nil {
return err
}

return nil
}
127 changes: 127 additions & 0 deletions test/extended/testdata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d67f411

Please sign in to comment.