cmd/tailscale, ipn/localapi: add "tailscale bugreport" subcommand

Adding a subcommand which prints and logs a log marker. This should help
diagnose any issues that users face.

Fixes #1466

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2021-03-30 15:59:44 -07:00
committed by Maisem Ali
parent 09148c07ba
commit db13b2d0c8
5 changed files with 101 additions and 8 deletions
+23
View File
@@ -16,6 +16,7 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"tailscale.com/ipn/ipnstate"
"tailscale.com/paths"
@@ -109,6 +110,28 @@ func Goroutines(ctx context.Context) ([]byte, error) {
return body, nil
}
// BugReport logs and returns a log marker that can be shared by the user with support.
func BugReport(ctx context.Context, note string) (string, error) {
u := fmt.Sprintf("http://local-tailscaled.sock/localapi/v0/bugreport?note=%s", url.QueryEscape(note))
req, err := http.NewRequestWithContext(ctx, "POST", u, nil)
if err != nil {
return "", err
}
res, err := DoLocalRequest(req)
if err != nil {
return "", err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return "", err
}
if res.StatusCode != 200 {
return "", fmt.Errorf("HTTP %s: %s", res.Status, body)
}
return strings.TrimSpace(string(body)), nil
}
// Status returns the Tailscale daemon's status.
func Status(ctx context.Context) (*ipnstate.Status, error) {
return status(ctx, "")