| index cfc3bbde0..d9c9285d7 100644 |
| --- a/internal/console/perfwalk_test.go |
| +++ b/internal/console/perfwalk_test.go |
| @@ -4,6 +4,7 @@ import ( |
| "bufio" |
| "context" |
| "fmt" |
| + "html" |
| "io" |
| "log" |
| "net/http" |
| @@ -11,6 +12,7 @@ import ( |
| "net/url" |
| "os" |
| "path/filepath" |
| + "regexp" |
| "slices" |
| "strconv" |
| "strings" |
| @@ -753,7 +755,8 @@ func perfSessionCeiling(t *testing.T) (int64, string, bool) { |
| } |
| |
| // TestPerfSessionS3Requests is the whole-session count the warm walk |
| -// cannot give: first views, deferred loads and a write's own reads. On |
| +// cannot give: first views, deferred loads (the Logs tab's /logs/data |
| +// poll, which the walk exempts from its count) and a write's own reads. On |
| // newPerfFixture with latency off, signed in as Paul, it runs a fixed |
| // script and sums every S3 request the fake answers, with perfQuiesce |
| // after each step so background loads are included, and holds the total |
| @@ -788,17 +791,47 @@ func TestPerfSessionS3Requests(t *testing.T) { |
| t.Fatalf("%s answered %d, want %d:\n%s", what, status, want, body) |
| } |
| } |
| - view := func(p string) { |
| + view := func(p string) (body string) { |
| t.Helper() |
| step("GET "+p, func() (int, string) { |
| - status, _, body := get(t, c, fx.ts.URL+p) |
| + var status int |
| + status, _, body = get(t, c, fx.ts.URL+p) |
| return status, body |
| }) |
| + return body |
| } |
| app := fx.path("/apps/kass") |
| + // After each Logs view, one poll of its deferred part, /logs/data, made |
| + // as the page's script makes it: the filter form's values, limit=200, |
| + // and the page's cursor in place of since. |
| + logsPoll := func(page string) { |
| + t.Helper() |
| + u := app + "/logs/data?" + perfLogsPollQuery(t, page).Encode() |
| + step("GET "+u, func() (int, string) { |
| + req, err := http.NewRequest(http.MethodGet, fx.ts.URL+u, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req.Header.Set("Accept", "application/json") |
| + resp, err := c.Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer resp.Body.Close() |
| + body, _ := io.ReadAll(resp.Body) |
| + if resp.StatusCode == http.StatusOK && !strings.Contains(string(body), `"lines"`) { |
| + t.Fatalf("GET %s answered no lines:\n%s", u, body) |
| + } |
| + return resp.StatusCode, string(body) |
| + }) |
| + } |
| for _, tab := range []string{"", "/instances", "/deployments", "/releases", "/logs", "/errors", "/availability", "/analytics", "/activity"} { |
| - view(app + tab) |
| - view(app + tab) |
| + for range 2 { |
| + page := view(app + tab) |
| + if tab == "/logs" { |
| + logsPoll(page) |
| + } |
| + } |
| } |
| for _, s := range slices.Sorted(mapKeys(appSettingsSections)) { |
| view(app + "/settings/" + s) |
| @@ -829,3 +862,42 @@ func TestPerfSessionS3Requests(t *testing.T) { |
| t.Errorf("the scripted session made %d S3 requests, over the ceiling of %d in testdata/perf-session-s3.txt (%s)", total, ceiling, reason) |
| } |
| } |
| + |
| +var ( |
| + perfLogsCursor = regexp.MustCompile(`id="logs-filter"[^>]*data-cursor="([^"]*)"`) |
| + perfLogsSelect = regexp.MustCompile(`(?s)<select name="([a-z]+)">(.*?)</select>`) |
| + perfLogsOption = regexp.MustCompile(`<option value="([^"]*)"( selected)?>`) |
| +) |
| + |
| +// perfLogsPollQuery is the query the Logs page's script sends on its first |
| +// poll (app_logs.html): every filter select's value (the selected option, |
| +// or the first, as a browser submits it), limit=200, and, when the page |
| +// carries a cursor, that cursor with since and until dropped. |
| +func perfLogsPollQuery(t *testing.T, page string) url.Values { |
| + t.Helper() |
| + m := perfLogsCursor.FindStringSubmatch(page) |
| + if m == nil { |
| + t.Fatalf("the Logs page has no logs-filter form with a data-cursor:\n%s", page) |
| + } |
| + q := url.Values{} |
| + for _, sel := range perfLogsSelect.FindAllStringSubmatch(page, -1) { |
| + opts := perfLogsOption.FindAllStringSubmatch(sel[2], -1) |
| + if len(opts) == 0 { |
| + continue |
| + } |
| + v := opts[0][1] |
| + for _, o := range opts { |
| + if o[2] != "" { |
| + v = o[1] |
| + } |
| + } |
| + q.Set(sel[1], html.UnescapeString(v)) |
| + } |
| + q.Set("limit", "200") |
| + if cursor := html.UnescapeString(m[1]); cursor != "" { |
| + q.Set("cursor", cursor) |
| + q.Del("since") |
| + q.Del("until") |
| + } |
| + return q |
| +} |