mirror of
https://github.com/neondatabase/neon.git
synced 2026-08-18 03:58:19 +00:00
c75b584430
## Problem Storage controller had basically no metrics. ## Summary of changes 1. Migrate the existing metrics to use Conrad's [`measured`](https://docs.rs/measured/0.0.14/measured/) crate. 2. Add metrics for incoming http requests 3. Add metrics for outgoing http requests to the pageserver 4. Add metrics for outgoing pass through requests to the pageserver 5. Add metrics for database queries Note that the metrics response for the attachment service does not use chunked encoding like the rest of the metrics endpoints. Conrad has kindly extended the crate such that it can now be done. Let's leave it for a follow-up since the payload shouldn't be that big at this point. Fixes https://github.com/neondatabase/neon/issues/6875
35 lines
1.0 KiB
Rust
35 lines
1.0 KiB
Rust
use anyhow::{anyhow, bail};
|
|
use hyper::{Body, Request, Response, StatusCode};
|
|
use std::{convert::Infallible, net::TcpListener};
|
|
use tracing::info;
|
|
use utils::http::{
|
|
endpoint::{self, prometheus_metrics_handler, request_span},
|
|
error::ApiError,
|
|
json::json_response,
|
|
RouterBuilder, RouterService,
|
|
};
|
|
|
|
async fn status_handler(_: Request<Body>) -> Result<Response<Body>, ApiError> {
|
|
json_response(StatusCode::OK, "")
|
|
}
|
|
|
|
fn make_router() -> RouterBuilder<hyper::Body, ApiError> {
|
|
endpoint::make_router()
|
|
.get("/metrics", |r| request_span(r, prometheus_metrics_handler))
|
|
.get("/v1/status", status_handler)
|
|
}
|
|
|
|
pub async fn task_main(http_listener: TcpListener) -> anyhow::Result<Infallible> {
|
|
scopeguard::defer! {
|
|
info!("http has shut down");
|
|
}
|
|
|
|
let service = || RouterService::new(make_router().build()?);
|
|
|
|
hyper::Server::from_tcp(http_listener)?
|
|
.serve(service().map_err(|e| anyhow!(e))?)
|
|
.await?;
|
|
|
|
bail!("hyper server without shutdown handling cannot shutdown successfully");
|
|
}
|