@@ -65,15 +65,15 @@ lazy_static! {
65
65
}
66
66
67
67
/// Internal metrics server state, holds state needed for serving
68
- /// dashboard and metrics.
68
+ /// metrics.
69
69
pub struct MetricsServer {
70
70
pub start_time : Instant ,
71
71
pub logger : Logger ,
72
72
pub adapter : Arc < State > ,
73
73
}
74
74
75
75
impl MetricsServer {
76
- /// Instantiate a metrics API with a dashboard
76
+ /// Instantiate a metrics API.
77
77
pub async fn spawn ( addr : impl Into < SocketAddr > + ' static , logger : Logger , adapter : Arc < State > ) {
78
78
let server = MetricsServer {
79
79
start_time : Instant :: now ( ) ,
@@ -82,56 +82,30 @@ impl MetricsServer {
82
82
} ;
83
83
84
84
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
-
110
85
let shared_state4metrics = shared_state. clone ( ) ;
111
86
let metrics_route = warp:: path ( "metrics" )
112
87
. and ( warp:: path:: end ( ) )
113
88
. and_then ( move || {
114
89
let shared_state = shared_state4metrics. clone ( ) ;
115
90
async move {
116
- let locked_state = shared_state. lock ( ) . await ;
91
+ let locked_state = shared_state. lock ( ) . await ;
117
92
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
+ } ) ;
127
103
128
- Result :: < Box < dyn Reply > , Rejection > :: Ok ( response)
104
+ Result :: < Box < dyn Reply > , Rejection > :: Ok ( response)
129
105
}
130
106
} ) ;
131
107
132
- warp:: serve ( dashboard_route. or ( metrics_route) )
133
- . bind ( addr)
134
- . await ;
108
+ warp:: serve ( metrics_route) . bind ( addr) . await ;
135
109
}
136
110
}
137
111
0 commit comments