-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[ADDED] base path for monitoring endpoints #1392
Conversation
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.
In general I think this looks good. Couple of questions on locking. Will let @kozlovic or @matthiashanel take a look as well and sign off.
Thanks!
@@ -1566,6 +1569,10 @@ const ( | |||
StackszPath = "/stacksz" | |||
) | |||
|
|||
func (s *Server) basePath(p string) string { | |||
return path.Join(s.httpBasePath, p) |
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.
Does this need the server lock?
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.
Same comment than above.
@@ -1081,7 +1082,7 @@ func myUptime(d time.Duration) string { | |||
// HandleRoot will show basic info and links to others handlers. | |||
func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) { | |||
// This feels dumb to me, but is required: https://code.google.com/p/go/issues/detail?id=4799 | |||
if r.URL.Path != "/" { | |||
if r.URL.Path != s.httpBasePath { |
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.
May have to protect here with a lock.
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 don't think we need because this is immutable. It is set when the server object is created and since it is not added to things that can be reloaded, then it should be fine. But we could protect for the future indeed.
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.
Thank you, very thorough PR!
I am wondering if base_path really need to be added to varz output, and if we need the option in the command line. If we do, you have some changes to do.
As for the locking, I think it is fine right now, but we could certainly use the protection for the future.
@@ -1081,7 +1082,7 @@ func myUptime(d time.Duration) string { | |||
// HandleRoot will show basic info and links to others handlers. | |||
func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) { | |||
// This feels dumb to me, but is required: https://code.google.com/p/go/issues/detail?id=4799 | |||
if r.URL.Path != "/" { | |||
if r.URL.Path != s.httpBasePath { |
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 don't think we need because this is immutable. It is set when the server object is created and since it is not added to things that can be reloaded, then it should be fine. But we could protect for the future indeed.
@@ -1566,6 +1569,10 @@ const ( | |||
StackszPath = "/stacksz" | |||
) | |||
|
|||
func (s *Server) basePath(p string) string { | |||
return path.Join(s.httpBasePath, p) |
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.
Same comment than above.
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.
Not a blocker, just wondering if we should rename the Option, config name, etc.. with starting with http to make it clear this is related to the http(s) monitoring endpoints?
server/configs/test.conf
Outdated
@@ -6,6 +6,8 @@ listen: 127.0.0.1:4242 | |||
|
|||
http: 8222 | |||
|
|||
base_path: /nats |
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.
Sorry to notice that now, but should we call it http_base_path
or http_root
or something like that but with leading http_
to make it clear that this is a http option?
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.
Good you mentioned, because I was also struggling with that, I was not really sure.
I kind of started with http_
because the monitoring part starts with http_
. But then I started to notice that you have other http handlers (like profiling), that my base path doesn't include them, in the end I decided to remove the prefix.
I'd use http_base_path
other than http_root
because I think it's more common in other projects.
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.
Let's go with http_base_path
and HTTPBasePath for option, etc..
server/const.go
Outdated
@@ -97,6 +97,9 @@ const ( | |||
// DEFAULT_HTTP_PORT is the default monitoring port. | |||
DEFAULT_HTTP_PORT = 8222 | |||
|
|||
// DEFAULT_BASE_PATH is the default base path for monitoring. | |||
DEFAULT_BASE_PATH = "/" |
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.
If we agree on the http naming, you could also have this be DEFAULT_HTTP_xxx
server/opts.go
Outdated
@@ -593,6 +595,8 @@ func (o *Options) processConfigFileLine(k string, v interface{}, errors *[]error | |||
o.HTTPPort = int(v.(int64)) | |||
case "https_port": | |||
o.HTTPSPort = int(v.(int64)) | |||
case "base_path": |
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.
You can have both, we sometimes do that. For instance:
case "http_base_path", "base_path":
..
to support multiple config names.
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'd keep only http_base_path
as we don't really need to be compatible with anything.
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.
Let's go with that and renaming of option, etc.. Will review again when the PR is updated.
@guilherme-santos the failure you are seeing has nothing to do with this change. |
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.
LGTM. Thanks for your contribution!
Related to nats-io/nats-server#1392.
Resolves #NNN
git pull --rebase origin master
)Resolves #
Changes proposed in this pull request:
http_base_path
to be able to access nats monitoring endpoint behind a proxy (e.g. nginx)/cc @nats-io/core