Skip to content

Commit ded554a

Browse files
committed
persist: make aggregate-only per-shard metrics process-level
Six per-shard families were only ever read summed over all shards, so the shard label bought nothing but one series per shard per process. The three `mz_persist_backpressure_*` families keep their names and lose their labels. They are set by the persist_source backpressure operator, which never runs in environmentd, so there every one of those series was a zero. The gauge among them now reads as the sum over live operator instances, each contributing its most recent value through `GaugeContribution` and withdrawing it on drop. The operator's metric bundle, `BackpressureOperatorMetrics`, is shared with the upsert operator. It now holds plain handles, and each owner keeps its own series alive: the persist client through its process-level `BackpressureMetrics`, upsert through the new per-worker `UpsertBackpressureMetrics`. The three `mz_persist_shard_pubsub_diff_*` counters move next to the other pubsub receiver metrics as `mz_persist_pubsub_client_receiver_diff_{applied,not_applied_stale,not_applied_out_of_order}`.
1 parent 04166d3 commit ded554a

10 files changed

Lines changed: 234 additions & 168 deletions

File tree

doc/user/data/metrics.yml

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,24 +1646,15 @@ metrics:
16461646
source: src/persist-client/src/internal/metrics.rs
16471647
visibility: internal
16481648
- name: mz_persist_backpressure_emitted_bytes
1649-
help: A counter with the number of emitted bytes.
1650-
labels:
1651-
- name
1652-
- shard
1649+
help: bytes emitted by backpressure operators
16531650
source: src/persist-client/src/internal/metrics.rs
16541651
visibility: internal
16551652
- name: mz_persist_backpressure_last_backpressured_bytes
1656-
help: The last count of bytes we are waiting to be retired in the operator. This cannot be directly compared to `retired_bytes`, but CAN indicate that backpressure is happening.
1657-
labels:
1658-
- name
1659-
- shard
1653+
help: sum over backpressure operators of the inflight bytes each last stalled on; not comparable to retired bytes, but nonzero growth indicates backpressure is happening
16601654
source: src/persist-client/src/internal/metrics.rs
16611655
visibility: internal
16621656
- name: mz_persist_backpressure_retired_bytes
1663-
help: A counter with the number of bytes retired by downstream processing.
1664-
labels:
1665-
- name
1666-
- shard
1657+
help: bytes retired by processing downstream of backpressure operators
16671658
source: src/persist-client/src/internal/metrics.rs
16681659
visibility: internal
16691660
- name: mz_persist_blob_cache_evictions
@@ -2198,6 +2189,18 @@ metrics:
21982189
help: count of grpc errors received
21992190
source: src/persist-client/src/internal/metrics.rs
22002191
visibility: internal
2192+
- name: mz_persist_pubsub_client_receiver_diff_applied
2193+
help: number of diffs received via pubsub that applied
2194+
source: src/persist-client/src/internal/metrics.rs
2195+
visibility: internal
2196+
- name: mz_persist_pubsub_client_receiver_diff_not_applied_out_of_order
2197+
help: number of diffs received via pubsub that did not apply due to out-of-order delivery
2198+
source: src/persist-client/src/internal/metrics.rs
2199+
visibility: internal
2200+
- name: mz_persist_pubsub_client_receiver_diff_not_applied_stale
2201+
help: number of diffs received via pubsub that did not apply due to staleness
2202+
source: src/persist-client/src/internal/metrics.rs
2203+
visibility: internal
22012204
- name: mz_persist_pubsub_client_receiver_state_push_diff_fast_path
22022205
help: count fast-path state push_diff calls
22032206
source: src/persist-client/src/internal/metrics.rs
@@ -2601,27 +2604,6 @@ metrics:
26012604
- shard
26022605
source: src/persist-client/src/internal/metrics.rs
26032606
visibility: internal
2604-
- name: mz_persist_shard_pubsub_diff_applied
2605-
help: number of diffs received via pubsub that applied
2606-
labels:
2607-
- name
2608-
- shard
2609-
source: src/persist-client/src/internal/metrics.rs
2610-
visibility: internal
2611-
- name: mz_persist_shard_pubsub_diff_not_applied_out_of_order
2612-
help: number of diffs received via pubsub that did not apply due to out-of-order delivery
2613-
labels:
2614-
- name
2615-
- shard
2616-
source: src/persist-client/src/internal/metrics.rs
2617-
visibility: internal
2618-
- name: mz_persist_shard_pubsub_diff_not_applied_stale
2619-
help: number of diffs received via pubsub that did not apply due to staleness
2620-
labels:
2621-
- name
2622-
- shard
2623-
source: src/persist-client/src/internal/metrics.rs
2624-
visibility: internal
26252607
- name: mz_persist_shard_rollup_count
26262608
help: count of rollups by shard
26272609
labels:

