Skip to content

Commit

Permalink
Add /health handler to node server
Browse files Browse the repository at this point in the history
This commit adds a very simple /health handler that returns 200 if
the server is running. This allows to check whether the node server
is running.

This fixes restatedev#2461.
  • Loading branch information
tillrohrmann committed Dec 30, 2024
1 parent 1ac1f70 commit 27457d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions crates/node/src/network_server/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use std::fmt::Write;

use axum::extract::State;
use http::StatusCode;
use metrics_exporter_prometheus::formatting;
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
use metrics_tracing_context::TracingContextLayer;
Expand Down Expand Up @@ -202,6 +203,10 @@ pub(crate) fn install_global_prometheus_recorder(opts: &CommonOptions) -> Promet
}

// -- Direct HTTP Handlers --
pub async fn report_health() -> StatusCode {
StatusCode::OK
}

pub async fn render_metrics(State(state): State<NodeCtrlHandlerState>) -> String {
let default_cf = CfName::new("default");
let mut out = String::new();
Expand Down
5 changes: 4 additions & 1 deletion crates/node/src/network_server/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use tokio::time::MissedTickBehavior;
use tonic::codec::CompressionEncoding;
use tracing::{debug, trace};

use crate::network_server::metrics::{install_global_prometheus_recorder, render_metrics};
use crate::network_server::metrics::{
install_global_prometheus_recorder, render_metrics, report_health,
};
use crate::network_server::state::NodeCtrlHandlerStateBuilder;
use restate_core::network::protobuf::core_node_svc::core_node_svc_server::CoreNodeSvcServer;
use restate_core::network::protobuf::node_ctl_svc::node_ctl_svc_server::NodeCtlSvcServer;
Expand Down Expand Up @@ -80,6 +82,7 @@ impl NetworkServer {

// -- HTTP service (for prometheus et al.)
let axum_router = axum::Router::new()
.route("/health", get(report_health))
.route("/metrics", get(render_metrics))
.route("/debug/pprof/heap", get(pprof::heap))
.route(
Expand Down

0 comments on commit 27457d8

Please sign in to comment.