Skip to content

Commit 2b63a53

Browse files
committed
k6browser: Add too many time series doc (0.55-v1)
1 parent c7326fa commit 2b63a53

File tree

7 files changed

+238
-17
lines changed

7 files changed

+238
-17
lines changed

docs/sources/k6/v0.55.x/using-k6-browser/recommended-practices/_index.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@ weight: 100
88

99
This section presents some examples and recommended practices when working with the `k6 browser` module to leverage browser automation as part of your k6 tests.
1010

11-
- [Hybrid approach to performance](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/hybrid-approach-to-performance)
12-
- [Page object model pattern](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/page-object-model-pattern)
13-
- [Selecting elements](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/selecting-elements)
14-
- [Simulate user input delay](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/simulate-user-input-delay)
15-
- [Preventing too many time series](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/preventing-too-many-time-series-issue)
11+
{{< section menuTitle="true">}}

docs/sources/k6/v0.56.x/using-k6-browser/recommended-practices/_index.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ weight: 100
88

99
This section presents some examples and recommended practices when working with the `k6 browser` module to leverage browser automation as part of your k6 tests.
1010

11-
- [Hybrid approach to performance](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/hybrid-approach-to-performance)
12-
- [Page object model pattern](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/page-object-model-pattern)
13-
- [Selecting elements](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/selecting-elements)
14-
- [Simulate user input delay](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/simulate-user-input-delay)
11+
{{< section menuTitle="true">}}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: 'Prevent too many time series error'
3+
description: 'A guide on how to prevent the `too many time series` issue when using k6 browser.'
4+
weight: 05
5+
---
6+
7+
# Preventing too many time series issue
8+
9+
Modern websites are complex and make a large number of requests to function as intended by their developers. These requests no longer serve only content for display to the end user but also retrieve insights, analytics, advertisements, and cache-busting purposes. Such requests are usually generated dynamically and may contain frequently changing IDs, posing challenges when correlating and analyzing your k6 test results.
10+
11+
When load testing a website using the k6 browser module, these dynamic requests can result in a high number of similar-looking requests, making it difficult to correlate them and extract valuable insights. This can also lead to test errors, such as a `too-many-metrics` error, due to high cardinality from metrics tagged with similar but dynamically changing URLs.
12+
13+
This issue also affects synthetic tests. While you may not encounter the _too-many-metrics_ error, you may end up with a large amount of uncorrelated metric data that cannot be tracked effectively over time.
14+
15+
To address this, the browser module has a [page.on('metric')](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/on) method, which allows you to define URL patterns using regex for matching. When a match is found, the URL and name tags for the metric are replaced with the new name.
16+
17+
## Example usage
18+
19+
{{< code >}}
20+
21+
<!-- eslint-skip-->
22+
23+
```javascript
24+
import { browser } from 'k6/browser';
25+
26+
export const options = {
27+
scenarios: {
28+
ui: {
29+
executor: 'shared-iterations',
30+
options: {
31+
browser: {
32+
type: 'chromium',
33+
},
34+
},
35+
},
36+
},
37+
}
38+
39+
export default async function() {
40+
const page = await browser.newPage();
41+
42+
// Here, we set up an event listener using page.on('metric').
43+
// You can call page.on('metric') multiple times, and each callback function
44+
// will be executed in the order that page.on was called.
45+
page.on('metric', (metric) => {
46+
// Currently, metric.tag is the only available method on the metric object.
47+
// It enables matching on the URL tag using a specified regex pattern.
48+
// You can call metric.tag multiple times within the callback function.
49+
metric.tag({
50+
// This is the new name assigned to any metric that matches the defined
51+
// URL pattern below.
52+
name: 'test',
53+
// Provide one or more match patterns here. Any metrics that match a pattern
54+
// will use the new name specified above.
55+
matches: [
56+
// Each match pattern can include a URL and an optional method.
57+
// When a method is specified, the metric must match both the URL pattern
58+
// and the method. If no method is provided, the pattern will match all
59+
// HTTP methods.
60+
{url: /^https:\/\/test\.k6\.io\/\?q=[0-9a-z]+$/, method: 'GET'},
61+
]
62+
});
63+
});
64+
65+
try {
66+
// The following lines are for demonstration purposes.
67+
// Visiting URLs with different query parameters (q) to illustrate matching.
68+
await page.goto('https://test.k6.io/?q=abc123');
69+
await page.goto('https://test.k6.io/?q=def456');
70+
} finally {
71+
// Ensure the page is closed after testing.
72+
await page.close();
73+
}
74+
}
75+
76+
```
77+
78+
{{< /code >}}

