Skip to content

Commit f4bdacf

Browse files
iskakaushikharshil-goel
authored andcommitted
feat(shadow-stream): walsender connection, backfill and queue metrics
1 parent cf5bbbc commit f4bdacf

6 files changed

Lines changed: 187 additions & 60 deletions

File tree

‎src/bin/stream/metrics_publish.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ pub(crate) struct ShadowMetricsView {
2828
/// yet, so the gauges keep their last value
2929
pub(crate) apply_lag: Option<(u64, f64)>,
3030
pub(crate) active_connections: u64,
31-
pub(crate) dropped_total: u64,
31+
pub(crate) socket_events: [u64; walshadow::shadow_stream::SocketEvent::COUNT],
32+
pub(crate) backfill_bytes_total: u64,
33+
pub(crate) send_queue_bytes: u64,
3234
}
3335

3436
/// Apply lag against the source head. A zero `shadow_replay` means no walreceiver
@@ -313,7 +315,9 @@ pub(crate) async fn populate_metrics(
313315
shadow_apply_lag_bytes: apply_lag_bytes,
314316
shadow_apply_lag_seconds: apply_lag_seconds,
315317
shadow_stream_active_connections: shadow_view.active_connections,
316-
shadow_stream_dropped_connections_total: shadow_view.dropped_total,
318+
shadow_stream_sockets_by_event: shadow_view.socket_events,
319+
wal_bytes: [shadow_view.backfill_bytes_total],
320+
buffer_bytes: [shadow_view.send_queue_bytes],
317321
..registry.snapshot().await
318322
};
319323
populate_pipeline_metrics(

‎src/bin/stream/session.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ async fn session_body(
14151415
holds require a live wire — point shadow's primary_conninfo here \
14161416
or raise --walsender-connect-timeout",
14171417
args.walsender_connect_timeout,
1418-
agg.accepted_total,
1418+
agg.accepted(),
14191419
);
14201420
or_signal(shutdown, async {
14211421
tokio::time::sleep(Duration::from_millis(100)).await;
@@ -2289,7 +2289,9 @@ async fn session_body(
22892289
ShadowMetricsView {
22902290
apply_lag,
22912291
active_connections: shadow_agg.active_connections as u64,
2292-
dropped_total: shadow_agg.dropped_total,
2292+
socket_events: shadow_agg.socket_events,
2293+
backfill_bytes_total: shadow_agg.backfill_bytes_total,
2294+
send_queue_bytes: shadow_agg.send_queue_bytes,
22932295
},
22942296
&boundary_hold_stats,
22952297
metrics_dbs.iter().map(DbMetricSources::series).collect(),

‎src/ops/metrics.rs‎

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::catalog::pending::DegradeReason;
3737
use crate::decode::heap_decoder::HEAP_OP_LABELS;
3838
use crate::ops::bridge::{OP_COUNT, OP_LABELS};
3939
use crate::pos::{Drain, EmitterAck, FilterDispatched, Floor, Pos, ShadowReplay, SourceReceived};
40+
use crate::source::shadow_stream::SocketEvent;
4041
use crate::source::transition::SWITCH_FAILURE_REASONS;
4142

4243
#[macro_export]
@@ -98,6 +99,18 @@ macro_rules! label_class {
9899
};
99100
}
100101

102+
label_class! {
103+
pub enum WalFlow {
104+
WalsenderBackfill => "walsender_backfill",
105+
}
106+
}
107+
108+
label_class! {
109+
pub enum Buffer {
110+
WalsenderSendQueue => "walsender_send_queue",
111+
}
112+
}
113+
101114
label_class! {
102115
pub enum WorkerState {
103116
Busy => "busy",
@@ -293,6 +306,11 @@ snapshot! {
293306
/// Failures by [`ErrorKind`], rendered
294307
/// `walshadow_errors_total{component,kind}`
295308
errors: [u64; ErrorKind::COUNT],
309+
/// Postgres data moved, by [`WalFlow`], rendered
310+
/// `walshadow_wal_bytes_total{flow}`
311+
wal_bytes: [u64; WalFlow::COUNT],
312+
/// Data held, by [`Buffer`], rendered `walshadow_buffer_bytes{buffer}`
313+
buffer_bytes: [u64; Buffer::COUNT],
296314
/// Refusal a crossing parked on, rendered as `crossing_wedged`. The
297315
/// pump keeps publishing rather than exiting into a restart that
298316
/// re-crosses and re-fails, so this is how the daemon says it is
@@ -598,9 +616,9 @@ snapshot! {
598616
"Estimated seconds shadow trails source, by source byte rate over last 30s.",
599617
gauge shadow_stream_active_connections: u64 =
600618
"Currently-attached walreceiver connections to walshadow's walsender.",
601-
/// Cumulative connections dropped by `slow_threshold` overflow
602-
counter shadow_stream_dropped_connections_total: u64 =
603-
"Connections dropped by slow-client cutoff since daemon start.",
619+
counter shadow_stream_sockets_by_event: [u64; SocketEvent::COUNT]
620+
["event" = SocketEvent::LABELS] =
621+
"Walsender socket lifecycle events: accepted (entered the handshake, START_REPLICATION or not), closed_slow_client (dropped at the send queue cap), closed_by_client (clean hangup), closed_error (handshake, I/O, protocol failure or refused START_REPLICATION). accepted minus the closed events is sockets alive.",
604622
counter catalog_boundary_holds_total: u64 =
605623
"Publication holds released at catalog-mutating commit boundaries.",
606624
counter catalog_boundary_hold_failures_total: u64 =
@@ -1102,6 +1120,26 @@ fn encode_snapshot(snap: &MetricsSnapshot, enc: &mut DescriptorEncoder<'_>) -> f
11021120
.map(|e| (e.pair(), snap.errors[e.index()])),
11031121
)?;
11041122

1123+
counter_series(
1124+
enc,
1125+
"walshadow_wal_bytes_total",
1126+
"Postgres data moved, by flow. walsender_backfill is WAL replayed from the retained wire buffer to a reconnecting shadow walreceiver.",
1127+
"flow",
1128+
WalFlow::ALL
1129+
.into_iter()
1130+
.map(|f| (f.label(), snap.wal_bytes[f.index()])),
1131+
)?;
1132+
1133+
gauge_series(
1134+
enc,
1135+
"walshadow_buffer_bytes",
1136+
"Data held right now, by buffer. walsender_send_queue is the largest unsent walsender queue across connections, read against the slow-client cap.",
1137+
"buffer",
1138+
Buffer::ALL
1139+
.into_iter()
1140+
.map(|b| (b.label(), snap.buffer_bytes[b.index()])),
1141+
)?;
1142+
11051143
counter_pairs(
11061144
enc,
11071145
"walshadow_worker_seconds_total",
@@ -1622,7 +1660,9 @@ mod tests {
16221660
shadow_apply_lag_bytes: 12345,
16231661
shadow_apply_lag_seconds: 1.23456,
16241662
shadow_stream_active_connections: 2,
1625-
shadow_stream_dropped_connections_total: 5,
1663+
shadow_stream_sockets_by_event: [9, 5, 3, 1],
1664+
wal_bytes: [4096],
1665+
buffer_bytes: [777],
16261666
..MetricsSnapshot::default()
16271667
};
16281668
let body = render(snap);
@@ -1635,9 +1675,19 @@ mod tests {
16351675
assert!(body.contains("# HELP walshadow_shadow_stream_active_connections"));
16361676
assert!(body.contains("# TYPE walshadow_shadow_stream_active_connections gauge"));
16371677
assert!(body.contains("walshadow_shadow_stream_active_connections 2"));
1638-
assert!(body.contains("# HELP walshadow_shadow_stream_dropped_connections"));
1639-
assert!(body.contains("# TYPE walshadow_shadow_stream_dropped_connections counter"));
1640-
assert!(body.contains("walshadow_shadow_stream_dropped_connections_total 5"));
1678+
assert!(body.contains("# TYPE walshadow_shadow_stream_sockets counter"));
1679+
assert!(body.contains("walshadow_shadow_stream_sockets_total{event=\"accepted\"} 9"));
1680+
assert!(
1681+
body.contains("walshadow_shadow_stream_sockets_total{event=\"closed_slow_client\"} 5")
1682+
);
1683+
assert!(
1684+
body.contains("walshadow_shadow_stream_sockets_total{event=\"closed_by_client\"} 3")
1685+
);
1686+
assert!(body.contains("walshadow_shadow_stream_sockets_total{event=\"closed_error\"} 1"));
1687+
assert!(body.contains("# TYPE walshadow_wal_bytes counter"));
1688+
assert!(body.contains("walshadow_wal_bytes_total{flow=\"walsender_backfill\"} 4096"));
1689+
assert!(body.contains("# TYPE walshadow_buffer_bytes gauge"));
1690+
assert!(body.contains("walshadow_buffer_bytes{buffer=\"walsender_send_queue\"} 777"));
16411691
}
16421692

16431693
/// Unknown rate stays infinite on the wire. prometheus-client spells it

0 commit comments

Comments
 (0)