-
Notifications
You must be signed in to change notification settings - Fork 476
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
Fix the Route Prefix bug and add ExternalURL Support (#190) #239
Fix the Route Prefix bug and add ExternalURL Support (#190) #239
Conversation
Pass in the prefix to the Static handler such that it can be removed from the Path looked up to serve files relative to the FileSystem's root. Signed-off-by: Andrew G10z <[email protected]>
Signed-off-by: Andrew G10z <[email protected]>
df5afa7
to
ebf02f6
Compare
Signed-off-by: Andrew G10z <[email protected]>
This works in conjunction with the `--web.route-prefix` flag to provide resources at the provided external URL, with the properly munged `route-prefix`. If an external URL is provided, but a `route-prefix` is not, this change takes the external URL's Path and uses that as the `route-prefix`. Includes a simple test checking for the presence of a known external-url in the body of the Status handler. Signed-off-by: Andrew G10z <[email protected]>
@beorn7: This should be ready to take a look at when you have a chance. I did notice that the asset compilation doesn't work for repositories outside of the |
Many thanks, I'll have a look ASAP. |
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.
As far as I can see, this should do the right thing (but I have a lot of trouble myself each time I try to wrap my mind around this prefix business).
Just a few comments about details.
handler/misc_test.go
Outdated
@@ -0,0 +1,75 @@ | |||
// Copyright 2014 The Prometheus Authors |
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.
New files should have the current year in the Copyright line. (Not that it matters a lot, it's just what we try to adhere to.)
handler/status_test.go
Outdated
@@ -0,0 +1,52 @@ | |||
// Copyright 2014 The Prometheus Authors |
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.
As above: New files should have the current year in the Copyright line. (Not that it matters a lot, it's just what we try to adhere to.)
main.go
Outdated
@@ -49,6 +50,7 @@ func main() { | |||
|
|||
listenAddress = app.Flag("web.listen-address", "Address to listen on for the web interface, API, and telemetry.").Default(":9091").String() | |||
metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String() | |||
externalURL = app.Flag("web.external-url", "The URL under which Prometheus is externally reachable.").Default("").URL() |
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.
s/Prometheus/the Pushgateway/
main.go
Outdated
@@ -49,6 +50,7 @@ func main() { | |||
|
|||
listenAddress = app.Flag("web.listen-address", "Address to listen on for the web interface, API, and telemetry.").Default(":9091").String() | |||
metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String() | |||
externalURL = app.Flag("web.external-url", "The URL under which Prometheus is externally reachable.").Default("").URL() | |||
routePrefix = app.Flag("web.route-prefix", "Prefix for the internal routes of web endpoints.").Default("").String() |
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.
The doc string should then also be adjusted to the one from Prometheus, i.e.:
"Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url."
@@ -135,6 +135,25 @@ func handlePprof(w http.ResponseWriter, r *http.Request, p httprouter.Params) { | |||
} | |||
} | |||
|
|||
func computeRoutePrefix(prefix string, externalURL *url.URL) string { |
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.
The inline comments in this function are essentially just describing the (very simple) code and thus make it actually less readable. I guess the point you are trying to make is that this code implements the spec given by the flags. How about turning them into a doc comment before the function:
// computeRoutePrefix returns the effective route prefix based on the provided
// flag values for --web.route-prefix and--web.external-url. With prefix empty,
// the path of externalURL is used instead. A prefix "/" results in an empty
// returned prefix. Any non-empty prefix is normalized to start, but not to end,
// with "/".
handler/status.go
Outdated
@@ -65,6 +67,14 @@ func Status( | |||
"value": func(f float64) string { | |||
return strconv.FormatFloat(f, 'f', -1, 64) | |||
}, | |||
"join": func(base string, paths ...string) string { |
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.
Instead of passing in a whole new function, wouldn't it be easier to just pass in the pre-calculated complete string to prefix URLs in the template with? The function is always called in the same way in the template.
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 can do that. The general purpose function is useful for future uses, but those uses don't currently exist, and are unlikely to be drastically different I'm guessing.
Oh boy. Some of these things are silly (copyright notice). I'll fix 'em up. |
Signed-off-by: Andrew G10z <[email protected]>
Signed-off-by: Andrew G10z <[email protected]>
8b07fb8
to
0f0cc1f
Compare
Signed-off-by: Andrew G10z <[email protected]>
ed25c35
to
e747fea
Compare
OK, BaseURL is precomputed before template render. |
Many thanks. Let's hope this really fixes the issue for good. |
Have we stopped trying to release this fix? Would love this functionality but it seems the latest release was in December 2018. |
A releases will happen soon. For this particular feature, I would really like to see it being tried out a bit by early adopters, who build from the tip of master. @nodox would be great if you volunteered. |
Building from master might be too involved from me. However if you create a docker image with the changes in master you've got yourself a beta tester. You can add an alpha/beta tag or whatever tage makes sense. Right now I'm trying to make this work using the Prometheus Helm chart on a Kubernetes. @beorn7 |
Thank you,
REST API also successfully receiving POSTs on When i've tried with |
Thanks @sepich . I'll have a look ASAP. |
For me, both Prometheus and PGW panic if I set
I think rejecting it is the right thing as @sepich did you manage to avoid the panic somehow? |
Ups, sorry for the typo. Yes, the |
I see. I'll try and fix. |
#244 should fix it. |
This fixes #190, I believe.
I've gotta figure out how to add in the
--web.external-url
with the same semantics as prometheus still. But, this should address the route-prefix issue as it stands right now.Happy to address the externalURL in another PR entirely, in which case this wouldn't be work in progress anymore, and would be ready for review.