Bladeren bron

Locate symbol endpoints with deeper paths (#249)

* Locate symbol endpoints with deeper paths

* Remove unnecessarily named return value

* Add test for deeper symbol path
Matt Joiner 7 jaren geleden
bovenliggende
commit
5f1b46005a
2 gewijzigde bestanden met toevoegingen van 14 en 16 verwijderingen
  1. 6
    9
      internal/symbolz/symbolz.go
  2. 8
    7
      internal/symbolz/symbolz_test.go

+ 6
- 9
internal/symbolz/symbolz.go Bestand weergeven

@@ -66,16 +66,13 @@ func Symbolize(p *profile.Profile, force bool, sources plugin.MappingSources, sy
66 66
 // symbolz returns the corresponding symbolz source for a profile URL.
67 67
 func symbolz(source string) string {
68 68
 	if url, err := url.Parse(source); err == nil && url.Host != "" {
69
-		if strings.Contains(url.Path, "/") {
70
-			if dir := path.Dir(url.Path); dir == "/debug/pprof" {
71
-				// For Go language profile handlers in net/http/pprof package.
72
-				url.Path = "/debug/pprof/symbol"
73
-			} else {
74
-				url.Path = "/symbolz"
75
-			}
76
-			url.RawQuery = ""
77
-			return url.String()
69
+		if strings.Contains(url.Path, "/debug/pprof/") {
70
+			url.Path = path.Clean(url.Path + "/../symbol")
71
+		} else {
72
+			url.Path = "/symbolz"
78 73
 		}
74
+		url.RawQuery = ""
75
+		return url.String()
79 76
 	}
80 77
 
81 78
 	return ""

+ 8
- 7
internal/symbolz/symbolz_test.go Bestand weergeven

@@ -26,13 +26,14 @@ import (
26 26
 
27 27
 func TestSymbolzURL(t *testing.T) {
28 28
 	for try, want := range map[string]string{
29
-		"http://host:8000/profilez":                        "http://host:8000/symbolz",
30
-		"http://host:8000/profilez?seconds=5":              "http://host:8000/symbolz",
31
-		"http://host:8000/profilez?seconds=5&format=proto": "http://host:8000/symbolz",
32
-		"http://host:8000/heapz?format=legacy":             "http://host:8000/symbolz",
33
-		"http://host:8000/debug/pprof/profile":             "http://host:8000/debug/pprof/symbol",
34
-		"http://host:8000/debug/pprof/profile?seconds=10":  "http://host:8000/debug/pprof/symbol",
35
-		"http://host:8000/debug/pprof/heap":                "http://host:8000/debug/pprof/symbol",
29
+		"http://host:8000/profilez":                                               "http://host:8000/symbolz",
30
+		"http://host:8000/profilez?seconds=5":                                     "http://host:8000/symbolz",
31
+		"http://host:8000/profilez?seconds=5&format=proto":                        "http://host:8000/symbolz",
32
+		"http://host:8000/heapz?format=legacy":                                    "http://host:8000/symbolz",
33
+		"http://host:8000/debug/pprof/profile":                                    "http://host:8000/debug/pprof/symbol",
34
+		"http://host:8000/debug/pprof/profile?seconds=10":                         "http://host:8000/debug/pprof/symbol",
35
+		"http://host:8000/debug/pprof/heap":                                       "http://host:8000/debug/pprof/symbol",
36
+		"http://some.host:8080/some/deeper/path/debug/pprof/endpoint?param=value": "http://some.host:8080/some/deeper/path/debug/pprof/symbol",
36 37
 	} {
37 38
 		if got := symbolz(try); got != want {
38 39
 			t.Errorf(`symbolz(%s)=%s, want "%s"`, try, got, want)