Ver código fonte

Change URL matching code to restore compatibility with old pprof (#276) (#278)

Change URL matching code to restore compatibility with old pprof (#276)
Erwan Legrand 7 anos atrás
pai
commit
9cd381157e
2 arquivos alterados com 31 adições e 1 exclusões
  1. 20
    1
      internal/symbolz/symbolz.go
  2. 11
    0
      internal/symbolz/symbolz_test.go

+ 20
- 1
internal/symbolz/symbolz.go Ver arquivo

@@ -63,10 +63,29 @@ func Symbolize(p *profile.Profile, force bool, sources plugin.MappingSources, sy
63 63
 	return nil
64 64
 }
65 65
 
66
+// Check whether path ends with one of the suffixes listed in
67
+// pprof_remote_servers.html from the gperftools distribution
68
+func hasGperftoolsSuffix(path string) bool {
69
+	suffixes := []string{
70
+		"/pprof/heap",
71
+		"/pprof/growth",
72
+		"/pprof/profile",
73
+		"/pprof/pmuprofile",
74
+		"/pprof/contention",
75
+	}
76
+	for _, s := range suffixes {
77
+		if strings.HasSuffix(path, s) {
78
+			return true
79
+		}
80
+	}
81
+	return false
82
+}
83
+
66 84
 // symbolz returns the corresponding symbolz source for a profile URL.
67 85
 func symbolz(source string) string {
68 86
 	if url, err := url.Parse(source); err == nil && url.Host != "" {
69
-		if strings.Contains(url.Path, "/debug/pprof/") {
87
+		// All paths in the net/http/pprof Go package contain /debug/pprof/
88
+		if strings.Contains(url.Path, "/debug/pprof/") || hasGperftoolsSuffix(url.Path) {
70 89
 			url.Path = path.Clean(url.Path + "/../symbol")
71 90
 		} else {
72 91
 			url.Path = "/symbolz"

+ 11
- 0
internal/symbolz/symbolz_test.go Ver arquivo

@@ -34,6 +34,17 @@ func TestSymbolzURL(t *testing.T) {
34 34
 		"http://host:8000/debug/pprof/profile?seconds=10":                         "http://host:8000/debug/pprof/symbol",
35 35
 		"http://host:8000/debug/pprof/heap":                                       "http://host:8000/debug/pprof/symbol",
36 36
 		"http://some.host:8080/some/deeper/path/debug/pprof/endpoint?param=value": "http://some.host:8080/some/deeper/path/debug/pprof/symbol",
37
+		"http://host:8000/pprof/profile":                                          "http://host:8000/pprof/symbol",
38
+		"http://host:8000/pprof/profile?seconds=15":                               "http://host:8000/pprof/symbol",
39
+		"http://host:8000/pprof/heap":                                             "http://host:8000/pprof/symbol",
40
+		"http://host:8000/debug/pprof/block":                                      "http://host:8000/debug/pprof/symbol",
41
+		"http://host:8000/debug/pprof/trace?seconds=5":                            "http://host:8000/debug/pprof/symbol",
42
+		"http://host:8000/debug/pprof/mutex":                                      "http://host:8000/debug/pprof/symbol",
43
+		"http://host/whatever/pprof/heap":                                         "http://host/whatever/pprof/symbol",
44
+		"http://host/whatever/pprof/growth":                                       "http://host/whatever/pprof/symbol",
45
+		"http://host/whatever/pprof/profile":                                      "http://host/whatever/pprof/symbol",
46
+		"http://host/whatever/pprof/pmuprofile":                                   "http://host/whatever/pprof/symbol",
47
+		"http://host/whatever/pprof/contention":                                   "http://host/whatever/pprof/symbol",
37 48
 	} {
38 49
 		if got := symbolz(try); got != want {
39 50
 			t.Errorf(`symbolz(%s)=%s, want "%s"`, try, got, want)