src/persist-client/src/cache.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,23 @@ where
415415
"applied pushed diff {}. seqno {} -> {}.",
416416
state.shard_id, seqno_before, state.seqno
417417
);
418-
self.shard_metrics.pubsub_push_diff_applied.inc();
418+
self.metrics.pubsub_client.receiver.diff_applied.inc();
419419
} else {
420420
debug!(
421421
"failed to apply pushed diff {}. seqno {} vs diff {}",
422422
state.shard_id, seqno_before, diff.seqno
423423
);
424424
if diff.seqno <= seqno_before {
425-
self.shard_metrics.pubsub_push_diff_not_applied_stale.inc();
425+
self.metrics
426+
.pubsub_client
427+
.receiver
428+
.diff_not_applied_stale
429+
.inc();
426430
} else {
427-
self.shard_metrics
428-
.pubsub_push_diff_not_applied_out_of_order
431+
self.metrics
432+
.pubsub_client
433+
.receiver
434+
.diff_not_applied_out_of_order
429435
.inc();
430436
}
431437
}

src/persist-client/src/internal/metrics.rs

Lines changed: 57 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use mz_ore::instrument;
2525
use mz_ore::metric;
2626
use mz_ore::metrics::{
2727
ComputedGauge, ComputedIntGauge, ComputedUIntGauge, Counter, DeleteOnDropCounter,
28-
DeleteOnDropGauge, IntCounter, MakeCollector, MetricVecExt, MetricsRegistry, UIntGauge,
29-
UIntGaugeVec, raw,
28+
DeleteOnDropGauge, IntCounter, MakeCollector, MetricsRegistry, UIntGauge, UIntGaugeVec, raw,
3029
};
3130
use mz_ore::stats::histogram_seconds_buckets;
3231
use mz_persist::location::{
@@ -107,6 +106,8 @@ pub struct Metrics {
107106

108107
/// Metrics for the persist sink.
109108
pub sink: SinkMetrics,
109+
/// Metrics for the persist_source backpressure operator.
110+
pub backpressure: BackpressureMetrics,
110111

111112
/// Metrics for S3-backed blob implementation
112113
pub s3_blob: S3BlobMetrics,
@@ -169,6 +170,7 @@ impl Metrics {
169170
inline: InlineMetrics::new(registry),
170171
semaphore: SemaphoreMetrics::new(cfg.clone(), registry.clone()),
171172
sink: SinkMetrics::new(registry),
173+
backpressure: BackpressureMetrics::new(registry),
172174
s3_blob,
173175
blob_hedge: BlobHedgeMetrics::new(registry),
174176
postgres_consensus: PostgresClientMetrics::new(registry, "mz_persist"),
@@ -1283,16 +1285,10 @@ pub struct ShardsMetrics {
12831285
usage_referenced_not_current_state_bytes: mz_ore::metrics::UIntGaugeVec,
12841286
usage_not_leaked_not_referenced_bytes: mz_ore::metrics::UIntGaugeVec,
12851287
usage_leaked_bytes: mz_ore::metrics::UIntGaugeVec,
1286-
pubsub_push_diff_applied: mz_ore::metrics::IntCounterVec,
1287-
pubsub_push_diff_not_applied_stale: mz_ore::metrics::IntCounterVec,
1288-
pubsub_push_diff_not_applied_out_of_order: mz_ore::metrics::IntCounterVec,
12891288
stale_version: mz_ore::metrics::UIntGaugeVec,
12901289
blob_gets: mz_ore::metrics::IntCounterVec,
12911290
blob_sets: mz_ore::metrics::IntCounterVec,
12921291
unconsolidated_snapshot: mz_ore::metrics::IntCounterVec,
1293-
backpressure_emitted_bytes: IntCounterVec,
1294-
backpressure_last_backpressured_bytes: UIntGaugeVec,
1295-
backpressure_retired_bytes: IntCounterVec,
12961292
inline_part_count: UIntGaugeVec,
12971293
inline_part_bytes: UIntGaugeVec,
12981294
compact_batches: UIntGaugeVec,
@@ -1441,21 +1437,6 @@ impl ShardsMetrics {
14411437
help: "data reclaimable by a leaked blob detector",
14421438
var_labels: ["shard", "name"],
14431439
)),
1444-
pubsub_push_diff_applied: registry.register(metric!(
1445-
name: "mz_persist_shard_pubsub_diff_applied",
1446-
help: "number of diffs received via pubsub that applied",
1447-
var_labels: ["shard", "name"],
1448-
)),
1449-
pubsub_push_diff_not_applied_stale: registry.register(metric!(
1450-
name: "mz_persist_shard_pubsub_diff_not_applied_stale",
1451-
help: "number of diffs received via pubsub that did not apply due to staleness",
1452-
var_labels: ["shard", "name"],
1453-
)),
1454-
pubsub_push_diff_not_applied_out_of_order: registry.register(metric!(
1455-
name: "mz_persist_shard_pubsub_diff_not_applied_out_of_order",
1456-
help: "number of diffs received via pubsub that did not apply due to out-of-order delivery",
1457-
var_labels: ["shard", "name"],
1458-
)),
14591440
stale_version: registry.register(metric!(
14601441
name: "mz_persist_shard_stale_version",
14611442
help: "indicates whether the current version of the shard is less than the current version of the code",
@@ -1476,23 +1457,6 @@ impl ShardsMetrics {
14761457
help: "in snapshot_and_read, the number of times consolidating the raw data wasn't enough to produce consolidated output",
14771458
var_labels: ["shard", "name"],
14781459
)),
1479-
backpressure_emitted_bytes: registry.register(metric!(
1480-
name: "mz_persist_backpressure_emitted_bytes",
1481-
help: "A counter with the number of emitted bytes.",
1482-
var_labels: ["shard", "name"],
1483-
)),
1484-
backpressure_last_backpressured_bytes: registry.register(metric!(
1485-
name: "mz_persist_backpressure_last_backpressured_bytes",
1486-
help: "The last count of bytes we are waiting to be retired in \
1487-
the operator. This cannot be directly compared to \
1488-
`retired_bytes`, but CAN indicate that backpressure is happening.",
1489-
var_labels: ["shard", "name"],
1490-
)),
1491-
backpressure_retired_bytes: registry.register(metric!(
1492-
name: "mz_persist_backpressure_retired_bytes",
1493-
help:"A counter with the number of bytes retired by downstream processing.",
1494-
var_labels: ["shard", "name"],
1495-
)),
14961460
inline_part_count: registry.register(metric!(
14971461
name: "mz_persist_shard_inline_part_count",
14981462
help: "count of parts inline in shard metadata",
@@ -1593,16 +1557,10 @@ pub struct ShardMetrics {
15931557
pub gc_finished: DeleteOnDropCounter<AtomicU64, Vec<String>>,
15941558
pub compaction_applied: DeleteOnDropCounter<AtomicU64, Vec<String>>,
15951559
pub cmd_succeeded: DeleteOnDropCounter<AtomicU64, Vec<String>>,
1596-
pub pubsub_push_diff_applied: DeleteOnDropCounter<AtomicU64, Vec<String>>,
1597-
pub pubsub_push_diff_not_applied_stale: DeleteOnDropCounter<AtomicU64, Vec<String>>,
1598-
pub pubsub_push_diff_not_applied_out_of_order: DeleteOnDropCounter<AtomicU64, Vec<String>>,
15991560
pub stale_version: DeleteOnDropGauge<AtomicU64, Vec<String>>,
16001561
pub blob_gets: DeleteOnDropCounter<AtomicU64, Vec<String>>,
16011562
pub blob_sets: DeleteOnDropCounter<AtomicU64, Vec<String>>,
16021563
pub unconsolidated_snapshot: DeleteOnDropCounter<AtomicU64, Vec<String>>,
1603-
pub backpressure_emitted_bytes: Arc<DeleteOnDropCounter<AtomicU64, Vec<String>>>,
1604-
pub backpressure_last_backpressured_bytes: Arc<DeleteOnDropGauge<AtomicU64, Vec<String>>>,
1605-
pub backpressure_retired_bytes: Arc<DeleteOnDropCounter<AtomicU64, Vec<String>>>,
16061564
pub inline_part_count: DeleteOnDropGauge<AtomicU64, Vec<String>>,
16071565
pub inline_part_bytes: DeleteOnDropGauge<AtomicU64, Vec<String>>,
16081566
pub compact_batches: DeleteOnDropGauge<AtomicU64, Vec<String>>,
@@ -1686,15 +1644,6 @@ impl ShardMetrics {
16861644
usage_leaked_bytes: shards_metrics
16871645
.usage_leaked_bytes
16881646
.get_delete_on_drop_metric(vec![shard.clone(), name.to_string()]),
1689-
pubsub_push_diff_applied: shards_metrics
1690-
.pubsub_push_diff_applied
1691-
.get_delete_on_drop_metric(vec![shard.clone(), name.to_string()]),
1692-
pubsub_push_diff_not_applied_stale: shards_metrics
1693-
.pubsub_push_diff_not_applied_stale
1694-
.get_delete_on_drop_metric(vec![shard.clone(), name.to_string()]),
1695-
pubsub_push_diff_not_applied_out_of_order: shards_metrics
1696-
.pubsub_push_diff_not_applied_out_of_order
1697-
.get_delete_on_drop_metric(vec![shard.clone(), name.to_string()]),
16981647
stale_version: shards_metrics
16991648
.stale_version
17001649
.get_delete_on_drop_metric(vec![shard.clone(), name.to_string()]),
@@ -1707,21 +1656,6 @@ impl ShardMetrics {
17071656
unconsolidated_snapshot: shards_metrics
17081657
.unconsolidated_snapshot
17091658
.get_delete_on_drop_metric(vec![shard.clone(), name.to_string()]),
1710-
backpressure_emitted_bytes: Arc::new(
1711-
shards_metrics
1712-
.backpressure_emitted_bytes
1713-
.get_delete_on_drop_metric(vec![shard.clone(), name.to_string()]),
1714-
),
1715-
backpressure_last_backpressured_bytes: Arc::new(
1716-
shards_metrics
1717-
.backpressure_last_backpressured_bytes
1718-
.get_delete_on_drop_metric(vec![shard.clone(), name.to_string()]),
1719-
),
1720-
backpressure_retired_bytes: Arc::new(
1721-
shards_metrics
1722-
.backpressure_retired_bytes
1723-
.get_delete_on_drop_metric(vec![shard.clone(), name.to_string()]),
1724-
),
17251659
inline_part_count: shards_metrics
17261660
.inline_part_count
17271661
.get_delete_on_drop_metric(vec![shard.clone(), name.to_string()]),
@@ -2017,6 +1951,43 @@ impl SinkWorkerMetrics {
20171951
}
20181952
}
20191953

1954+
/// Metrics for the `persist_source` backpressure operator, summed over every
1955+
/// instance of the operator in the process. Like [SinkMetrics], these belong
1956+
/// to a dataflow operator rather than the client, but the client owns the only
1957+
/// registry the operator can reach.
1958+
#[derive(Debug)]
1959+
pub struct BackpressureMetrics {
1960+
/// Bytes emitted by backpressure operators.
1961+
pub emitted_bytes: IntCounter,
1962+
/// Sum over live operator instances of the inflight bytes each one most
1963+
/// recently stalled on. Instances contribute deltas, so the sum stays exact
1964+
/// as operators start and stop.
1965+
pub last_backpressured_bytes: UIntGauge,
1966+
/// Bytes retired by processing downstream of backpressure operators.
1967+
pub retired_bytes: IntCounter,
1968+
}
1969+
1970+
impl BackpressureMetrics {
1971+
fn new(registry: &MetricsRegistry) -> Self {
1972+
BackpressureMetrics {
1973+
emitted_bytes: registry.register(metric!(
1974+
name: "mz_persist_backpressure_emitted_bytes",
1975+
help: "bytes emitted by backpressure operators",
1976+
)),
1977+
last_backpressured_bytes: registry.register(metric!(
1978+
name: "mz_persist_backpressure_last_backpressured_bytes",
1979+
help: "sum over backpressure operators of the inflight bytes each last \
1980+
stalled on; not comparable to retired bytes, but nonzero growth \
1981+
indicates backpressure is happening",
1982+
)),
1983+
retired_bytes: registry.register(metric!(
1984+
name: "mz_persist_backpressure_retired_bytes",
1985+
help: "bytes retired by processing downstream of backpressure operators",
1986+
)),
1987+
}
1988+
}
1989+
}
1990+
20201991
/// A minimal set of metrics imported into honeycomb for alerting.
20211992
#[derive(Debug)]
20221993
pub struct AlertsMetrics {
@@ -2165,6 +2136,10 @@ pub struct PubSubClientReceiverMetrics {
21652136
pub(crate) state_pushed_diff_fast_path: IntCounter,
21662137
pub(crate) state_pushed_diff_slow_path_succeeded: IntCounter,
21672138
pub(crate) state_pushed_diff_slow_path_failed: IntCounter,
2139+
2140+
pub(crate) diff_applied: IntCounter,
2141+
pub(crate) diff_not_applied_stale: IntCounter,
2142+
pub(crate) diff_not_applied_out_of_order: IntCounter,
21682143
}
21692144

21702145
impl PubSubClientReceiverMetrics {
@@ -2196,6 +2171,18 @@ impl PubSubClientReceiverMetrics {
21962171
name: "mz_persist_pubsub_client_receiver_state_push_diff_slow_path_failed",
21972172
help: "count of unsuccessful slow-path state push_diff calls",
21982173
)),
2174+
diff_applied: registry.register(metric!(
2175+
name: "mz_persist_pubsub_client_receiver_diff_applied",
2176+
help: "number of diffs received via pubsub that applied",
2177+
)),
2178+
diff_not_applied_stale: registry.register(metric!(
2179+
name: "mz_persist_pubsub_client_receiver_diff_not_applied_stale",
2180+
help: "number of diffs received via pubsub that did not apply due to staleness",
2181+
)),
2182+
diff_not_applied_out_of_order: registry.register(metric!(
2183+
name: "mz_persist_pubsub_client_receiver_diff_not_applied_out_of_order",
2184+
help: "number of diffs received via pubsub that did not apply due to out-of-order delivery",
2185+
)),
21992186
}
22002187
}
22012188
}

src/persist-client/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub mod iter;
7878
pub mod metrics {
7979
//! Utilities related to metrics.
8080
pub use crate::internal::metrics::{
81-
Metrics, SinkMetrics, SinkWorkerMetrics, UpdateDelta, encode_ts_metric,
81+
BackpressureMetrics, Metrics, SinkMetrics, SinkWorkerMetrics, UpdateDelta, encode_ts_metric,
8282
};
8383
}
8484
pub mod operators {

0 commit comments

Comments
 (0)