1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use crate::rest::ContextLock;
use warp::{Filter, Rejection, Reply};

pub fn filter(
    context: ContextLock,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
    warp::path!("prometheus")
        .and(warp::get())
        .and(warp::any().map(move || context.clone()))
        .and_then(|context: ContextLock| async move {
            let context = context.read().await;
            let full_context = context.try_full().map_err(warp::reject::custom)?;
            full_context
                .prometheus
                .as_ref()
                .expect("Prometheus metrics exporter not set in API context!")
                .http_response()
        })
}