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

Changed the truncate summary to cut build logs from top #272

Merged
merged 13 commits into from
Feb 16, 2025

Conversation

sarahdeitke
Copy link
Contributor

From these two tickets:

Previous attempt at this change:
#270

Desired behavior threads:
jenkinsci/github-checks-plugin#343 (comment)
jenkinsci/github-checks-plugin#423

We believe it is better to default truncating the checks build logs to be from the start rather than the end of the logs. This behavior is better because typically the most relevant logs, especially error logs, happen at the end of the output.

I reverted my previous PR because truncating text is not actually relevant to the change I want.

I maintained the existing behavior in cases where truncating the build logs was a non-viable option.

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

*/
private Optional<String> truncateSummary(final TruncatedString summaryToTruncate, final int maxSize) {
String content = summaryToTruncate.toString();
if (!content.contains("<summary>")) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not too keen on all this implementation detail of the build log being in checks output.

Couldn't we do something smarter when we get the log here:
https://github.com/jenkinsci/checks-api-plugin/blob/master/src/main/java/io/jenkins/plugins/checks/status/FlowExecutionAnalyzer.java#L205-L208

Possibly we can offset it to only ask for the last bit of log, if we can't do that we could process it in that method to truncate to just what we need?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timja are you ok with hardcoding the max char size in the FlowExecutionAnalyzer?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think we'll need to, based on the GitHub size for now, no other providers have been published, we can refactor if anymore come along or find a way to pass the config in but for now I think it would be overengineering to do it another way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks I wasn't clear on consumers so was nervous to modify the FlowExecutionAnalyzer, but agree that's much simpler. Will refactor and tag you again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timja could you review again when you get a moment?

@@ -132,9 +134,12 @@ private Pair<String, String> processErrorOrWarningRow(final FlowGraphTable.Row r
nodeTextBuilder.append(String.format("**Error**: *%s*", displayName));
nodeSummaryBuilder.append(String.format("```%n%s%n```%n", displayName));
if (!suppressLogs) {
String log = getLog(flowNode);
// -2 for "\n\n" at the end of the summary
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it be approx -70 (or even -100 to be safe?)

echo '<details>%n<summary>Build log</summary>%n%n```%n%s%n```%n</details>' | wc
       1       2      68

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you are looking at an older version of the code, I have included the log format in the max size. I added an additional 30 character buffer to be safe though

                // -2 for "\n\n" at the end of the summary
                String logTemplate = "<details>%n<summary>Build log</summary>%n%n```%n%s%n```%n</details>";
                int maxMessageSize = MAX_MESSAGE_SIZE_TO_CHECKS_API - nodeSummaryBuilder.length() - logTemplate.length() - 2;

assertThat(details.getOutput()).isPresent().get().satisfies(output -> {
assertThat(output.getSummary()).isPresent().get().satisfies(summary -> {
// Verify the log section exists and is truncated
assertThat(summary).contains("<details>");
Copy link
Member

Choose a reason for hiding this comment

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

could you also check for </details> to make sure its not dropped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@timja timja added the enhancement New feature or request label Feb 16, 2025
Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

Thanks!

@timja timja merged commit bfdc7df into jenkinsci:master Feb 16, 2025
22 checks passed
@mwebber
Copy link

mwebber commented Feb 17, 2025

@timja The v2.2.3 release which includes this PR shows up at https://plugins.jenkins.io/checks-api/releases/, but without any summary of changes, and v2.2.3 does not appear at all at https://github.com/jenkinsci/checks-api-plugin/releases.
Is there some step that was missed in the release process?
(v2.2.3 does appear in my Jenkins → Manage Jenkins → Plugins → Updates)

@timja
Copy link
Member

timja commented Feb 17, 2025

@timja The v2.2.3 release which includes this PR shows up at plugins.jenkins.io/checks-api/releases, but without any summary of changes, and v2.2.3 does not appear at all at jenkinsci/checks-api-plugin/releases. Is there some step that was missed in the release process? (v2.2.3 does appear in my Jenkins → Manage Jenkins → Plugins → Updates)

yes a manual step in this repo that I missed, see here: https://github.com/jenkinsci/checks-api-plugin/releases/tag/v2.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants