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-71244] Avoid relative link in update center #7992

Merged
merged 2 commits into from May 31, 2023

Conversation

Bananeweizen
Copy link
Contributor

@Bananeweizen Bananeweizen commented May 14, 2023

See JENKINS-71244.

  • convert the relative link to an absolute one, since it might be used in different contexts
  • update all message bundles to use the new format argument

Note: To my mind, all relative URLs in properties files are a bad design choice, since the related code may be used from different context URLs. It would probably be rather easy to detect such issues with a regex checkstyle rule looking for href=". in properties files. If core maintainers agree, I could raise a separate issue for that.

Testing done

I've run a developer instance with this change. But I have not been able to force the update center error on my local machine. So Jenkins still runs, but the actual change is untested.

Proposed changelog entries

  • JENKINS-71244: Fix update center proxy configuration hyperlink in error messages

Proposed upgrade guidelines

N/A

Submitter checklist

  • The Jira issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples).
    • Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • New or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@NotMyFault NotMyFault added the bug For changelog: Minor bug. Will be listed after features label May 14, 2023
@NotMyFault NotMyFault requested a review from a team May 14, 2023 08:26
Copy link
Member

@NotMyFault NotMyFault 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 PR! I have tested issue described on the master branch via

diff --git a/core/src/main/java/hudson/model/UpdateCenter.java b/core/src/main/java/hudson/model/UpdateCenter.java
index b9ca1d2001..7fb5a2ce89 100644
--- a/core/src/main/java/hudson/model/UpdateCenter.java
+++ b/core/src/main/java/hudson/model/UpdateCenter.java
@@ -1680,6 +1680,7 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
 
                 connectionStates.put(ConnectionStatus.UPDATE_SITE, ConnectionStatus.CHECKING);
                 statuses.add(Messages.UpdateCenter_Status_CheckingJavaNet());
+                statuses.add(Messages.UpdateCenter_Status_UnknownHostException("yo"));
 
                 config.checkUpdateCenter(this, site.getUrl());
 

to replicate the problem the issue linked describes, without messing with networking.
The URL to the proxy configuration page is resolved properly:
Screenshot 2023-05-26 at 13 58 13
I'm not confident this PR addresses an actual issue, given I can't replicate the issue described.

@Bananeweizen
Copy link
Contributor Author

@NotMyFault I'm not exactly sure, but it looks like you are on the main page of the update center when trying to reproduce, right? If I remember it right from the issue, I was actually installing updates (i.e. my screenshot shows pluginManager/updates). Since that error message can appear on pages with different depth from the root, a fixed relative address (as before the patch) cannot work in all cases.

@NotMyFault
Copy link
Member

I was actually installing updates

I see, you were on /manage/pluginManager/updates/. On this view, I can replicate the issue with the patch I added above, on the master branch and verify the change proposed working.

I recommend removing the leading slash in the .properties files because Jenkins.get().getRootUrl() adds a trailing slash to all URLs creating a double slash: http://localhost:8085//manage/pluginManager/advanced

* convert the relative link to an absolute one, since it might be used
in different contexts (with different depth from the server root
directory)
* update all message bundles to use the new format argument
@Bananeweizen
Copy link
Contributor Author

I recommend removing the leading slash in the .properties files because Jenkins.get().getRootUrl() adds a trailing slash to all URLs creating a double slash: http://localhost:8085//manage/pluginManager/advanced

Done. I also like it when such things are cleaned up. :) And I'll have to remember your trick of not even fiddling with the network if it's easily possible to just trigger the error condition in (additional) code. Thanks for that.

I didn't rebase, assuming that simplifies your review and you'll probably rebase on submit anyway. Please tell me if that doesn't fit to typical Jenkins project workflows.

@NotMyFault
Copy link
Member

I didn't rebase, assuming that simplifies your review and you'll probably rebase on submit anyway. Please tell me if that doesn't fit to typical Jenkins project workflows.

No worries, all good. We don't do that during the review phase, given it detaches code comments, slows the time-to-merge down for no good reason, and generally causes more harm than good.
To maintain a clean history, PRs are squashed, typically.

@NotMyFault NotMyFault requested a review from a team May 27, 2023 17:53
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.

.

@timja
Copy link
Member

timja commented May 29, 2023

/label ready-for-merge


This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.

Thanks!

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label May 29, 2023
@NotMyFault NotMyFault merged commit 9061e7b into jenkinsci:master May 31, 2023
16 checks passed
@daniel-beck
Copy link
Member

This breaks links when the UI is not accessed through the configured root URL.

@NotMyFault
Copy link
Member

This breaks links when the UI is not accessed through the configured root URL.

Would you recommend a change independent of #getRootUrl?

@Bananeweizen Bananeweizen deleted the proxy_link branch June 1, 2023 13:29
krisstern pushed a commit to krisstern/jenkins that referenced this pull request Jun 7, 2023
* convert the relative link to an absolute one, since it might be used
in different contexts (with different depth from the server root
directory)
* update all message bundles to use the new format argument

Co-authored-by: Alexander Brandes <mc.cache@web.de>
(cherry picked from commit 9061e7b)
@daniel-beck
Copy link
Member

Would you recommend a change independent of #getRootUrl?

This should use Jenkins#getRootUrlFromRequest, or StaplerRequest#getContextPath (like the Jelly variable rootURL).

@daniel-beck
Copy link
Member

daniel-beck commented Aug 26, 2023

This should use Jenkins#getRootUrlFromRequest, or StaplerRequest#getContextPath (like the Jelly variable rootURL).

JENKINS-71905 documents the problem this change causes.

FTR using #getRootUrlFromRequest would also be incorrect, as the full error message is kinda persisted and not recomputed in every request. StaplerRequest#getContextPath may work though, as long as nobody is crazy enough to use different context paths depending on the domain.

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 ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
4 participants