Commit 7daa6e6
authored
Replace the OpenMetrics parser by a more efficient one (#44216)
### What does this PR do?
Replace the OpenMetrics parser of `github.com/prometheus/common/expfmt` by the one of `github.com/prometheus/prometheus/model/textparse`.
### Motivation
While the former is easier to use, the latter is more efficient and profiles on staging and prod are suggesting that the OpenMetrics parsing done in the `kubelet` and `containerd` checks are not negligeable.
This PR adds basic benchmarks in `pkg/util/prometheus/parse_test.go`.
Here are the results of those benchmark on the `main` commit this PR is based on:
```console
$ go test ./pkg/util/prometheus/... -bench=BenchmarkParseMetrics -benchmem -count=10 -benchtime=3s | ~/go/bin/benchstat -
goos: linux
goarch: amd64
pkg: github.com/DataDog/datadog-agent/pkg/util/prometheus
cpu: 12th Gen Intel(R) Core(TM) i9-12900H
│ - │
│ sec/op │
ParseMetrics-20 4.645m ± 2%
ParseMetricsWithFilter-20 1.844m ± 2%
ParseMetricsSmall-20 8.025µ ± 3%
geomean 409.6µ
│ - │
│ B/op │
ParseMetrics-20 2.741Mi ± 0%
ParseMetricsWithFilter-20 1.127Mi ± 0%
ParseMetricsSmall-20 8.867Ki ± 0%
geomean 306.2Ki
│ - │
│ allocs/op │
ParseMetrics-20 82.06k ± 0%
ParseMetricsWithFilter-20 30.34k ± 0%
ParseMetricsSmall-20 128.0 ± 0%
geomean 6.830k
```
Here are the results of the same benchmarks on the latest commit of this PR:
```console
$ go test ./pkg/util/prometheus/... -bench=BenchmarkParseMetrics -benchmem -count=10 -benchtime=3s | ~/go/bin/benchstat -
goos: linux
goarch: amd64
pkg: github.com/DataDog/datadog-agent/pkg/util/prometheus
cpu: 12th Gen Intel(R) Core(TM) i9-12900H
│ - │
│ sec/op │
ParseMetrics-20 1.453m ± 2%
ParseMetricsWithFilter-20 649.6µ ± 1%
ParseMetricsSmall-20 2.545µ ± 3%
geomean 133.9µ
│ - │
│ B/op │
ParseMetrics-20 1.536Mi ± 0%
ParseMetricsWithFilter-20 702.7Ki ± 0%
ParseMetricsSmall-20 3.445Ki ± 0%
geomean 156.2Ki
│ - │
│ allocs/op │
ParseMetrics-20 8.032k ± 0%
ParseMetricsWithFilter-20 3.621k ± 0%
ParseMetricsSmall-20 26.00 ± 0%
geomean 911.0
```
While **the CPU consumption is divided by 3, the number of memory allocations is divided by 10**!
This should help removing some stress on the GC.
### Describe how you validated your changes
This change has been deployed on a staging cluster:
<img width="3619" height="1214" alt="image" src="https://github.com/user-attachments/assets/e5d34900-f226-4edb-9130-59e4a51f880f" />
<!-- <img width="3621" height="1455" alt="image" src="https://github.com/user-attachments/assets/f8e91910-7524-489c-bbeb-87dd8ed91b4f" /> -->
### Additional Notes
Co-authored-by: lenaic.huard <[email protected]>1 parent 78d4f54 commit 7daa6e6
File tree
15 files changed
+899
-251
lines changed- comp/otelcol/status/impl
- pkg
- collector/corechecks/containers
- containerd
- kubelet
- common
- provider
- cadvisor
- kubelet
- prometheus
- slis
- util/prometheus
15 files changed
+899
-251
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
| |||
60 | 70 | | |
61 | 71 | | |
62 | 72 | | |
| 73 | + | |
| 74 | + | |
63 | 75 | | |
64 | 76 | | |
65 | 77 | | |
| |||
69 | 81 | | |
70 | 82 | | |
71 | 83 | | |
72 | | - | |
73 | 84 | | |
74 | 85 | | |
75 | 86 | | |
76 | 87 | | |
77 | 88 | | |
| 89 | + | |
78 | 90 | | |
79 | 91 | | |
80 | 92 | | |
| |||
83 | 95 | | |
84 | 96 | | |
85 | 97 | | |
| 98 | + | |
86 | 99 | | |
87 | 100 | | |
88 | 101 | | |
| |||
94 | 107 | | |
95 | 108 | | |
96 | 109 | | |
| 110 | + | |
97 | 111 | | |
98 | 112 | | |
| 113 | + | |
99 | 114 | | |
100 | 115 | | |
101 | 116 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | 208 | | |
213 | 209 | | |
214 | 210 | | |
| |||
217 | 213 | | |
218 | 214 | | |
219 | 215 | | |
220 | | - | |
| 216 | + | |
221 | 217 | | |
222 | 218 | | |
223 | | - | |
| 219 | + | |
224 | 220 | | |
225 | 221 | | |
226 | 222 | | |
| |||
Lines changed: 7 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | 11 | | |
14 | | - | |
| 12 | + | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
18 | | - | |
| 16 | + | |
19 | 17 | | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
24 | | - | |
| 22 | + | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
35 | 33 | | |
36 | 34 | | |
37 | 35 | | |
38 | | - | |
| 36 | + | |
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
| |||
45 | 43 | | |
46 | 44 | | |
47 | 45 | | |
48 | | - | |
49 | | - | |
| 46 | + | |
| 47 | + | |
50 | 48 | | |
51 | 49 | | |
52 | | - | |
| 50 | + | |
53 | 51 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
| |||
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
| 23 | + | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
154 | 153 | | |
155 | 154 | | |
156 | 155 | | |
157 | | - | |
158 | | - | |
159 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
160 | 159 | | |
161 | | - | |
162 | | - | |
| 160 | + | |
| 161 | + | |
163 | 162 | | |
164 | 163 | | |
165 | | - | |
| 164 | + | |
166 | 165 | | |
167 | 166 | | |
168 | | - | |
| 167 | + | |
169 | 168 | | |
170 | 169 | | |
171 | 170 | | |
| |||
0 commit comments