mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-20 06:30:43 +00:00
## Problem Monitoring dashboards show aggregates of all proxy instances, including terminating ones. This can skew the results or make graphs less readable. Also, alerts must be tuned to ignore certain signals from terminating proxies. ## Summary of changes Add a `service_info` metric currently with one label, `state`, showing if an instance is in state `init`, `running`, or `terminating`. The metric can be joined with other metrics to filter the presented time series.
44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
use std::convert::Infallible;
|
|
|
|
use anyhow::bail;
|
|
use tokio_util::sync::CancellationToken;
|
|
use tracing::{info, warn};
|
|
|
|
use crate::metrics::{Metrics, ServiceInfo};
|
|
|
|
/// Handle unix signals appropriately.
|
|
pub async fn handle<F>(
|
|
token: CancellationToken,
|
|
mut refresh_config: F,
|
|
) -> anyhow::Result<Infallible>
|
|
where
|
|
F: FnMut(),
|
|
{
|
|
use tokio::signal::unix::{SignalKind, signal};
|
|
|
|
let mut hangup = signal(SignalKind::hangup())?;
|
|
let mut interrupt = signal(SignalKind::interrupt())?;
|
|
let mut terminate = signal(SignalKind::terminate())?;
|
|
|
|
loop {
|
|
tokio::select! {
|
|
// Hangup is commonly used for config reload.
|
|
_ = hangup.recv() => {
|
|
info!("received SIGHUP");
|
|
refresh_config();
|
|
}
|
|
// Shut down the whole application.
|
|
_ = interrupt.recv() => {
|
|
warn!("received SIGINT, exiting immediately");
|
|
Metrics::get().service.info.set_label(ServiceInfo::terminating());
|
|
bail!("interrupted");
|
|
}
|
|
_ = terminate.recv() => {
|
|
warn!("received SIGTERM, shutting down once all existing connections have closed");
|
|
Metrics::get().service.info.set_label(ServiceInfo::terminating());
|
|
token.cancel();
|
|
}
|
|
}
|
|
}
|
|
}
|