Skip to content
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

Merged
merged 11 commits into from
Oct 15, 2024

Conversation

dwnusbaum
Copy link
Member

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() from WorkflowRun.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

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@dwnusbaum dwnusbaum added the bug label Oct 1, 2024
Comment on lines -663 to -669
Timer.get().submit(() -> {
try {
getParent().logRotate();
} catch (Exception x) {
LOGGER.log(Level.WARNING, "failed to perform log rotation after " + this, x);
}
});
Copy link
Member Author

@dwnusbaum dwnusbaum Oct 1, 2024

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.

Copy link
Member

Choose a reason for hiding this comment

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

(#70)

Comment on lines +607 to +620
@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";
}

Copy link
Member Author

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> {
Copy link
Member Author

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());
Copy link
Member Author

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.
Copy link
Member Author

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 -->
Copy link
Member

Choose a reason for hiding this comment

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

@dwnusbaum
Copy link
Member Author

dwnusbaum commented Oct 14, 2024

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 lts-candidate, and then we could swap to the LTS line here if it does get backported.

@dwnusbaum dwnusbaum changed the title [JENKINS-73835] Remove redundant log rotation after changes in core and add a regression test for LogRotator deleting incomplete builds [JENKINS-73824][JENKINS-73835] Remove redundant log rotation after changes in core and add regression tests related to deleting Pipeline jobs and builds Oct 15, 2024
@@ -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>
Copy link
Member Author

@dwnusbaum dwnusbaum Oct 15, 2024

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.

@dwnusbaum dwnusbaum marked this pull request as ready for review October 15, 2024 17:40
@dwnusbaum dwnusbaum requested a review from a team as a code owner October 15, 2024 17:40
pom.xml Outdated Show resolved Hide resolved
Copy link
Member

@jglick jglick left a 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.

@dwnusbaum dwnusbaum enabled auto-merge October 15, 2024 19:57
@dwnusbaum dwnusbaum merged commit 6c53109 into jenkinsci:master Oct 15, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants