11use std:: net:: SocketAddr ;
22
33use apollo_infra:: component_definitions:: ComponentStarter ;
4- use apollo_infra:: metrics:: MetricsConfig ;
5- use apollo_infra:: tokio_metrics:: setup_tokio_metrics;
4+ use apollo_infra:: metrics:: { initialize_metrics_recorder, MetricsConfig } ;
65use apollo_infra:: trace_util:: { configure_tracing, get_log_directives, set_log_level} ;
76use apollo_infra_utils:: type_name:: short_type_name;
87use apollo_l1_provider_types:: { L1ProviderSnapshot , SharedL1ProviderClient } ;
98use apollo_mempool_types:: communication:: SharedMempoolClient ;
109use apollo_mempool_types:: mempool_types:: MempoolSnapshot ;
11- use apollo_metrics:: metrics:: COLLECT_SEQUENCER_PROFILING_METRICS ;
1210use apollo_monitoring_endpoint_config:: config:: MonitoringEndpointConfig ;
1311use axum:: extract:: Path ;
1412use axum:: http:: StatusCode ;
1513use axum:: response:: { IntoResponse , Response } ;
1614use axum:: routing:: { get, post} ;
1715use axum:: { async_trait, Json , Router , Server } ;
1816use hyper:: Error ;
19- use metrics_exporter_prometheus:: { PrometheusBuilder , PrometheusHandle } ;
17+ use metrics_exporter_prometheus:: PrometheusHandle ;
2018use tracing:: level_filters:: LevelFilter ;
2119use tracing:: { error, info, instrument} ;
2220
@@ -34,11 +32,6 @@ pub(crate) const L1_PROVIDER_SNAPSHOT: &str = "l1ProviderSnapshot";
3432pub ( crate ) const SET_LOG_LEVEL : & str = "setLogLevel" ;
3533pub ( crate ) const LOG_LEVEL : & str = "logLevel" ;
3634
37- pub const HISTOGRAM_BUCKETS : & [ f64 ] = & [
38- 0.001 , 0.0025 , 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 0.25 , 0.5 , 1.0 , 2.5 , 5.0 , 10.0 , 25.0 , 50.0 ,
39- 100.0 , 250.0 ,
40- ] ;
41-
4235pub struct MonitoringEndpoint {
4336 config : MonitoringEndpointConfig ,
4437 version : & ' static str ,
@@ -51,28 +44,10 @@ impl MonitoringEndpoint {
5144 pub fn new (
5245 config : MonitoringEndpointConfig ,
5346 version : & ' static str ,
54- metrics_config : MetricsConfig ,
47+ prometheus_handle : Option < PrometheusHandle > ,
5548 mempool_client : Option < SharedMempoolClient > ,
5649 l1_provider_client : Option < SharedL1ProviderClient > ,
5750 ) -> Self {
58- // TODO(Tsabary): consider error handling
59- let prometheus_handle = if metrics_config. collect_metrics {
60- // TODO(Lev): add tests that show the metrics are collected / not collected based on the
61- // config value.
62- COLLECT_SEQUENCER_PROFILING_METRICS
63- . set ( metrics_config. collect_profiling_metrics )
64- . expect ( "Should be able to set profiling metrics collection." ) ;
65-
66- Some (
67- PrometheusBuilder :: new ( )
68- . set_buckets ( HISTOGRAM_BUCKETS )
69- . expect ( "Should be able to set buckets" )
70- . install_recorder ( )
71- . expect ( "should be able to build the recorder and install it globally" ) ,
72- )
73- } else {
74- None
75- } ;
7651 MonitoringEndpoint {
7752 config,
7853 version,
@@ -141,24 +116,15 @@ impl MonitoringEndpoint {
141116 }
142117}
143118
144- // TODO(tsabary): finalize the separation of the metrics recorder initialization and the monitoring
145- // endpoint setup
146119pub fn create_monitoring_endpoint (
147120 config : MonitoringEndpointConfig ,
148121 version : & ' static str ,
149122 metrics_config : MetricsConfig ,
150123 mempool_client : Option < SharedMempoolClient > ,
151124 l1_provider_client : Option < SharedL1ProviderClient > ,
152125) -> MonitoringEndpoint {
153- let result = MonitoringEndpoint :: new (
154- config,
155- version,
156- metrics_config,
157- mempool_client,
158- l1_provider_client,
159- ) ;
160- setup_tokio_metrics ( ) ;
161- result
126+ let prometheus_handle = initialize_metrics_recorder ( metrics_config) ;
127+ MonitoringEndpoint :: new ( config, version, prometheus_handle, mempool_client, l1_provider_client)
162128}
163129
164130#[ async_trait]
0 commit comments