Commit 1957ca8
feat!: metrics refactor (#3262)
## Description
Depends on n0-computer/net-tools#20
Until now, we were using a superglobal static `iroh_metrics::core::Core`
struct to collect metrics into. This allowed us to use macros to track
metrics from anywhere in the codebase. However, this also made it
impossible to collect metrics *per endpoint*, which is what you want
usually as soon as you have more than one endpoint in your app.
This PR builds on n0-computer/iroh-metrics#15,
n0-computer/iroh-metrics#22, and n0-computer/iroh-metrics#23. It removes
the global metrics collection from all crates in the iroh repository.
Instead, we now create and pass metrics collector structs to all places
where we need to collect metrics.
This PR disables the `static_core` feature from iroh-metrics, which
means the macros for superglobal metrics collection are not available
anymore. This is good, because otherwise we could easily miss metrics
not tracked onto the proper metrics collector.
This PR also updates iroh-dns-server and iroh-relay to use manual
metrics collection.
While this means that we have to pass our metrics structs to more
places, it also makes metrics collection more visible, and we can now
also split the metrics structs further easily if we want to separate
concerns more.
This PR should not change anything apart from metrics collection. Most
places are straightforward conversions from the macros to methods on the
metrics collectors. At a few places, logic was changed slightly to move
metrics collection a layer up to save a few clones.
## Breaking Changes
* All metrics structs (`iroh::metrics::{MagicsockMetrics,
PortmapMetrics, NetReportMetrics}`) now implement `MetricsGroup` from
the new version `0.34` of `iroh-metrics` and no longer implement traits
from `[email protected]`.
* Metrics are no longer registered onto the static superglobal `Core`.
`iroh` does not use `static_core` feature of `iroh-metrics`. Metrics are
now exposed from the subsystems that track them, see e.g.
`Endpoint::metrics`.
Several methods now take a `Metrics` argument. You can always pass
`Default::default` if you don't want to unify metrics tracking with
other sections.
#### `iroh`
* `iroh::metrics::{MagicsockMetrics, NetReportMetrics, PortmapMetrics}`
all are now marked `non_exhaustive`, and implement
`iroh_metrics::MetricsGroup` from `[email protected]` and no longer
implement `iroh_metrics::Metric` from `[email protected]`. They also no
longer implement `Clone` (put them into an `Arc` for cloning instead).
* `iroh::net_report::Client::new` now takes
`iroh::net_report::metrics::Metrics` as forth argument
#### `iroh-dns-server`
* `iroh_dns_server::server::Server::spawn` now takes `Metrics` as third
argument
* `iroh_dns_server::ZoneStore::persistent` now takes `Metrics` as third
argument
* `iroh_dns_server::ZoneStore::in_memory` now takes `Metrics` as third
argument
* `iroh_dns_server::ZoneStore::new` now takes `Metrics` as third
argument
* `iroh_dns_server::state::AppState` now has a public `metrics: Metrics`
field
* `iroh_dns_server::dns::DnsHandler::new` now takes `Metrics` as third
argument
* function `iroh_dns_server::metrics::init_metrics` is removed
#### `iroh-relay`
* `iroh_relay::metrics::{StunMetrics, Metrics}` all are now marked
`non_exhaustive`, and implement `iroh_metrics::MetricsGroup` from
`[email protected]` and no longer implement `iroh_metrics::Metric` from
`[email protected]`. They also no longer implement `Clone` (put them
into an `Arc` for cloning instead).
## Notes & open questions
<!-- Any notes, remarks or open questions you have to make about the PR.
-->
## Change checklist
<!-- Remove any that are not relevant. -->
- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All breaking changes documented.
- [x] List all breaking changes in the above "Breaking Changes" section.
- [x] Open an issue or PR on any number0 repos that are affected by this
breaking change. Give guidance on how the updates should be handled or
do the actual updates themselves.
- [x] [`iroh-gossip`](https://github.com/n0-computer/iroh-gossip)
- n0-computer/iroh-gossip#58
- [x] [`iroh-blobs`](https://github.com/n0-computer/iroh-blobs)
- n0-computer/iroh-blobs#85
- [x] [`iroh-docs`](https://github.com/n0-computer/iroh-docs)
- n0-computer/iroh-docs#41
---------
Co-authored-by: dignifiedquire <[email protected]>1 parent 839bfaa commit 1957ca8
File tree
34 files changed
+847
-773
lines changed- iroh-dns-server
- benches
- src
- store
- iroh-relay
- src
- server
- iroh
- bench
- src/bin
- src
- endpoint
- magicsock
- node_map
- net_report
- reportgen
34 files changed
+847
-773
lines changedSome 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 | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
4 | | - | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | | - | |
12 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| |||
122 | 121 | | |
123 | 122 | | |
124 | 123 | | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| |||
168 | 169 | | |
169 | 170 | | |
170 | 171 | | |
171 | | - | |
| 172 | + | |
172 | 173 | | |
173 | | - | |
174 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
175 | 180 | | |
176 | 181 | | |
177 | 182 | | |
178 | 183 | | |
179 | 184 | | |
180 | 185 | | |
181 | 186 | | |
182 | | - | |
183 | | - | |
| 187 | + | |
| 188 | + | |
184 | 189 | | |
185 | | - | |
186 | | - | |
187 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
188 | 193 | | |
189 | 194 | | |
190 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
34 | | - | |
| 33 | + | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
| |||
227 | 226 | | |
228 | 227 | | |
229 | 228 | | |
230 | | - | |
| 229 | + | |
231 | 230 | | |
232 | 231 | | |
233 | 232 | | |
234 | 233 | | |
235 | 234 | | |
236 | | - | |
| 235 | + | |
237 | 236 | | |
238 | 237 | | |
239 | 238 | | |
| |||
244 | 243 | | |
245 | 244 | | |
246 | 245 | | |
247 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
248 | 251 | | |
249 | 252 | | |
250 | 253 | | |
251 | 254 | | |
252 | | - | |
253 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
254 | 260 | | |
255 | | - | |
| 261 | + | |
256 | 262 | | |
257 | | - | |
| 263 | + | |
258 | 264 | | |
259 | 265 | | |
260 | 266 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
| 5 | + | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
| |||
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
31 | 28 | | |
32 | 29 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
5 | 4 | | |
6 | 5 | | |
7 | | - | |
8 | | - | |
| 6 | + | |
| 7 | + | |
9 | 8 | | |
| 9 | + | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
| 13 | + | |
12 | 14 | | |
| 15 | + | |
13 | 16 | | |
| 17 | + | |
14 | 18 | | |
| 19 | + | |
15 | 20 | | |
| 21 | + | |
16 | 22 | | |
| 23 | + | |
17 | 24 | | |
| 25 | + | |
18 | 26 | | |
| 27 | + | |
19 | 28 | | |
| 29 | + | |
20 | 30 | | |
| 31 | + | |
21 | 32 | | |
| 33 | + | |
22 | 34 | | |
| 35 | + | |
23 | 36 | | |
| 37 | + | |
24 | 38 | | |
| 39 | + | |
25 | 40 | | |
26 | 41 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | | - | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
25 | 30 | | |
26 | | - | |
| 31 | + | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
| |||
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
47 | | - | |
48 | | - | |
| 52 | + | |
| 53 | + | |
49 | 54 | | |
50 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
51 | 60 | | |
52 | 61 | | |
53 | 62 | | |
54 | 63 | | |
55 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
| |||
122 | 133 | | |
123 | 134 | | |
124 | 135 | | |
125 | | - | |
| 136 | + | |
126 | 137 | | |
127 | 138 | | |
128 | 139 | | |
129 | 140 | | |
130 | | - | |
| 141 | + | |
131 | 142 | | |
132 | 143 | | |
133 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
0 commit comments