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-60577] - Prevent the RSS feed in Computer page from returning an error 404 #4411

Merged
merged 7 commits into from
Jan 15, 2020

Conversation

fcojfernandez
Copy link
Member

See JENKINS-60577.

Accessing the RSS feed for latest builds from the Computer page returns a 404 error. Whilst in User and View class the method doRssLatest exists, in Computer this method is missing.
I've also made a small code refactor to avoid further duplication.

Proposed changelog entries

  • JENKINS-60577, Prevent the RSS feed in Computer page from returning an error 404

Submitter checklist

  • JIRA issue is well described
  • Changelog entry appropriate for the audience affected by the change (users or developer, depending on the change). Examples
    * Use the Internal: prefix if the change has no user-visible impact (API, test frameworks, etc.)
  • Appropriate autotests or explanation to why this change has no tests
  • For dependency updates: links to external changelogs and, if possible, full diffs

Desired reviewers

@jenkinsci/core-pr-reviewers

@fcojfernandez fcojfernandez requested a review from a team January 2, 2020 13:17
RunList runs) throws IOException, ServletException {
RSS.forwardToRss(getDisplayName() + suffix, getUrl(), runs.newBuilds(),
Run.FEED_ADAPTER, req, rsp);
RSS.rss(req, rsp, getDisplayName() + " failed builds", getUrl(), getBuilds().failureOnly().newBuilds());
Copy link
Member

Choose a reason for hiding this comment

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

I feel like it would be a huge change, but would It make more sense to make RSS an interface, and have a function that returns getBuilds().failureOnly().newBuilds() ?

@MarkEWaite MarkEWaite added the bug For changelog: Minor bug. Will be listed after features label Jan 2, 2020
@oleg-nenashev oleg-nenashev self-requested a review January 3, 2020 22:40
@oleg-nenashev oleg-nenashev changed the title [JENKINS-60577] Rss Latest Builds for Computer [JENKINS-60577] - Prevent the RSS feed in Computer page from returning an error 404 Jan 3, 2020
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! It is definitely an improvement which worth merging. OTOH it would be great to document new API and limitations of the newly introduced endpoint

@@ -90,4 +91,14 @@ public static void doTrackback( Object it, StaplerRequest req, StaplerResponse r

req.getView(Jenkins.get(),"/hudson/"+flavor+".jelly").forward(req,rsp);
}

public static void rss(StaplerRequest req, StaplerResponse rsp, String title, String url, RunList runList) throws IOException, ServletException {
Copy link
Member

Choose a reason for hiding this comment

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

Nice 2 have. Add Javadoc to newly introduced methods

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed!. I thought I had added before the commit 🤦‍♂️


public void doRssLatest( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
final List<Run> lastBuilds = new ArrayList<>();
for (AbstractProject<?, ?> p : Jenkins.get().allItems(AbstractProject.class)) {
Copy link
Member

Choose a reason for hiding this comment

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

Should the limitation to AbstractBuild be documented somewhere?

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've just wanted to keep some coherence and I just saw

public void doRssLatest(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
final List<Run> lastBuilds = new ArrayList<>();
for (AbstractProject<?, ?> p : Jenkins.get().allItems(AbstractProject.class)) {
for (AbstractBuild<?, ?> b = p.getLastBuild(); b != null; b = b.getPreviousBuild()) {
if (relatedTo(b)) {
lastBuilds.add(b);
break;
}
}
}
// historically these have been reported sorted by project name, we switched to the lazy iteration
// so we only have to sort the sublist of runs rather than the full list of irrelevant projects
lastBuilds.sort((o1, o2) -> Items.BY_FULL_NAME.compare(o1.getParent(), o2.getParent()));
rss(req, rsp, " latest build", RunList.fromRuns(lastBuilds), Run.FEED_ADAPTER_LATEST);
}

TBH, I don't know if any kind of limitation should apply. I will add a javadoc explaining what is displayed and if you think something else / other documentation is needed just let me know and I'm happy to add it.

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 think now I've understood you well ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe 5a2c62e?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think Oleg meant that this code only takes into account AbstractProjects, it doesn't take into account, for example, FreeStyleProjects.

Copy link

Choose a reason for hiding this comment

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

Would performance be a concern here? Given we are asking for all the items and looping through them?

Copy link
Member Author

Choose a reason for hiding this comment

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

TBH, I don't think this feature is widely used since it's been broken for so long, so personally I wound't care (personal opinion).
As I said above, I'm mimicking the current behaviour for the already existing User class. If there is another way to gather that information, I'm unknown. And also I'm open to suggestions if this is not the information that should be retrieved.

Copy link

Choose a reason for hiding this comment

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

Sounds reasonable. A bad performant feature (worst case scenario) is better than a broken one.

Copy link
Member

Choose a reason for hiding this comment

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

I think Oleg meant that this code only takes into account AbstractProjects, it doesn't take into account, for example, FreeStyleProjects.

It does not take Pipeline into account, for example. I know that we are still waiting for proper Node information API to be exposed for Pipeline, but 🤷‍♂

Copy link
Member Author

Choose a reason for hiding this comment

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

@MRamonLeon and @oleg-nenashev you're right. I should have misread the feed in my tests. It's only displaying the FreeStyleProject and not the pipeline:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>principal last builds only</title>
  <link rel="alternate" type="text/html" href="http://localhost:7080/computer/(master)/"/>
  <updated>2020-01-13T09:52:40Z</updated>
  <author>
    <name>Jenkins Server</name>
  </author>
  <id>urn:uuid:903deee0-7bfa-11db-9fe1-0800200c9a66</id>
  <entry>
    <title>free #3 (estable)</title>
    <link rel="alternate" type="text/html" href="http://localhost:7080/job/free/3/"/>
    <id>tag:hudson.dev.java.net,2020:free:3</id>
    <published>2020-01-13T09:52:40Z</published>
    <updated>2020-01-13T09:52:40Z</updated>
  </entry>
</feed>

I will change the javadoc!

@oleg-nenashev oleg-nenashev added the plugin-api-changes Changes the API of Jenkins available for use in plugins. label Jan 3, 2020
@fcojfernandez
Copy link
Member Author

The failing tests is totally unrelated to this PR. Closing and re-opening so the CI is re-launched.


public void doRssLatest( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
final List<Run> lastBuilds = new ArrayList<>();
for (AbstractProject<?, ?> p : Jenkins.get().allItems(AbstractProject.class)) {
Copy link

Choose a reason for hiding this comment

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

Would performance be a concern here? Given we are asking for all the items and looping through them?

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

I believe the doRssLatest() javadoc should explicitly document the limitation that only AbstractProject-based jobs will be supported. Sorry for not explicitly referencing other job types in https://github.com/jenkinsci/jenkins/pull/4411/files#r362985417

/**
* Retrieve the RSS feed for the last build for each project executed in this computer
*/
public void doRssLatest( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
Copy link
Member

Choose a reason for hiding this comment

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

Should it be marked as @Restricted(DoNotlUse.class). AFAIK it is only for Stapler. And yes, I know that the historical methods are not annotated. So it is not blocking

Copy link
Member Author

Choose a reason for hiding this comment

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

@oleg-nenashev I'm happy to add the annotation. Should I annotate the other methods in this class? and in the other classes? I can do it as part of this PR

Copy link
Member

Choose a reason for hiding this comment

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

I think it is fine to annotate this class in this pull request. If you prefer to be on the safe side, just do it for newly introduced endpoints

@fcojfernandez
Copy link
Member Author

@oleg-nenashev I've updated the javadoc to document the limitation to AbstractProjects. Let me know if you want me to add the annotation and if it's convenient to add it to the rest of methods

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

There are minor outstanding comments, but the code looks good to me overall. Thanks a lot @fcojfernandez !

@fcojfernandez
Copy link
Member Author

Added the @Restricted annotation. I think this PR is ready for merge, but since I'm the author I will let @oleg-nenashev or any other member of @jenkinsci/core-pr-reviewers add the label.

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments!
I plan to merge it tomorrow if no negative feedback

@oleg-nenashev oleg-nenashev added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Jan 14, 2020
@oleg-nenashev oleg-nenashev merged commit 3ade716 into jenkinsci:master Jan 15, 2020
@fcojfernandez fcojfernandez deleted the JENKINS-60577 branch January 15, 2020 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Minor bug. Will be listed after features plugin-api-changes Changes the API of Jenkins available for use in plugins. ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants