Harvest the latest metrics when /metrics
is requested
Now that we track active projects, if nothing happens to the store during the activity timeout we would still serve some old metrics that may not account for the staleness of a project. This commit changes it so that we grab a mutable reference to the store before serving the metrics, which has the side effect of updating all the metrics.
This commit is contained in:
parent
e373e05d27
commit
a85f9e74b1
2 changed files with 6 additions and 4 deletions
|
@ -1670,10 +1670,10 @@ pub fn routes(server: Arc<Server>) -> Router<Body> {
|
|||
.layer(
|
||||
ServiceBuilder::new()
|
||||
.layer(Extension(server.app_state.clone()))
|
||||
.layer(middleware::from_fn(auth::validate_header))
|
||||
.layer(Extension(server)),
|
||||
.layer(middleware::from_fn(auth::validate_header)),
|
||||
)
|
||||
.route("/metrics", get(handle_metrics))
|
||||
.layer(Extension(server))
|
||||
}
|
||||
|
||||
pub async fn handle_websocket_request(
|
||||
|
@ -1707,7 +1707,10 @@ pub async fn handle_websocket_request(
|
|||
})
|
||||
}
|
||||
|
||||
pub async fn handle_metrics() -> axum::response::Response {
|
||||
pub async fn handle_metrics(Extension(server): Extension<Arc<Server>>) -> axum::response::Response {
|
||||
// We call `store_mut` here for its side effects of updating metrics.
|
||||
server.store_mut().await;
|
||||
|
||||
let encoder = prometheus::TextEncoder::new();
|
||||
let metric_families = prometheus::gather();
|
||||
match encoder.encode_to_string(&metric_families) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue