-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL Grouping/Aggregation #371
Comments
As mentioned over Slack, support for k6's That said, we'll still have to implement URL grouping by Using regex for this would be the more flexible option, but sticking with globbing patterns like with If we want to use the global |
Hmm, I don't have a very strong opinion here, but I'd prefer if we can avoid doing this via a new global option, at least until we have a clear idea of how to implement that optimally... 🤔 Global options are always a heavy maintenance burden over time and they are often not flexible enough to address all use cases. In some cases they are unavoidable, but in general I think we've found that programmable APIs are both easier to maintain and more flexible. In this case, maybe a new callback to the |
Sorry! I somehow missed responding to this one 😞 I thought it could be interesting to have an automatic way of doing this. After all, we have the metrics data and all the URLs in k6! (at least for some time). Maybe we could have the option to aggregate "high cardinality data" that would check the latest URLs and remove the highly changing part (and replace it with id_X or something). There is a "similar" feature in Grafana that lets you dedup Loki logs based on the signature. |
Internally, if I remember correctly, we had something similar for Prometheus metrics labels, too (In Python). |
After some discussions we want to showcase the following API that will soon be available to allow grouping of metrics which are tagged with Here's the API (some details may slightly change): export default async function() {
const context = await browser.newContext();
const page = await context.newPage();
// Register a callback on the page object to be executed whenever a
// metric is about to be emitted: offering the user the ability to build
// their own logic and grouping of URLs.
page.on('metric', metric => {
let regex = /^https:\/\/example\.com\/checkout\/[0-9a-f]*$/;
// Grouping all browser metrics that contain the url tag which match the
// regex with the name "example-checkout", which would allow the customer to
// build a graph by querying for "shop-checkout".
if (regex.test(metric.tags['url'])) {
metric.tags['url']["name"] = 'example-checkout'
}
});
await page.goto('https://example.com');
await page.close();
} The new API extends the NOTE: This will only intercept metrics that the browser module emits, which currently are:
We also hope to offer an easier to use helper function on page.on('metric', metric => {
metric.groupURLTag({
urls: [
{url: /^https:\/\/example\.com\/[0-9a-f]*\/checkout\/[0-9a-f]*$/, name:"account-basket"},
{url: /^https:\/\/example\.com\/catalogue\?session=[0-9a-f]*$/, name:"catalogue"},
]});
}); |
Jumping in here from the k8s monitoring team, we would be very interested in this! |
While implementing this feature, I've had to change it ever so slightly, which is to not expose the metric internals and allow the user to amend them. Instead the focus is only on the |
The final API looks like this: page.on('metric', (metric) => {
metric.Tag({
urls: [
{url: /^https:\/\/test\.k6\.io\/\?q=[0-9a-z]+$/, name:'test'},
]
});
}); There's an example you can work with to get you off your feet (remember to change the import to |
It is often useful to aggregate endpoint URLs that contain dynamic values. This is critical in the k6 Cloud due to the limits we have in place to prevent tests from emitting
too-many-metrics
/too-many-urls
.The URL Grouping documentation provides a solution for k6 scripts using the
http
module, but becausexk6-browser
operates at the browser-level, there is no opportunity for the user to apply thename
tag to requests that require it.The situation is compounded by the fact that
xk6-browser
gains visibility of all HTTP requests incurred by the browser, including 3rd party hosts that would not normally be interacted with at all using HTTP k6 scripts.Potential solutions
Allowlist/blocklist hosts in xk6-browser
A cursory browse through Playwright docs suggests there is no convenient way of preventing/allowing requests to certain hosts, e.g. through specifying regular expressions. There is, however, a request interception mechanism involving Page.route or BrowserContext.route that could be used to abort requests that don't fit the criteria.
Pros:
Cons:
Allowlist/blocklist hosts after-the-fact
This means xk6-browser still sends requests to the additional hosts, but that traffic can be filtered out of results.
Pros:
Cons:
Aggregation Rules
This would involve the user specifying URL grouping regular expressions (likely in
options
) ahead of time. Before any metric is generated, we check if the URL matches any of the patterns and apply the transformation as necessary.Example:
Pros:
name
http
andxk6-browser
name
tag to the request that initiates the redirect chain, but then all requests in that chain end up with the samename
tag)Cons:
Tasks
The text was updated successfully, but these errors were encountered: