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

[ADDED] base path for monitoring endpoints #1392

Merged
merged 1 commit into from
May 13, 2020

Conversation

guilherme-santos
Copy link
Contributor

@guilherme-santos guilherme-santos commented May 13, 2020

  • Link to issue, e.g. Resolves #NNN
  • Documentation added (if applicable)
  • Tests added
  • Branch rebased on top of current master (git pull --rebase origin master)
  • Changes squashed to a single commit (described here)
  • Build is green in Travis CI
  • You have certified that the contribution is your original work and that you license the work to the project under the Apache 2 license

Resolves #

Changes proposed in this pull request:

  • Add flag http_base_path to be able to access nats monitoring endpoint behind a proxy (e.g. nginx)

/cc @nats-io/core

Copy link
Member

@derekcollison derekcollison left a 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)
Copy link
Member

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?

Copy link
Member

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 {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

@kozlovic kozlovic left a 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.

server/monitor.go Outdated Show resolved Hide resolved
@@ -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 {
Copy link
Member

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.

server/opts.go Outdated Show resolved Hide resolved
@@ -1566,6 +1569,10 @@ const (
StackszPath = "/stacksz"
)

func (s *Server) basePath(p string) string {
return path.Join(s.httpBasePath, p)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment than above.

main.go Outdated Show resolved Hide resolved
Copy link
Member

@kozlovic kozlovic left a 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?

@@ -6,6 +6,8 @@ listen: 127.0.0.1:4242

http: 8222

base_path: /nats
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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 = "/"
Copy link
Member

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":
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@matthiashanel
Copy link
Contributor

@guilherme-santos the failure you are seeing has nothing to do with this change.
As for the review I am good if Ivan is good.

Copy link
Member

@kozlovic kozlovic left a 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!

@kozlovic kozlovic changed the title Implement basePath for monitoring endpoints [ADDED] base path for monitoring endpoints May 13, 2020
@kozlovic kozlovic merged commit 54e0140 into nats-io:master May 13, 2020
kozlovic added a commit to nats-io/nats.docs that referenced this pull request Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants