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

[vtadmin] Add debug endpoints #8268

Merged
merged 2 commits into from
Jun 7, 2021
Merged

Conversation

ajm188
Copy link
Contributor

@ajm188 ajm188 commented Jun 6, 2021

Description

This adds debug endpoints to vtadmin-api, namely the /debug/pprof/ friends, and also a /debug/env to show environment variables available to the vtadmin-api process.

net/http/pprof was being stubborn about how to get it to play nicely with gorilla/mux, but I managed to get it working, unfortunately at the cost of making the route registration a bit more confusing.

We also add some config options to opt users out of debug endpoints entirely, as well as to control the behavior of the /debug/env endpoint to sanitize, or omit entirely, any environment variables that may be sensitive.

Examples!

No changes to flags:
❯ curl -s localhost:14200/debug/env | grep CDPATH
CDPATH=:/Users/amason/work:/Users/amason/work
Adding sanitization:
diff --git a/examples/local/scripts/vtadmin-up.sh b/examples/local/scripts/vtadmin-up.sh
index e76a920618..4ceeee7b5d 100755
--- a/examples/local/scripts/vtadmin-up.sh
+++ b/examples/local/scripts/vtadmin-up.sh
@@ -9,6 +9,7 @@ vtadmin \
   --addr ":${vtadmin_api_port}" \
   --http-origin "http://localhost:3000" \
   --http-tablet-url-tmpl "http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \
+  --http-debug-sanitize-env "CDPATH" \
   --tracer "opentracing-jaeger" \
   --grpc-tracing \
   --http-tracing \
❯ curl -s localhost:14200/debug/env | grep CDPATH
CDPATH=********
Adding omission:
diff --git a/examples/local/scripts/vtadmin-up.sh b/examples/local/scripts/vtadmin-up.sh
index e76a920618..3172d4ddd6 100755
--- a/examples/local/scripts/vtadmin-up.sh
+++ b/examples/local/scripts/vtadmin-up.sh
@@ -9,6 +9,7 @@ vtadmin \
   --addr ":${vtadmin_api_port}" \
   --http-origin "http://localhost:3000" \
   --http-tablet-url-tmpl "http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \
+  --http-debug-omit-env "CDPATH" \
   --tracer "opentracing-jaeger" \
   --grpc-tracing \
   --http-tracing \
❯ curl -s localhost:14200/debug/env | grep -c CDPATH
0
Disabling entirely:
diff --git a/examples/local/scripts/vtadmin-up.sh b/examples/local/scripts/vtadmin-up.sh
index e76a920618..221006c4a4 100755
--- a/examples/local/scripts/vtadmin-up.sh
+++ b/examples/local/scripts/vtadmin-up.sh
@@ -9,6 +9,7 @@ vtadmin \
   --addr ":${vtadmin_api_port}" \
   --http-origin "http://localhost:3000" \
   --http-tablet-url-tmpl "http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \
+  --http-no-debug \
   --tracer "opentracing-jaeger" \
   --grpc-tracing \
   --http-tracing \
❯ curl localhost:14200/debug/env
404 page not found

I also poked around in the pprof endpoints and took some profiles.

Related Issue(s)

Closes #8267

Checklist

  • Tests were added or are not required - n/a
  • Documentation was added or is not required

Deployment Notes

Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
@ajm188 ajm188 added this to In progress in VTAdmin via automation Jun 6, 2021
@ajm188 ajm188 marked this pull request as ready for review June 6, 2021 12:10
Copy link
Contributor

@doeg doeg left a comment

Choose a reason for hiding this comment

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

I don't know much about pprof, but from a Go standpoint this looks great!


// Sort by env var name, ascending.
sort.SliceStable(vars, func(i, j int) bool {
left, right := vars[i], vars[j]
Copy link
Contributor

Choose a reason for hiding this comment

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

(Goodfellas voice) One's going left, the other's going right, so what?

@ajm188 ajm188 merged commit c489dc0 into vitessio:main Jun 7, 2021
VTAdmin automation moved this from In progress to Done Jun 7, 2021
@ajm188 ajm188 deleted the am_vtadmin_debug branch June 7, 2021 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

[vtadmin-api] Add debug endpoints
2 participants