iroh/address_lookup/metrics.rs
1//! Metrics for address lookup.
2
3use iroh_metrics::{Counter, EncodeLabelSet, Family, MetricsGroup};
4use serde::{Deserialize, Serialize};
5
6/// Labels identifying an address lookup service by its provenance string,
7/// see [`crate::address_lookup::Item::provenance`].
8#[derive(
9 Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, EncodeLabelSet,
10)]
11pub struct ServiceLabels {
12 /// Provenance string of the service.
13 pub service: String,
14}
15
16impl ServiceLabels {
17 /// Creates labels for the given service provenance.
18 pub fn new(service: impl Into<String>) -> Self {
19 Self {
20 service: service.into(),
21 }
22 }
23}
24
25/// Metrics collected by address lookup.
26///
27/// A lookup is one call to [`AddressLookupServices::resolve`] and queries all
28/// configured services at once. Each service can yield several results and
29/// errors per lookup; those are counted in the `service_*` counters, labeled
30/// by the service's provenance (e.g. `dns`, `pkarr`).
31///
32/// [`AddressLookupServices::resolve`]: crate::address_lookup::AddressLookupServices::resolve
33#[derive(Debug, Serialize, Deserialize, MetricsGroup)]
34#[non_exhaustive]
35#[metrics(name = "address_lookup", default)]
36pub struct Metrics {
37 /// Lookups started.
38 pub lookups: Counter,
39 /// Lookups that ended without a single result.
40 ///
41 /// Includes lookups with no services configured. Lookups abandoned early
42 /// (e.g. once a connection is established) are not counted.
43 pub lookups_failed: Counter,
44 /// Results yielded per service.
45 pub service_results: Family<ServiceLabels, Counter>,
46 /// Errors yielded per service.
47 pub service_errors: Family<ServiceLabels, Counter>,
48}