Skip to content

[JENKINS-34217] add option to disable historical statistics gathering… #133

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/hudson/tasks/junit/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import edu.hm.hafner.echarts.ChartModelConfiguration;
import edu.hm.hafner.echarts.JacksonFacade;
import edu.hm.hafner.echarts.LinesChartModel;
import hudson.model.Job;
import hudson.model.Run;
import jenkins.model.Jenkins;
import hudson.tasks.test.TestObject;
import hudson.tasks.test.TestObjectIterable;
import hudson.tasks.test.TestResultDurationChart;
Expand All @@ -34,6 +37,8 @@
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.bind.JavaScriptMethod;
import java.util.List;
import java.util.ArrayList;

/**
* History of {@link hudson.tasks.test.TestObject} over time.
Expand All @@ -49,13 +54,29 @@ public History(TestObject testObject) {
this.testObject = testObject;
}

public List<TestResult> getList(int start, int end) {
List<TestResult> list = new ArrayList<TestResult>();
end = Math.min(end, testObject.getRun().getParent().getBuilds().size());
for (Run<?,?> b: testObject.getRun().getParent().getBuilds().subList(start, end)) {
if (b.isBuilding()) continue;
TestResult o = testObject.getResultInRun(b);
if (o != null) {
list.add(o);
}
}
return list;
}

@SuppressWarnings("unused") // Called by jelly view
public TestObject getTestObject() {
return testObject;
}

@SuppressWarnings("unused") // Called by jelly view
public boolean historyAvailable() {
Job<?,?> job = testObject.getRun().getParent();
JobTestResultDisplayProperty settings = job.getProperty(JobTestResultDisplayProperty.class);
if (settings != null && settings.getDisableHistoricalResults()) return false
if (testObject instanceof hudson.tasks.junit.TestResult) {
TestResultImpl pluggableStorage = ((hudson.tasks.junit.TestResult) testObject).getPluggableStorage();
if (pluggableStorage != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* The MIT License
*
* Copyright 2016 SAP SE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.tasks.junit;

import hudson.Extension;
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

/**
*
*/
public class JobTestResultDisplayProperty extends JobProperty<Job<?, ?>> {
private final boolean disableHistoricalResults;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use spaces not tabs please to be consistent with elsewhere


public JobTestResultDisplayProperty(Boolean disableHistoricalResults) {
if ( disableHistoricalResults != null ) {
this.disableHistoricalResults = disableHistoricalResults;
}
else {
this.disableHistoricalResults = false;
}
}

public boolean getDisableHistoricalResults() {
return disableHistoricalResults;
}

@Extension
public static class DescriptorImpl extends JobPropertyDescriptor {

@Override
public String getDisplayName() {
return "";
}

@Override
public JobTestResultDisplayProperty newInstance(StaplerRequest req, JSONObject formData) {
if (formData.isNullObject()) return null;
return new JobTestResultDisplayProperty(formData.getBoolean("junitsettings-disableHistoricalResults"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

field should be stored on the descriptor I think and then use data binding instead of retrieving from formData

}
}
}
11 changes: 11 additions & 0 deletions src/main/java/hudson/tasks/junit/TestResultAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ public List<CaseResult> getSkippedTests() {
}


@Override
public boolean shouldCalculatePreviousResults() {
JobTestResultDisplayProperty settings = run.getParent().getProperty(JobTestResultDisplayProperty.class);
if ( settings != null ) {
return !settings.getDisableHistoricalResults();
}
else {
return super.shouldCalculatePreviousResults();
}
}

/**
* Loads a {@link TestResult} from disk.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ public double getHealthScaleFactor() {
return 1.0;
}

/**
* Allows a particular job to disable scanning previous result history.
*
* @return if calculation of previous results should be done
*/
public boolean shouldCalculatePreviousResults() {
return true;
}

/**
* Exposes this object to the remote API.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/hudson/tasks/test/TestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public TestResult getPreviousResult() {
if (b == null) {
return null;
}

// abort if the job is configured to not do this
AbstractTestResultAction tra = b.getAction(getParentAction().getClass());
if ( tra != null && !tra.shouldCalculatePreviousResults()) return null;

while(true) {
b = b.getPreviousBuild();
if(b==null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private TestResultActionIterable createBuildHistory(Run<?, ?> lastCompletedBuild
@Deprecated
public void doTrend( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
AbstractTestResultAction a = getLastTestResultAction();
if(a!=null)
if(a!=null && a.shouldCalculatePreviousResults())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not used anymore

a.doGraph(req,rsp);
else
rsp.setStatus(HttpServletResponse.SC_NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
The MIT License

Copyright 2016 SAP AG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:optionalBlock name="junitsettings-disableHistoricalResults"
title="${%Disable JUnit historical test results statistics}"
checked="${instance.disableHistoricalResults}"
inline="true"
help="/descriptor/hudson.tasks.junit.JobTestResultDisplayProperty/help/disableHistoricalResults"
/>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
The MIT License

Copyright 2016 SAP AG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<div>
If enabled, historical test results will not be computed and maintained for this job.
<br>
The test results graph will not be displayed, and the number of builds for which a test has been failing will not be computed.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,31 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:local="local" xmlns:c="/charts">
<c:trend-chart it="${from}" title="${%Test Result Trend}" enableLinks="true"/>
<j:set var="tr" value="${action.lastTestResultAction}" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect merge conflict resolution

<j:if test="${tr.previousResult!=null and tr.shouldCalculatePreviousResults()}">
<!-- at least two data points are required for a trend report -->
<div align="right">
<j:set var="mode" value="${h.getCookie(request,'TestResultAction_failureOnly').value}" />
<j:if test="${mode!=null}">
<j:set var="trendQueryString1" value="?failureOnly=${mode}" />
<j:set var="trendQueryString2" value="&amp;failureOnly=${mode}" />
</j:if>
<div class="test-trend-caption">
${%Test Result Trend}
</div>
<div>
<img src="test/trend${trendQueryString1}" lazymap="test/trendMap${trendQueryString1}" alt="[Test result trend chart]"/>
</div>
<div style="text-align:right">
<a href="test/flipTrend">
<j:choose>
<!-- needs to strip whitespace here -->
<j:when test="${mode}">(${%show test # and failure #})</j:when>
<j:otherwise>(${%just show failures})</j:otherwise>
</j:choose>
</a> <st:nbsp/>
<a href="test/?width=800&amp;height=600${trendQueryString2}">${%enlarge}</a>
</div>
</div>
</j:if>
</j:jelly>