-
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
Conversation
…ng only on a OneOffExecutor
…nd add a regression test for LogRotator deleting incomplete builds
Timer.get().submit(() -> { | ||
try { | ||
getParent().logRotate(); | ||
} catch (Exception x) { | ||
LOGGER.log(Level.WARNING, "failed to perform log rotation after " + this, x); | ||
} | ||
}); |
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.
Originally made asynchronous in 63fdbe8. Note though that since jenkinsci/jenkins#4368, Jenkins core was also calling Job.logRotate
synchronously from Run.onEndBuilding
-> RunListener.onFinalized
(at least with the default global build discarder configuration), so one of the calls was redundant.
With this PR only Jenkins core calls Job.logRotate
, and it does so synchronously. We could make that call asynchronous if there are any concerns, but given that default configurations have been calling it synchronously for years now, it didn't seem necessary to preserve the asynchronicity.
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.
(#70)
@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"; | ||
} | ||
|
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.
Just moving these next to the relevant test for clarity.
@@ -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 comment
The 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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Prior to the fix, this fails intermittently because some directory contains build.xml
.
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 comment
The 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 RunList.size
and RunList.sublist
in LogRotator.perform
compared to other builds completing, which can cause builds other than the one with the largest build number to be preserved by LogRotator
.
pom.xml
Outdated
<jenkins.version>2.454</jenkins.version> | ||
<!-- TODO: Waiting for https://github.com/jenkinsci/jenkins/pull/9810 to make it to an LTS line. --> | ||
<jenkins.version>2.479-rc35393.97fb_6a_a_25d9b_</jenkins.version> | ||
<!-- Waiting for a release of https://github.com/jenkinsci/plugin-pom/pull/1004 --> |
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.
src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Jesse Glick <[email protected]>
Core PR has been merged but not yet released. I think in this case we should go ahead and release the cleanup here once the next weekly is out, even if it means we need to use a weekly as a baseline temporarily. I think the core fix is a reasonable backporting candidate as well, so I will mark it as |
@@ -63,7 +63,8 @@ | |||
</pluginRepositories> | |||
<properties> | |||
<changelist>999999-SNAPSHOT</changelist> | |||
<jenkins.version>2.479</jenkins.version> | |||
<!-- TODO: Waiting for JENKINS-73824 and JENKINS-73835 to make it into an LTS line --> | |||
<jenkins.version>2.481</jenkins.version> |
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
in WorkflowRun.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.
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.
I see no problem with merging as is (just bump the BOM). Can always drop the core dep back down to 2.479.x later if the requisite core fixes are backported.
See JENKINS-73835 and jenkinsci/jenkins#9810. Thematically related to #468 and jenkinsci/jenkins#9790.
The upstream changes allow us to remove the direct call to
getParent().logRotate()
fromWorkflowRun.finish()
in this PR, and we can add a regression test for log rotation potentially cleaning up Pipeline builds too early.Testing done
See new automated test.
Submitter checklist