Repository: google/pprof
Pull request #704 (2022-05-20 21:08:47)

Make config menu entries relative.
An earlier change had added support for placing pprof URLs under
the /ui prefix. However config menu entry URLs were built by
editing a URL produced by stripping the /ui prefix and were
therefore falling outside the /ui prefix. This ended up in
mis-navigation to the graph view when a config menu entry was
selected in another view.

Fixed by emitting a relative URL (e.g., ?f=foo) instead of an
absolute URL (e.g., /flamegraph?f=foo).

codecov-commenter: # [Codecov](https://codecov.io/gh/google/pprof/pull/704?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#704](https://codecov.io/gh/google/pprof/pull/704?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (4ae7136) into [master](https://codecov.io/gh/google/pprof/commit/33a8accb95cf726b21e3c2c60ba1215266f9b64d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (33a8acc) will **decrease** coverage by `0.00%`.
> The diff coverage is `n/a`.

```diff
@@            Coverage Diff             @@
##           master     #704      +/-   ##
==========================================
- Coverage   63.70%   63.69%   -0.01%     
==========================================
  Files          41       41              
  Lines        6488     6489       +1     
==========================================
  Hits         4133     4133              
- Misses       1913     1914       +1     
  Partials      442      442              
```


| [Impacted Files](https://codecov.io/gh/google/pprof/pull/704?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [.../github.com/google/pprof/internal/report/source.go](https://codecov.io/gh/google/pprof/pull/704/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-c3JjL2dpdGh1Yi5jb20vZ29vZ2xlL3Bwcm9mL2ludGVybmFsL3JlcG9ydC9zb3VyY2UuZ28=) | `80.23% <0.00%> (-0.20%)` | :arrow_down: |
| [...ithub.com/google/pprof/internal/driver/settings.go](https://codecov.io/gh/google/pprof/pull/704/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-c3JjL2dpdGh1Yi5jb20vZ29vZ2xlL3Bwcm9mL2ludGVybmFsL2RyaXZlci9zZXR0aW5ncy5nbw==) | `67.74% <0.00%> (+0.52%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/pprof/pull/704?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/pprof/pull/704?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Last update [33a8acc...4ae7136](https://codecov.io/gh/google/pprof/pull/704?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).


Patch:
diff --git a/internal/driver/settings.go b/internal/driver/settings.go
index f72314b..1e9154c 100644
--- a/internal/driver/settings.go
+++ b/internal/driver/settings.go
@@ -79,7 +79,7 @@ type configMenuEntry struct {
 }
 
 // configMenu returns a list of items to add to a menu in the web UI.
-func configMenu(fname string, url url.URL) []configMenuEntry {
+func configMenu(fname string, u url.URL) []configMenuEntry {
 	// Start with system configs.
 	configs := []namedConfig{{Name: "Default", config: defaultConfig()}}
 	if settings, err := readSettings(fname); err == nil {
@@ -91,13 +91,15 @@ func configMenu(fname string, url url.URL) []configMenuEntry {
 	result := make([]configMenuEntry, len(configs))
 	lastMatch := -1
 	for i, cfg := range configs {
-		dst, changed := cfg.config.makeURL(url)
+		dst, changed := cfg.config.makeURL(u)
 		if !changed {
 			lastMatch = i
 		}
+		// Use a relative URL to work in presence of stripping/redirects in webui.go.
+		rel := &url.URL{RawQuery: dst.RawQuery, ForceQuery: true}
 		result[i] = configMenuEntry{
 			Name:       cfg.Name,
-			URL:        dst.String(),
+			URL:        rel.String(),
 			UserConfig: (i != 0),
 		}
 	}


Test patch:
diff --git a/internal/driver/settings_test.go b/internal/driver/settings_test.go
index f87eb49..e0ea14c 100644
--- a/internal/driver/settings_test.go
+++ b/internal/driver/settings_test.go
@@ -135,9 +135,9 @@ func TestConfigMenu(t *testing.T) {
 	pageURL, _ := url.Parse("/top?f=foo")
 	menu := configMenu(fname, *pageURL)
 	want := []configMenuEntry{
-		{Name: "Default", URL: "/top", Current: false, UserConfig: false},
-		{Name: "A", URL: "/top?f=foo", Current: true, UserConfig: true},
-		{Name: "B", URL: "/top?f=bar", Current: false, UserConfig: true},
+		{Name: "Default", URL: "?", Current: false, UserConfig: false},
+		{Name: "A", URL: "?f=foo", Current: true, UserConfig: true},
+		{Name: "B", URL: "?f=bar", Current: false, UserConfig: true},
 	}
 	if !reflect.DeepEqual(menu, want) {
 		t.Errorf("ConfigMenu returned %v; want %v", menu, want)