-
Notifications
You must be signed in to change notification settings - Fork 124
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
[JENKINS-73824][JENKINS-73835] Remove redundant log rotation after changes in core and add regression tests related to deleting Pipeline jobs and builds #470
Changes from all commits
cd986f1
3426a6a
bf16a19
3ac9611
727f35b
fe9e2fa
e42df03
fdc5a32
f87c54e
ff71764
1232095
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -660,13 +660,6 @@ private void finish(@NonNull Result r, @CheckForNull Throwable t) { | |
listener = null; | ||
} | ||
saveWithoutFailing(true); | ||
Timer.get().submit(() -> { | ||
try { | ||
getParent().logRotate(); | ||
} catch (Exception x) { | ||
LOGGER.log(Level.WARNING, "failed to perform log rotation after " + this, x); | ||
} | ||
}); | ||
Comment on lines
-663
to
-669
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally made asynchronous in 63fdbe8. Note though that since jenkinsci/jenkins#4368, Jenkins core was also calling With this PR only Jenkins core calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (#70) |
||
onEndBuilding(); | ||
} finally { // Ensure this is ALWAYS removed from FlowExecutionList | ||
FlowExecutionList.get().unregister(new Owner(this)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import static org.hamcrest.collection.IsEmptyCollection.empty; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.emptyArray; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
@@ -58,6 +59,7 @@ | |
import hudson.slaves.EnvironmentVariablesNodeProperty; | ||
import hudson.slaves.NodeProperty; | ||
import hudson.slaves.NodePropertyDescriptor; | ||
import hudson.tasks.LogRotator; | ||
import hudson.util.DescribableList; | ||
import hudson.util.StreamTaskListener; | ||
import java.io.File; | ||
|
@@ -73,6 +75,7 @@ | |
import java.util.TreeSet; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import jenkins.model.CauseOfInterruption; | ||
import jenkins.model.InterruptedBuildAction; | ||
import jenkins.model.Jenkins; | ||
|
@@ -109,6 +112,7 @@ | |
import org.xml.sax.SAXException; | ||
|
||
public class WorkflowRunTest { | ||
private static final Logger LOGGER = Logger.getLogger(WorkflowRunTest.class.getName()); | ||
|
||
@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher(); | ||
@Rule public JenkinsRule r = new JenkinsRule(); | ||
|
@@ -520,7 +524,7 @@ private void assertCulprits(WorkflowRun b, String... expectedIds) throws IOExcep | |
assertThat(await().until(() -> ExtensionList.lookupSingleton(CheckCompletedFlag.class).buildXml.get(b.getExternalizableId()), notNullValue()), | ||
containsString("<completed>true</completed>")); | ||
} | ||
@TestExtension public static final class CheckCompletedFlag extends RunListener<WorkflowRun> { | ||
@TestExtension("completedFlag") public static final class CheckCompletedFlag extends RunListener<WorkflowRun> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only need by this specific test and causes annoying log spam in the new test since it tries to look at build directories for deleted builds. |
||
final Map<String, String> buildXml = new HashMap<>(); | ||
@Override public void onFinalized(WorkflowRun r) { | ||
try { | ||
|
@@ -600,6 +604,20 @@ private void assertCulprits(WorkflowRun b, String... expectedIds) throws IOExcep | |
assertPollingBaselines(b3.checkouts(listener), nullValue(), nullValue()); | ||
} | ||
|
||
@SafeVarargs | ||
private static void assertPollingBaselines(List<WorkflowRun.SCMCheckout> checkouts, Matcher<Object>... indexedMatchers) { | ||
assertThat("Number of checkouts should match number of matchers", checkouts.size(), equalTo(indexedMatchers.length)); | ||
for (int i = 0; i < checkouts.size(); i++) { | ||
assertThat("Unexpected baseline for checkout at index " + i, checkouts.get(i).pollingBaseline, indexedMatchers[i]); | ||
} | ||
} | ||
|
||
private static String checkoutString(GitSampleRepoRule repo, boolean changelog, boolean polling) { | ||
return " checkout(changelog:" + changelog +", poll:" + polling + | ||
", scm: [$class: 'GitSCM', branches: [[name: '*/master']], " + | ||
", userRemoteConfigs: [[url: $/" + repo.fileUrl() + "/$]]])\n"; | ||
} | ||
|
||
Comment on lines
+607
to
+620
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just moving these next to the relevant test for clarity. |
||
// This test is to ensure that the shortDescription on the CancelCause is escaped properly on summary.jelly | ||
@Issue("SECURITY-3042") | ||
@Test public void escapedDisplayNameAfterAbort() throws Exception { | ||
|
@@ -667,19 +685,42 @@ public void onInitialize(Run run) { | |
|
||
} | ||
|
||
|
||
@SafeVarargs | ||
private static void assertPollingBaselines(List<WorkflowRun.SCMCheckout> checkouts, Matcher<Object>... indexedMatchers) { | ||
assertThat("Number of checkouts should match number of matchers", checkouts.size(), equalTo(indexedMatchers.length)); | ||
for (int i = 0; i < checkouts.size(); i++) { | ||
assertThat("Unexpected baseline for checkout at index " + i, checkouts.get(i).pollingBaseline, indexedMatchers[i]); | ||
@Issue("JENKINS-73835") | ||
@Test public void logRotationOnlyProcessesCompletedBuilds() throws Throwable { | ||
logging.record(LogRotator.class, Level.FINER); | ||
var p = r.createProject(WorkflowJob.class); | ||
p.setDefinition(new CpsFlowDefinition( | ||
"echo params.FOO; semaphore 'wait'", true)); | ||
p.addProperty(new ParametersDefinitionProperty(List.of(new StringParameterDefinition("FOO")))); | ||
// Keep 0 builds, i.e. delete all builds immediately. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am keeping 0 builds rather than 1 build to simplify test assertions. Mainly I am trying to avoid complicated issues involving the exact timing of calls to |
||
LogRotator logRotator = new LogRotator(-1, 0, -1, -1); | ||
logRotator.setRemoveLastBuild(true); | ||
p.setBuildDiscarder(logRotator); | ||
int buildsToRun = 10; // Increase this number to reproduce the issue more easily prior to the fix. | ||
Run[] builds = new Run[buildsToRun]; | ||
File[] buildDirs = new File[buildsToRun]; | ||
// Run a large number of builds that should finish around the same time to check race conditions with log rotation and build completion. | ||
for (int i = 0; i < buildsToRun; i++) { | ||
var b = p.scheduleBuild2(0, new ParametersAction(List.of(new StringParameterValue("FOO", "b" + i)))).waitForStart(); | ||
builds[i] = b; | ||
buildDirs[i] = b.getRootDir(); | ||
SemaphoreStep.waitForStart("wait/" + (i+1), b); | ||
} | ||
for (int i = 0; i < buildsToRun; i++) { | ||
SemaphoreStep.success("wait/" + (i+1), null); | ||
} | ||
LOGGER.info("Waiting for all builds to complete"); | ||
for (int i = 0; i < buildsToRun; i++) { | ||
r.waitForCompletion(builds[i]); | ||
} | ||
LOGGER.info("Checking that all build directories are empty"); | ||
for (int i = 0; i < buildsToRun; i++) { | ||
String[] filesInBuildDir = buildDirs[i].list(); | ||
if (filesInBuildDir == null) { | ||
filesInBuildDir = new String[0]; | ||
} | ||
assertThat("Expected " + buildDirs[i] + " to be empty but saw: " + Arrays.toString(filesInBuildDir), filesInBuildDir, emptyArray()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prior to the fix, this fails intermittently because some directory contains |
||
} | ||
} | ||
|
||
private static String checkoutString(GitSampleRepoRule repo, boolean changelog, boolean polling) { | ||
return " checkout(changelog:" + changelog +", poll:" + polling + | ||
", scm: [$class: 'GitSCM', branches: [[name: '*/master']], " + | ||
", userRemoteConfigs: [[url: $/" + repo.fileUrl() + "/$]]])\n"; | ||
} | ||
|
||
} |
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.
Up to reviewers what we want to do here. The removal of the call to
logRotate
inWorkflowRun.finish
eliminates a redundancy, but things should be fine for 2.481+ users even with the redundant log rotation. We can either merge this as-is or wait for the fixes to make it into an LTS line.