@@ -65,15 +65,15 @@ lazy_static! {
6565}
6666
6767/// Internal metrics server state, holds state needed for serving
68- /// dashboard and metrics.
68+ /// metrics.
6969pub struct MetricsServer {
7070 pub start_time : Instant ,
7171 pub logger : Logger ,
7272 pub adapter : Arc < State > ,
7373}
7474
7575impl MetricsServer {
76- /// Instantiate a metrics API with a dashboard
76+ /// Instantiate a metrics API.
7777 pub async fn spawn ( addr : impl Into < SocketAddr > + ' static , logger : Logger , adapter : Arc < State > ) {
7878 let server = MetricsServer {
7979 start_time : Instant :: now ( ) ,
@@ -82,56 +82,30 @@ impl MetricsServer {
8282 } ;
8383
8484 let shared_state = Arc :: new ( Mutex :: new ( server) ) ;
85-
86- let shared_state4dashboard = shared_state. clone ( ) ;
87- let dashboard_route = warp:: path ( "dashboard" )
88- . or ( warp:: path:: end ( ) )
89- . and_then ( move |_| {
90- let shared_state = shared_state4dashboard. clone ( ) ;
91- async move {
92- let locked_state = shared_state. lock ( ) . await ;
93- let response = locked_state
94- . render_dashboard ( ) // Defined in a separate impl block near dashboard-specific code
95- . await
96- . unwrap_or_else ( |e| {
97- // Add logging here
98- error ! ( locked_state. logger, "Dashboard: Rendering failed" ; "error" => e. to_string( ) ) ;
99-
100- // Withhold failure details from client
101- "Could not render dashboard! See the logs for details" . to_owned ( )
102- } ) ;
103- Result :: < Box < dyn Reply > , Rejection > :: Ok ( Box :: new ( reply:: with_status (
104- reply:: html ( response) ,
105- StatusCode :: OK ,
106- ) ) )
107- }
108- } ) ;
109-
11085 let shared_state4metrics = shared_state. clone ( ) ;
11186 let metrics_route = warp:: path ( "metrics" )
11287 . and ( warp:: path:: end ( ) )
11388 . and_then ( move || {
11489 let shared_state = shared_state4metrics. clone ( ) ;
11590 async move {
116- let locked_state = shared_state. lock ( ) . await ;
91+ let locked_state = shared_state. lock ( ) . await ;
11792 let mut buf = String :: new ( ) ;
118- let response = encode ( & mut buf, & & PROMETHEUS_REGISTRY . lock ( ) . await ) . map_err ( |e| -> Box < dyn std:: error:: Error > { e. into ( )
119- } ) . and_then ( |_| -> Result < _ , Box < dyn std:: error:: Error > > {
120-
121- Ok ( Box :: new ( reply:: with_status ( buf, StatusCode :: OK ) ) )
122- } ) . unwrap_or_else ( |e| {
123- error ! ( locked_state. logger, "Metrics: Could not gather metrics from registry" ; "error" => e. to_string( ) ) ;
124-
125- Box :: new ( reply:: with_status ( "Could not gather metrics. See logs for details" . to_string ( ) , StatusCode :: INTERNAL_SERVER_ERROR ) )
126- } ) ;
93+ let response = encode ( & mut buf, & & PROMETHEUS_REGISTRY . lock ( ) . await )
94+ . map_err ( |e| -> Box < dyn std:: error:: Error > {
95+ e. into ( )
96+ } )
97+ . and_then ( |_| -> Result < _ , Box < dyn std:: error:: Error > > {
98+ Ok ( Box :: new ( reply:: with_status ( buf, StatusCode :: OK ) ) )
99+ } ) . unwrap_or_else ( |e| {
100+ error ! ( locked_state. logger, "Metrics: Could not gather metrics from registry" ; "error" => e. to_string( ) ) ;
101+ Box :: new ( reply:: with_status ( "Could not gather metrics. See logs for details" . to_string ( ) , StatusCode :: INTERNAL_SERVER_ERROR ) )
102+ } ) ;
127103
128- Result :: < Box < dyn Reply > , Rejection > :: Ok ( response)
104+ Result :: < Box < dyn Reply > , Rejection > :: Ok ( response)
129105 }
130106 } ) ;
131107
132- warp:: serve ( dashboard_route. or ( metrics_route) )
133- . bind ( addr)
134- . await ;
108+ warp:: serve ( metrics_route) . bind ( addr) . await ;
135109 }
136110}
137111
0 commit comments