grafana / xk6-browser

The browser module adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol to k6.
https://grafana.com/docs/k6/latest/javascript-api/k6-browser/
GNU Affero General Public License v3.0
341 stars 42 forks source link

Filter out request metrics by their URL tag #1434

Open ankur22 opened 1 month ago

ankur22 commented 1 month ago

Feature Description

As mentioned in https://github.com/grafana/xk6-browser/issues/371, there could be a need to filter out metrics from requests with given urls which just create noise in the results. These could be requests that track user flow, adverts, or requests which aren't related to your team's ownership (if a website/page is split between multiple teams). These wouldn't be useful to see in the results and instead create noise.

Suggested Solution (optional)

  1. Implement page.route (https://github.com/grafana/xk6-browser/issues/10), to allow the user to add urls to intercept and abort, thus not recording metrics to do with that request. This would also prevent the request from being sent.
  2. Extend the functionality in page.on('metric') to allow for an ignore function, so that users can ignore metrics but still allow the request to complete e.g.:
    •  page.on('metric', metric => {
          // All metrics will not be recorded if the url tag matches the regex.
          metric.ignoreURLTag({
          urls: [
            {url: /^https:\/\/example\.com\/[0-9a-f]*\/checkout\/[0-9a-f]*$/},
            {url: /^https:\/\/example\.com\/catalogue\?session=[0-9a-f]*$/},
          ]});
       });

Other considerations

We should use the feature to ignore about:blank metrics!

Already existing or connected issues / PRs (optional)

Compliments https://github.com/grafana/xk6-browser/issues/371 Connected: https://github.com/grafana/xk6-browser/issues/10

andrewslotin commented 2 weeks ago

Can we filter out about:blank metrics by default once this is in place?

ankur22 commented 2 weeks ago

Can we filter out https://github.com/grafana/xk6-browser/issues/518 by default once this is in place?

Nice idea! Yes, we should do that 👍