-
-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Conversation
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()); |
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 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()
?
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.
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 { |
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.
Nice 2 have. Add Javadoc to newly introduced methods
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.
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)) { |
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.
Should the limitation to AbstractBuild
be documented somewhere?
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've just wanted to keep some coherence and I just saw
jenkins/core/src/main/java/hudson/model/User.java
Lines 882 to 896 in 4d05982
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.
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 think now I've understood you well ...
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.
Maybe 5a2c62e?
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 think Oleg meant that this code only takes into account AbstractProject
s, it doesn't take into account, for example, FreeStyleProject
s.
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.
Would performance be a concern here? Given we are asking for all the items and looping through them?
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.
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.
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.
Sounds reasonable. A bad performant feature (worst case scenario) is better than a broken one.
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 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 🤷♂
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.
@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!
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)) { |
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.
Would performance be a concern here? Given we are asking for all the items and looping through them?
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 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 { |
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.
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
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.
@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
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 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
Co-Authored-By: Oleg Nenashev <[email protected]>
@oleg-nenashev I've updated the javadoc to document the limitation to |
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.
There are minor outstanding comments, but the code looks good to me overall. Thanks a lot @fcojfernandez !
Added the |
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.
Thanks for addressing the comments!
I plan to merge it tomorrow if no negative feedback
See JENKINS-60577.
Accessing the RSS feed for latest builds from the
Computer
page returns a 404 error. Whilst inUser
andView
class the methoddoRssLatest
exists, inComputer
this method is missing.I've also made a small code refactor to avoid further duplication.
Proposed changelog entries
Submitter checklist
* Use the
Internal:
prefix if the change has no user-visible impact (API, test frameworks, etc.)Desired reviewers
@jenkinsci/core-pr-reviewers