docs/sources/k6/v0.57.x/using-k6-browser/recommended-practices/_index.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ weight: 100
88

99
This section presents some examples and recommended practices when working with the `k6 browser` module to leverage browser automation as part of your k6 tests.
1010

11-
- [Hybrid approach to performance](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/hybrid-approach-to-performance)
12-
- [Page object model pattern](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/page-object-model-pattern)
13-
- [Selecting elements](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/selecting-elements)
14-
- [Simulate user input delay](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/simulate-user-input-delay)
11+
{{< section menuTitle="true">}}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: 'Prevent too many time series error'
3+
description: 'A guide on how to prevent the `too many time series` issue when using k6 browser.'
4+
weight: 05
5+
---
6+
7+
# Preventing too many time series issue
8+
9+
Modern websites are complex and make a large number of requests to function as intended by their developers. These requests no longer serve only content for display to the end user but also retrieve insights, analytics, advertisements, and cache-busting purposes. Such requests are usually generated dynamically and may contain frequently changing IDs, posing challenges when correlating and analyzing your k6 test results.
10+
11+
When load testing a website using the k6 browser module, these dynamic requests can result in a high number of similar-looking requests, making it difficult to correlate them and extract valuable insights. This can also lead to test errors, such as a `too-many-metrics` error, due to high cardinality from metrics tagged with similar but dynamically changing URLs.
12+
13+
This issue also affects synthetic tests. While you may not encounter the _too-many-metrics_ error, you may end up with a large amount of uncorrelated metric data that cannot be tracked effectively over time.
14+
15+
To address this, the browser module has a [page.on('metric')](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/on) method, which allows you to define URL patterns using regex for matching. When a match is found, the URL and name tags for the metric are replaced with the new name.
16+
17+
## Example usage
18+
19+
{{< code >}}
20+
21+
<!-- eslint-skip-->
22+
23+
```javascript
24+
import { browser } from 'k6/browser';
25+
26+
export const options = {
27+
scenarios: {
28+
ui: {
29+
executor: 'shared-iterations',
30+
options: {
31+
browser: {
32+
type: 'chromium',
33+
},
34+
},
35+
},
36+
},
37+
}
38+
39+
export default async function() {
40+
const page = await browser.newPage();
41+
42+
// Here, we set up an event listener using page.on('metric').
43+
// You can call page.on('metric') multiple times, and each callback function
44+
// will be executed in the order that page.on was called.
45+
page.on('metric', (metric) => {
46+
// Currently, metric.tag is the only available method on the metric object.
47+
// It enables matching on the URL tag using a specified regex pattern.
48+
// You can call metric.tag multiple times within the callback function.
49+
metric.tag({
50+
// This is the new name assigned to any metric that matches the defined
51+
// URL pattern below.
52+
name: 'test',
53+
// Provide one or more match patterns here. Any metrics that match a pattern
54+
// will use the new name specified above.
55+
matches: [
56+
// Each match pattern can include a URL and an optional method.
57+
// When a method is specified, the metric must match both the URL pattern
58+
// and the method. If no method is provided, the pattern will match all
59+
// HTTP methods.
60+
{url: /^https:\/\/test\.k6\.io\/\?q=[0-9a-z]+$/, method: 'GET'},
61+
]
62+
});
63+
});
64+
65+
try {
66+
// The following lines are for demonstration purposes.
67+
// Visiting URLs with different query parameters (q) to illustrate matching.
68+
await page.goto('https://test.k6.io/?q=abc123');
69+
await page.goto('https://test.k6.io/?q=def456');
70+
} finally {
71+
// Ensure the page is closed after testing.
72+
await page.close();
73+
}
74+
}
75+
76+
```
77+
78+
{{< /code >}}

