Skip to content

Commit 342bfd2

Browse files
emmaling27Convex, Inc.
authored andcommitted
Metrics for ClientMessage args size (#40989)
following up on #40977, adds metrics for argument size of ClientMessage variants GitOrigin-RevId: 3e54728d67187e811021fa8d2f0af5fb92e394c8
1 parent 8a4d243 commit 342bfd2

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

crates/sync/src/metrics.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,54 @@ pub fn mutation_queue_timer(partition_id: u64) -> StatusTimer {
9999
timer
100100
}
101101

102+
register_convex_histogram!(
103+
SYNC_QUERY_MODIFICATION_ARGS_BYTES,
104+
"Size of query modification args in ClientMessages",
105+
&["partition_id"]
106+
);
107+
pub fn log_query_modification_args_size(partition_id: u64, size: usize) {
108+
log_distribution_with_labels(
109+
&SYNC_QUERY_MODIFICATION_ARGS_BYTES,
110+
size as f64,
111+
vec![StaticMetricLabel::new(
112+
"partition_id",
113+
partition_id.to_string(),
114+
)],
115+
);
116+
}
117+
118+
register_convex_histogram!(
119+
SYNC_MUTATION_ARGS_BYTES,
120+
"Size of mutation args in ClientMessages",
121+
&["partition_id"]
122+
);
123+
pub fn log_mutation_args_size(partition_id: u64, size: usize) {
124+
log_distribution_with_labels(
125+
&SYNC_MUTATION_ARGS_BYTES,
126+
size as f64,
127+
vec![StaticMetricLabel::new(
128+
"partition_id",
129+
partition_id.to_string(),
130+
)],
131+
);
132+
}
133+
134+
register_convex_histogram!(
135+
SYNC_ACTION_ARGS_BYTES,
136+
"Size of action args in ClientMessages",
137+
&["partition_id"]
138+
);
139+
pub fn log_action_args_size(partition_id: u64, size: usize) {
140+
log_distribution_with_labels(
141+
&SYNC_ACTION_ARGS_BYTES,
142+
size as f64,
143+
vec![StaticMetricLabel::new(
144+
"partition_id",
145+
partition_id.to_string(),
146+
)],
147+
);
148+
}
149+
102150
register_convex_counter!(
103151
SYNC_QUERY_FAILED_TOTAL,
104152
"Number of query failures",

crates/sync/src/worker.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ use crate::{
101101
metrics::{
102102
self,
103103
connect_timer,
104+
log_action_args_size,
105+
log_mutation_args_size,
106+
log_query_modification_args_size,
104107
modify_query_to_transition_timer,
105108
mutation_queue_timer,
106109
TypedClientEvent,
@@ -517,6 +520,16 @@ impl<RT: Runtime> SyncWorker<RT> {
517520
new_version,
518521
modifications,
519522
} => {
523+
let total_args_size = modifications
524+
.iter()
525+
.filter_map(|m| match m {
526+
QuerySetModification::Add(q) => {
527+
Some(q.args.iter().map(|v| v.heap_size()).sum::<usize>())
528+
},
529+
QuerySetModification::Remove { .. } => None,
530+
})
531+
.sum();
532+
log_query_modification_args_size(self.partition_id, total_args_size);
520533
self.state
521534
.modify_query_set(base_version, new_version, modifications)?;
522535
self.schedule_update();
@@ -531,6 +544,7 @@ impl<RT: Runtime> SyncWorker<RT> {
531544
args,
532545
component_path,
533546
} => {
547+
log_mutation_args_size(self.partition_id, args.iter().map(|v| v.heap_size()).sum());
534548
let identity = self.state.identity(self.rt.system_time())?;
535549
let mutation_identifier =
536550
self.state.session_id().map(|id| SessionRequestIdentifier {
@@ -638,6 +652,7 @@ impl<RT: Runtime> SyncWorker<RT> {
638652
args,
639653
component_path,
640654
} => {
655+
log_action_args_size(self.partition_id, args.iter().map(|v| v.heap_size()).sum());
641656
let identity = self.state.identity(self.rt.system_time())?;
642657

643658
let api = self.api.clone();

0 commit comments

Comments
 (0)