1//! Crate-specific metrics functionality.
2//!
3//! This module re-exports the contents of the `metrics` crate. This is
4//! effectively a way to monkey-patch the functions in this module into the
5//! `metrics` crate, at least from the point of view of the other code in this
6//! crate.
7//!
8//! Code in this crate that wants to use metrics should `use crate::metrics;`,
9//! so that this module shadows the `metrics` crate.
10//!
11//! This trick is probably good to avoid in general, because it could be
12//! confusing, but in this limited case, it seems like a clean option.
1314pub use metrics::*;
1516/// Registers all metrics used by this crate.
17pub fn register_metrics() {
18describe_histogram!(
19 DEX_ARB_DURATION,
20 Unit::Seconds,
21"The time spent computing arbitrage during endblock phase"
22);
23describe_histogram!(
24 DEX_BATCH_DURATION,
25 Unit::Seconds,
26"The time spent executing batches within the DEX"
27);
28describe_histogram!(
29 DEX_PATH_SEARCH_DURATION,
30 Unit::Seconds,
31"The time spent searching for paths while executing trades within the DEX"
32);
33describe_counter!(
34 DEX_PATH_SEARCH_RELAX_PATH_DURATION,
35 Unit::Seconds,
36"The time spent relaxing a path while routing trades within the DEX"
37);
38describe_histogram!(
39 DEX_ROUTE_FILL_DURATION,
40 Unit::Seconds,
41"The time spent filling routes while executing trades within the DEX"
42);
43describe_histogram!(
44 DEX_RPC_SIMULATE_TRADE_DURATION,
45 Unit::Seconds,
46"The time spent processing a SimulateTrade RPC request"
47);
48}
4950// We configure buckets for the DEX routing times manually, in order to ensure
51// Prometheus metrics are structured as a Histogram, rather than as a Summary.
52// These values may need to be updated over time.
53// These values are logarithmically spaced from 5us to 67ms.
54const GENERIC_DEX_BUCKETS: &[f64; 16] = &[
550.0005,
560.000792,
570.001256,
580.001991,
590.003155,
600.005,
610.00648985018,
620.00842363108,
630.01093362074,
640.01419151211,
650.01842015749,
660.02390881249,
670.03103292223,
680.0402798032,
690.05228197763,
700.06786044041,
71];
7273pub const DEX_PATH_SEARCH_DURATION: &str = "penumbra_dex_path_search_duration_seconds";
74pub const DEX_PATH_SEARCH_RELAX_PATH_DURATION: &str =
75"penumbra_dex_path_search_relax_path_duration_seconds";
76pub const DEX_ROUTE_FILL_DURATION: &str = "penumbra_dex_route_fill_duration_seconds";
77pub const DEX_ARB_DURATION: &str = "penumbra_dex_arb_duration_seconds";
78pub const DEX_BATCH_DURATION: &str = "penumbra_dex_batch_duration_seconds";
79pub const DEX_RPC_SIMULATE_TRADE_DURATION: &str =
80"penumbra_dex_rpc_simulate_trade_duration_seconds";
8182/// An extension trait providing DEX-related interfaces for [`PrometheusBuilder`].
83///
84/// [builder]: metrics_exporter_prometheus::PrometheusBuilder
85pub trait PrometheusBuilderExt
86where
87Self: Sized,
88{
89/// Configure buckets for histogram metrics.
90fn set_buckets_for_dex_metrics(self) -> Result<Self, metrics_exporter_prometheus::BuildError>;
91}
9293impl PrometheusBuilderExt for metrics_exporter_prometheus::PrometheusBuilder {
94fn set_buckets_for_dex_metrics(self) -> Result<Self, metrics_exporter_prometheus::BuildError> {
95use metrics_exporter_prometheus::Matcher::Full;
96self.set_buckets_for_metric(
97 Full(DEX_PATH_SEARCH_DURATION.to_owned()),
98 GENERIC_DEX_BUCKETS,
99 )?
100.set_buckets_for_metric(
101 Full(DEX_PATH_SEARCH_RELAX_PATH_DURATION.to_owned()),
102 GENERIC_DEX_BUCKETS,
103 )?
104.set_buckets_for_metric(
105 Full(DEX_ROUTE_FILL_DURATION.to_owned()),
106 GENERIC_DEX_BUCKETS,
107 )?
108.set_buckets_for_metric(Full(DEX_ARB_DURATION.to_owned()), GENERIC_DEX_BUCKETS)?
109.set_buckets_for_metric(Full(DEX_BATCH_DURATION.to_owned()), GENERIC_DEX_BUCKETS)?
110.set_buckets_for_metric(
111 Full(DEX_RPC_SIMULATE_TRADE_DURATION.to_owned()),
112 GENERIC_DEX_BUCKETS,
113 )
114 }
115}