docs/sources/k6/v1.0.x/using-k6-browser/recommended-practices/_index.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ weight: 100
88

99
This section presents some examples and recommended practices when working with the `k6 browser` module to leverage browser automation as part of your k6 tests.
1010

11-
- [Hybrid approach to performance](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/hybrid-approach-to-performance)
12-
- [Page object model pattern](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/page-object-model-pattern)
13-
- [Selecting elements](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/selecting-elements)
14-
- [Simulate user input delay](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/simulate-user-input-delay)
11+
{{< section menuTitle="true">}}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: 'Prevent too many time series error'
3+
description: 'A guide on how to prevent the `too many time series` issue when using k6 browser.'
4+
weight: 05
5+
---
6+
7+
# Preventing too many time series issue
8+
9+
Modern websites are complex and make a large number of requests to function as intended by their developers. These requests no longer serve only content for display to the end user but also retrieve insights, analytics, advertisements, and cache-busting purposes. Such requests are usually generated dynamically and may contain frequently changing IDs, posing challenges when correlating and analyzing your k6 test results.
10+
11+
When load testing a website using the k6 browser module, these dynamic requests can result in a high number of similar-looking requests, making it difficult to correlate them and extract valuable insights. This can also lead to test errors, such as a `too-many-metrics` error, due to high cardinality from metrics tagged with similar but dynamically changing URLs.
12+
13+
This issue also affects synthetic tests. While you may not encounter the _too-many-metrics_ error, you may end up with a large amount of uncorrelated metric data that cannot be tracked effectively over time.
14+
15+
To address this, the browser module has a [page.on('metric')](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/on) method, which allows you to define URL patterns using regex for matching. When a match is found, the URL and name tags for the metric are replaced with the new name.
16+
17+
## Example usage
18+
19+
{{< code >}}
20+
21+
<!-- eslint-skip-->
22+
23+
```javascript
24+
import { browser } from 'k6/browser';
25+
26+
export const options = {
27+
scenarios: {
28+
ui: {
29+
executor: 'shared-iterations',
30+
options: {
31+
browser: {
32+
type: 'chromium',
33+
},
34+
},
35+
},
36+
},
37+
}
38+
39+
export default async function() {
40+
const page = await browser.newPage();
41+
42+
// Here, we set up an event listener using page.on('metric').
43+
// You can call page.on('metric') multiple times, and each callback function
44+
// will be executed in the order that page.on was called.
45+
page.on('metric', (metric) => {
46+
// Currently, metric.tag is the only available method on the metric object.
47+
// It enables matching on the URL tag using a specified regex pattern.
48+
// You can call metric.tag multiple times within the callback function.
49+
metric.tag({
50+
// This is the new name assigned to any metric that matches the defined
51+
// URL pattern below.
52+
name: 'test',
53+
// Provide one or more match patterns here. Any metrics that match a pattern
54+
// will use the new name specified above.
55+
matches: [
56+
// Each match pattern can include a URL and an optional method.
57+
// When a method is specified, the metric must match both the URL pattern
58+
// and the method. If no method is provided, the pattern will match all
59+
// HTTP methods.
60+
{url: /^https:\/\/test\.k6\.io\/\?q=[0-9a-z]+$/, method: 'GET'},
61+
]
62+
});
63+
});
64+
65+
try {
66+
// The following lines are for demonstration purposes.
67+
// Visiting URLs with different query parameters (q) to illustrate matching.
68+
await page.goto('https://test.k6.io/?q=abc123');
69+
await page.goto('https://test.k6.io/?q=def456');
70+
} finally {
71+
// Ensure the page is closed after testing.
72+
await page.close();
73+
}
74+
}
75+
76+
```
77+
78+
{{< /code >}}

0 commit comments

Comments
 (0)