Skip to content

Commit f427433

Browse files
ppcanocodebien
andauthored
Update Prometheus Remove Write docs (#1085)
* Update Prometheus Remove Write docs * Update src/data/markdown/translated-guides/en/03 Results output/200 Real-time/00 Prometheus remote write.md Co-authored-by: Ivan <[email protected]> * Update src/data/markdown/translated-guides/en/03 Results output/200 Real-time/00 Prometheus remote write.md Co-authored-by: Ivan <[email protected]> * Update src/data/markdown/translated-guides/en/03 Results output/200 Real-time/00 Prometheus remote write.md Co-authored-by: Ivan <[email protected]> * Update src/data/markdown/translated-guides/en/03 Results output/200 Real-time/00 Prometheus remote write.md Co-authored-by: Ivan <[email protected]> * Fix typo * Reorder `Prometheus Native histogram` section * Complete Prometheus RW update * Fix spelling * minor edit * minor edit * Update src/data/markdown/translated-guides/en/03 Results output/200 Real-time/00 Prometheus remote write.md Co-authored-by: Ivan <[email protected]> * Address Ivan suggestions --------- Co-authored-by: Ivan <[email protected]>
1 parent ade95ef commit f427433

File tree

1 file changed

+110
-68
lines changed

1 file changed

+110
-68
lines changed

src/data/markdown/translated-guides/en/03 Results output/200 Real-time/00 Prometheus remote write.md

Lines changed: 110 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@ excerpt: 'Use the Prometheus remote write output to send test results to any Pro
55

66
<ExperimentalBlockquote />
77

8+
<Blockquote mod="note" title="">
9+
10+
If you want to export cloud results to remote write,
11+
refer to [Cloud to Prometheus RW](/cloud/integrations/prometheus-remote-write/).
12+
13+
</Blockquote>
14+
815
Prometheus remote write is a protocol that makes it possible to reliably propagate data in real-time from a sender to a receiver.
916
It has a defined [specification](https://docs.google.com/document/d/1LPhVRSFkGNSuU1fBd81ulhsCPR4hkSZyyBj1SZ8fWOM/edit)
1017
and multiple implementations.
1118
For example, you can store the metrics in [Prometheus](https://prometheus.io/docs/prometheus/latest/feature_flags/#remote-write-receiver).
1219
For other implementations, check the [Prometheus Integrations](https://prometheus.io/docs/operating/integrations) guide.
1320

1421
With the Prometheus remote write output, k6 can send test-result metrics to a Prometheus remote write endpoint.
15-
The output during the `k6 run` execution gets all the generated data points for the [built-in k6 metrics](/using-k6/metrics/).
22+
The output during the `k6 run` execution gets all the generated data points for the [built-in and custom metrics](/using-k6/metrics/).
1623
It then generates the equivalent Prometheus remote write time series.
1724

18-
<Blockquote mod="note" title="">
19-
20-
If you want to export cloud results to remote write,
21-
refer to [Cloud to Prometheus RW](/cloud/integrations/prometheus-remote-write/).
22-
23-
</Blockquote>
2425

25-
## About metrics mapping
26+
## Metrics mapping
2627

2728
All k6 metric types are converted into an equivalent Prometheus remote write type:
2829

@@ -31,108 +32,149 @@ All k6 metric types are converted into an equivalent Prometheus remote write typ
3132
| Counter | Counter | `k6_*_total` |
3233
| Gauge | Gauge | `k6_*_<unit-suffix>` |
3334
| Rate | Gauge | `k6_*_rate` |
34-
| Trend | Gauges / Native Histogram | `k6_*_<unit-suffix>` |
35+
| Trend | [Counter and Gauges (default)](#counter-and-gauges) or [Native Histogram](#prometheus-native-histogram) | `k6_*_<unit-suffix>` |
36+
37+
The output maps the metrics into time series with Name labels.
38+
As much as possible, k6 respects the [naming best practices](https://prometheus.io/docs/practices/naming) that the Prometheus project defines:
39+
40+
* All time series are prefixed with the `k6_` namespace.
41+
* All time series are suffixed with the base unit of the sample value (if k6 knows what the base unit is).
42+
* Trends and rates have the relative suffixes, to make them more discoverable.
3543

36-
### Trend metric conversion
44+
## Trend metric conversions
3745

38-
By default, k6 trend metrics convert to primitive counters and gauges.
39-
To convert trend metrics to high-fidelity histograms, you can use Prometheus Native histogram instead.
46+
This output provides two distinct mechanisms to send [Trend metrics](/using-k6/metrics/) to Prometheus:
4047

41-
Because k6 can't easily determine fixed buckets in advance, k6 metrics can't export to the original Prometheus histograms.
42-
So, the output maps a trend metric into primitive counter and gauges.
43-
Each value represents a math function (count, sum, min, max, avg, med, p(x)).
44-
This mapping has following drawbacks:
48+
1. [Counter and Gauge metrics](#counter-and-gauges) (default)
49+
2. [Prometheus Native histogram](#prometheus-native-histogram)
50+
51+
Both options provide efficient storage of test results while providing high-precision queries.
52+
53+
Note that k6 aggregates trend metric data before sending it to Prometheus in both options. The reasons for aggregating data are:
54+
55+
- Prometheus stores data in a millisecond precision (`ms`), but k6 metrics collect data points with higher accuracy, nanosecond (`ns`).
56+
- A load test could generate vast amounts of data points. High-precision raw data could quickly become expensive and complex to scale and is unnecessary when analyzing performance trends.
57+
58+
### Counter and Gauges
59+
60+
By default, Prometheus supports [Counter and Gauge Metric types](https://prometheus.io/docs/concepts/metric_types/). Therefore, this option is the default of this output and converts all the k6 `Trend` metrics to Counter and Gauges Prometheus metrics.
61+
62+
You can configure how to convert all the k6 trend metrics with the [`K6_PROMETHEUS_RW_TREND_STATS` option](#options) that accepts a comma-separated list of stats functions: `count`, `sum`, `min`, `max`, `avg`, `med`, `p(x)`.
63+
64+
65+
Given the list of stats functions, k6 converts all trend metrics to the respective math functions as Prometheus metrics.
66+
67+
68+
For example, `K6_PROMETHEUS_RW_TREND_STATS=p(90),p(95),max` transforms each trend metric into three Prometheus metrics as follows:
69+
70+
- `k6_*_p90`
71+
- `k6_*_p95`
72+
- `k6_*_max`
73+
74+
This option provides a configurable solution to represent `Trend` metrics in Prometheus but has the following drawbacks:
75+
- Convert a k6 `Trend` metric to several Prometheus metrics.
4576
- It is impossible to aggregate some gauge values (especially percentiles).
4677
- It uses a memory-expensive k6 data structure.
4778

48-
To resolve these limitations, you can map a trend as a [Prometheus Native Histogram](https://prometheus.io/docs/concepts/metric_types/#histogram).
49-
To do this,
50-
you can use the `K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM=true` environment variable
51-
(or one of the other ways).
52-
The output then converts all the trend types into a dedicated Native Histogram.
79+
### Prometheus Native histogram
5380

54-
Mapping trends as native histograms gives you more efficient storage and more precise queries.
55-
The drawback is that **the feature is experimental, released in Prometheus v2.40.0**.
5681

57-
<Blockquote mod="note" title="">
82+
To resolve the previous drawbacks, you can convert k6 trend metrics to high-fidelity histograms using [Prometheus Native Histogram](https://prometheus.io/docs/concepts/metric_types/#histogram). Each k6 trend metric maps to its respective Prometheus histogram metric: `k6_*`.
5883

59-
Native Histogram is an experimental feature, so it has to be enabled ([--enable-feature=native-histograms](https://prometheus.io/docs/prometheus/latest/feature_flags/#native-histograms)).
60-
Other remote write implementations might not support it yet.
6184

62-
</Blockquote>
85+
<Blockquote mod="" title="">
6386

64-
### Naming conventions
87+
To learn the benefits and outcomes of using Histograms, watch [High-resolution Histograms in the Prometheus TSDB](https://www.youtube.com/watch?v=F72Tk8iaWeA).
6588

66-
The output maps the metrics into time series with Name labels.
67-
As much as possible, k6 respects the [naming best practices](https://prometheus.io/docs/practices/naming) that the Prometheus project defines:
89+
</Blockquote>
6890

69-
* All time series are prefixed with the `k6_` namespace.
70-
* All time series are suffixed with the base unit of the sample value (if k6 knows what the base unit is).
71-
* Trends and rates have the relative suffixes, to make them more discoverable.
91+
Note that Native Histogram is an experimental feature released in Prometheus v2.40.0, and other remote write implementations might not support it yet. In the future, when Prometheus makes this feature stable, k6 will consider using it as the default conversion method for Trend metrics.
7292

73-
### Stale trend metrics
93+
The additional settings to use Native Histogram types are:
94+
95+
1. Enable the feature flag [--enable-feature=native-histograms](https://prometheus.io/docs/prometheus/latest/feature_flags/#native-histograms) in Prometheus.
96+
2. Run the k6 test enabling the `K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM=true` environment variable.
7497

75-
This k6 output can mark the time series at the end of the test as stale.
76-
To enable the stale marker option, set the `K6_PROMETHEUS_RW_STALE_MARKERS` environment variable to `true`.
7798

78-
By default, the metrics are active for 5 minutes after the last flushed sample.
79-
They are automatically marked as stale after.
80-
For details about staleness, refer to the [Prometheus docs](https://prometheus.io/docs/prometheus/latest/querying/basics/#staleness).
8199

82100
## Send test metrics to a remote write endpoint
83101

84-
<Blockquote mod="note" title="Prometheus as remote write agent">
102+
To use remote write in Prometheus 2.x:
85103

86-
To use remote write in Prometheus 2.x, use the `--web.enable-remote-write-receiver ` flag.
87-
The [xk6 extension](https://github.com/grafana/xk6-output-prometheus-remote) repository has some docker compose examples in the [example](https://github.com/grafana/xk6-output-prometheus-remote/tree/main/example) directory.
88-
For remote write storage options, refer to the [Prometheus docs](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write).
104+
- Enable the feature flag [--web.enable-remote-write-receiver](https://prometheus.io/docs/prometheus/latest/feature_flags/#remote-write-receiver). For remote write storage options, refer to the [Prometheus docs](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write).
105+
106+
- Optionally, enable the feature flag [--enable-feature=native-histograms](https://prometheus.io/docs/prometheus/latest/feature_flags/#native-histograms) in Prometheus 2.40.0 or higher to use [Prometheus Native Histogram](#prometheus-native-histogram).
89107

90-
</Blockquote>
91108

92-
To send k6 metrics to a remote write endpoint, follow these steps:
109+
To send k6 metrics to a remote write endpoint:
93110
1. Set up a running remote write endpoint with an endpoint that k6 can reach.
94-
1. Run your k6 script, using the `--out` flag with `experimental-prometheus-rw` as the argument:
111+
2. Run your k6 script, using the `--out` flag with `experimental-prometheus-rw` as the argument:
112+
113+
<CodeGroup labels={["Trend stats", "Native Histogram"]}>
95114

96115
```bash
97116
k6 run -o experimental-prometheus-rw script.js
98117
```
99-
100-
All the time series have a `k6_` prefix.
101-
In the Metric Explorer UI in Grafana, it looks something like this:
102118

103-
![k6 metrics as seen in the Prometheus UI](images/Prometheus/prom-metric-explorer.png)
119+
```bash
120+
K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM=true k6 run -o experimental-prometheus-rw script.js
121+
```
104122

105-
### Authenticate
123+
</CodeGroup>
106124

107-
If the remote write endpoint requires authentication, the output supports the HTTP Basic authentication and it can be used with the following command:
125+
If the remote write endpoint requires authentication, the output supports the HTTP Basic authentication and it can be used with the following command:
108126

109-
<CodeGroup labels={[""]}>
127+
<CodeGroup labels={["Trend stats", "Native Histogram"]}>
110128

111-
```bash
129+
```bash
112130
K6_PROMETHEUS_RW_USERNAME=foo \
113131
K6_PROMETHEUS_RW_PASSWORD=bar \
114132
./k6 run script.js -o experimental-prometheus-rw
115-
```
133+
```
134+
135+
```bash
136+
K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM=true \
137+
K6_PROMETHEUS_RW_USERNAME=foo \
138+
K6_PROMETHEUS_RW_PASSWORD=bar \
139+
./k6 run script.js -o experimental-prometheus-rw
140+
```
141+
142+
</CodeGroup>
143+
144+
145+
All the time series have a [`k6_` prefix](#metrics-mapping).
146+
In the Metric Explorer UI in Grafana, it looks something like this:
147+
148+
![k6 metrics as seen in the Prometheus UI](images/Prometheus/prom-metric-explorer.png)
149+
116150

117-
</CodeGroup>
118151

119-
Feel free to request more authentication methods or provide your experience in the [issue tracker](https://github.com/grafana/xk6-output-prometheus-remote/issues).
152+
The [`xk6-output-prometheus-remote` extension](https://github.com/grafana/xk6-output-prometheus-remote) repository has some docker compose examples. Feel free to request more authentication methods or provide your experience in the [issue tracker](https://github.com/grafana/xk6-output-prometheus-remote/issues).
120153

121154
## Options
122155

123156
k6 has special options for remote write output.
124157

125-
| Name | Type | Default | Description |
126-
| ---- | ---- | ------- | ----------- |
127-
| `K6_PROMETHEUS_RW_SERVER_URL` | `string` | `http://localhost:9090/api/v1/write` | URL of the Prometheus remote write implementation's endpoint. |
128-
| `K6_PROMETHEUS_RW_HEADERS_<here-the-header-key>` | list of `string` | | Additional headers to include in the HTTP requests. `K6_PROMETHEUS_RW_HEADERS_X-MY-HEADER=foo`|
129-
| `K6_PROMETHEUS_RW_USERNAME` | `string` | | User for the HTTP Basic authentication at the Prometheus remote write endpoint. |
130-
| `K6_PROMETHEUS_RW_PASSWORD` | `string` | | Password for the HTTP Basic authentication at the Prometheus remote write endpoint. |
131-
| `K6_PROMETHEUS_RW_PUSH_INTERVAL` | `string` | `5s` | Interval of the metrics' aggregation and upload to the endpoint. |
132-
| `K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM` | `boolean` | false | If true, it maps the all defined trend metrics as [Native Histograms](#trend). |
133-
| `K6_PROMETHEUS_RW_TREND_STATS` | list of `string` | `p(99)` | If Native Histogram is not enabled then it defines the stats functions to map for the all defined trend metrics. It's a comma-separated list of stats functions to include (e.g. `p(90),avg,sum`). Check the trend section to know the entire set of the supported stats. |
134-
| `K6_PROMETHEUS_RW_INSECURE_SKIP_TLS_VERIFY` | `boolean` | false | If true, the HTTP client skips TLS verification on the endpoint. |
135-
| `K6_PROMETHEUS_RW_STALE_MARKERS` | `boolean` | false | If true, the output at the end of the test marks all the seen time series as stale. |
158+
| Name | Type | Description |
159+
| ---- | ---- | ----------- |
160+
| `K6_PROMETHEUS_RW_SERVER_URL` | `string` | URL of the Prometheus remote write implementation's endpoint. Default is ``http://localhost:9090/api/v1/write`` |
161+
| `K6_PROMETHEUS_RW_HEADERS_<here-the-header-key>` | list of `string` | Additional headers to include in the HTTP requests. `K6_PROMETHEUS_RW_HEADERS_X-MY-HEADER=foo`|
162+
| `K6_PROMETHEUS_RW_USERNAME` | `string` | User for the HTTP Basic authentication at the Prometheus remote write endpoint. |
163+
| `K6_PROMETHEUS_RW_PASSWORD` | `string` | Password for the HTTP Basic authentication at the Prometheus remote write endpoint. |
164+
| `K6_PROMETHEUS_RW_PUSH_INTERVAL` | `string` | Interval of the metrics' aggregation and upload to the endpoint. Default is `5s` |
165+
| `K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM` | `boolean` | If true, it maps the all defined trend metrics as [Native Histograms](#prometheus-native-histogram). Default is `false`. |
166+
| `K6_PROMETHEUS_RW_TREND_STATS` | list of `string` | If Native Histogram is not enabled then it defines the stats functions to map for the all defined trend metrics. It's a comma-separated list of stats functions to include (e.g. `p(90),avg,sum`). Check the trend section to know the entire set of the supported stats. Default is `p(99)` |
167+
| `K6_PROMETHEUS_RW_INSECURE_SKIP_TLS_VERIFY` | `boolean` | If true, the HTTP client skips TLS verification on the endpoint. Default is `false`. |
168+
| `K6_PROMETHEUS_RW_STALE_MARKERS` | `boolean` | If true, the output at the end of the test marks all the seen time series as stale. Default is `false`. |
169+
170+
### Stale trend metrics
171+
172+
This k6 output can mark the time series at the end of the test as stale.
173+
To enable the stale marker option, set the `K6_PROMETHEUS_RW_STALE_MARKERS` environment variable to `true`.
174+
175+
By default, the metrics are active for 5 minutes after the last flushed sample.
176+
They are automatically marked as stale after.
177+
For details about staleness, refer to the [Prometheus docs](https://prometheus.io/docs/prometheus/latest/querying/basics/#staleness).
136178

137179
## Time series visualization
138180

0 commit comments

Comments
 (0)