Repository navigation
Keep the path prefix of Alertmanager and Prometheus URLs - #799
Merged
vincent-olivert-riera merged 1 commit intoOct 19, 2026
Merged
Conversation
vincent-olivert-riera
requested changes
Oct 16, 2026
vincent-olivert-riera
left a comment
Contributor
There was a problem hiding this comment.
Thanks for your contribution.
Please check the review comments, thanks!
Contributor
Author
|
Thanks for the review! I've applied all three suggestions in d16438a: switched |
Contributor
@MankhongGarden, thanks. Please squash the fixup commit and rebase your branch on master before we can merge it. |
urllib.parse.urljoin drops the path of the base URL when the second argument starts with "/", so a Prometheus or Alertmanager served under a path prefix (e.g. http://example.com/prometheus/) was called without the prefix. Add util.join_url and use it for the Alertmanager, Prometheus and proxy shard URLs. Fixes line#225
MankhongGarden
force-pushed
the
fix/urljoin-base-path
branch
from
October 19, 2026 02:17
d16438a to
7b8dad7
Compare
Contributor
Author
|
Done, squashed into a single commit and rebased onto the latest master (7b8dad7). Thanks! |
vincent-olivert-riera
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #225
What
Promgen builds Alertmanager and Prometheus URLs with
urllib.parse.urljoin(base, "/api/..."). When the second argument starts with/,urljoinreplaces the whole path of the base URL, so a server running under a path prefix loses it:So with
alertmanager.url: http://example.com/alertmanager/(a common setup behind a reverse proxy, or Alertmanager started with--web.route-prefix), creating, listing and deleting silences and fetching alerts all call the wrong URL. The same happens toprometheus.url(/-/reload,clean_tombstones) and to the shard URLs used by the query proxy (/api/v1/query,/api/v1/labels, ...).rest.pyalready builds the shard query URL asf"{shard.url}/api/v1/query", which keeps the prefix, so the behaviour was also inconsistent between endpoints.Change (6 files, +68/-10)
promgen/util.py: addjoin_url(base, path), which appends the path to the base URL and keeps its prefix (base.rstrip("/") + "/" + path.lstrip("/")).promgen/prometheus.py,promgen/proxy.py,promgen/tasks.py: useutil.join_urlat the 7 places that usedurljoinwith an absolute path (Alertmanager silences/alerts, Prometheus reload and clean_tombstones, proxy shard requests). The unusedurljoinimports are removed.test_util.test_join_urlcovers base URLs with and without a prefix and trailing slash, and a path with a query string.test_silence.test_alertmanager_url_with_path_prefixposts a silence withalertmanager.urlset tohttp://example.com/alertmanager/and checks the request goes to.../alertmanager/api/v2/silences.Why this approach
urljoin(base, "api/v2/silences")): only works when the configured URL ends with/.http://example.com/alertmanagerwould still dropalertmanager.rest.pydoes: works, but duplicates the trailing-slash handling 7 times.http://alertmanager:9093) is unchanged, so existing setups are not affected.Testing
master(request goes tohttp://example.com/api/v2/silences) and passes with this change.promgen test: no new failures compared withmaster.ruff check promgenandruff format --diff promgen(ruff 0.14.14, as in the Makefile): clean.promgen checkandpromgen makemigrations --check: no changes.Scope
Only URL building is changed. It does not depend on any other open issue or PR.