Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metric: add started and killed walredo processes counter #5809

Merged
merged 7 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pageserver/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,31 @@ pub(crate) static WAL_REDO_RECORD_COUNTER: Lazy<IntCounter> = Lazy::new(|| {
.unwrap()
});

pub(crate) struct WalRedoProcessCounters {
pub(crate) started: IntCounter,
pub(crate) shutdown: IntCounter,
pub(crate) killed: IntCounter,
}

impl Default for WalRedoProcessCounters {
fn default() -> Self {
let wal_redo_process_counter = register_int_counter_vec!(
"pageserver_wal_redo_process_total",
"Number of WAL redo process by operation since pageserver startup",
&["operation"]
)
.unwrap();
Self {
started: wal_redo_process_counter.with_label_values(&["started"]),
shutdown: wal_redo_process_counter.with_label_values(&["shutdown"]),
killed: wal_redo_process_counter.with_label_values(&["killed"]),
}
}
}

pub(crate) static WAL_REDO_PROCESS_COUNTERS: Lazy<WalRedoProcessCounters> =
Lazy::new(WalRedoProcessCounters::default);

/// Similar to `prometheus::HistogramTimer` but does not record on drop.
pub struct StorageTimeMetricsTimer {
metrics: StorageTimeMetrics,
Expand Down
8 changes: 6 additions & 2 deletions pageserver/src/walredo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ use std::sync::atomic::{AtomicUsize, Ordering};

use crate::config::PageServerConf;
use crate::metrics::{
WAL_REDO_BYTES_HISTOGRAM, WAL_REDO_RECORDS_HISTOGRAM, WAL_REDO_RECORD_COUNTER, WAL_REDO_TIME,
WAL_REDO_WAIT_TIME,
WAL_REDO_BYTES_HISTOGRAM, WAL_REDO_PROCESS_COUNTERS, WAL_REDO_RECORDS_HISTOGRAM,
WAL_REDO_RECORD_COUNTER, WAL_REDO_TIME, WAL_REDO_WAIT_TIME,
};
use crate::pgdatadir_mapping::{key_to_rel_block, key_to_slru_block};
use crate::repository::Key;
Expand Down Expand Up @@ -668,9 +668,12 @@ impl WalRedoProcess {
.spawn_no_leak_child(tenant_id)
.context("spawn process")?;

WAL_REDO_PROCESS_COUNTERS.started.inc();

let mut child = scopeguard::guard(child, |child| {
error!("killing wal-redo-postgres process due to a problem during launch");
child.kill_and_wait();
WAL_REDO_PROCESS_COUNTERS.killed.inc();
});

let stdin = child.stdin.take().unwrap();
Expand Down Expand Up @@ -1002,6 +1005,7 @@ impl Drop for WalRedoProcess {
.take()
.expect("we only do this once")
.kill_and_wait();
WAL_REDO_PROCESS_COUNTERS.shutdown.inc();
self.stderr_logger_cancel.cancel();
// no way to wait for stderr_logger_task from Drop because that is async only
}
Expand Down