Skip to content

Commit f16f6c8

Browse files
committed
Reduce transport/sync metric cardinality
1 parent 40cb0f7 commit f16f6c8

4 files changed

Lines changed: 170 additions & 44 deletions

File tree

crates/corro-agent/src/agent/handlers.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,10 @@ pub async fn handle_gossip_to_send(
299299
error!("could not write datagram {addr}: {e}");
300300
return;
301301
}
302-
counter!("corro.peer.datagram.sent.total", "actor_id" => actor_id.to_string())
302+
counter!("corro.peer.datagram.sent.total", "traffic" => "foca")
303303
.increment(1);
304-
counter!("corro.peer.datagram.bytes.sent.total").increment(len as u64);
304+
counter!("corro.peer.datagram.bytes.sent.total", "traffic" => "foca")
305+
.increment(len as u64);
305306
}
306307
.instrument(debug_span!("send_swim_payload", %addr, %actor_id, buf_size = len)),
307308
);
@@ -340,10 +341,16 @@ pub async fn handle_notifications(
340341
MemberAddedResult::NewMember | MemberAddedResult::Removed => {
341342
if matches!(member_added_res, MemberAddedResult::Removed) {
342343
debug!("Member Removed {actor:?} due to member id mismatch");
343-
counter!("corro.gossip.member.removed", "id" => actor.id().0.to_string(), "addr" => actor.addr().to_string()).increment(1);
344+
counter!(
345+
"corro.gossip.member.removed",
346+
"traffic" => "foca",
347+
"kind" => "member_id_mismatch"
348+
)
349+
.increment(1);
344350
} else {
345351
debug!("Member Added {actor:?}");
346-
counter!("corro.gossip.member.added", "id" => actor.id().0.to_string(), "addr" => actor.addr().to_string()).increment(1);
352+
counter!("corro.gossip.member.added", "traffic" => "foca")
353+
.increment(1);
347354
}
348355

349356
let members_len = { agent.members().read().states.len() as u32 };
@@ -386,7 +393,8 @@ pub async fn handle_notifications(
386393
info!("Member Down {actor:?} (removed: {removed})");
387394
if removed {
388395
debug!("Member Down {actor:?}");
389-
counter!("corro.gossip.member.removed", "id" => actor.id().0.to_string(), "addr" => actor.addr().to_string()).increment(1);
396+
counter!("corro.gossip.member.removed", "traffic" => "foca", "kind" => "member_down")
397+
.increment(1);
390398
// actually removed a member
391399
// notify of new cluster size
392400
let member_len = { agent.members().read().states.len() as u32 };
@@ -1065,13 +1073,20 @@ pub async fn handle_sync(
10651073
) -> Result<(), SyncClientError> {
10661074
let sync_state = generate_sync(bookie, agent.actor_id()).await;
10671075

1068-
for (actor_id, needed) in sync_state.need.iter() {
1069-
gauge!("corro.sync.client.needed", "actor_id" => actor_id.to_string())
1070-
.set(needed.len() as f64);
1071-
}
1072-
for (actor_id, version) in sync_state.heads.iter() {
1073-
gauge!("corro.sync.client.head", "actor_id" => actor_id.to_string()).set(version.0 as f64);
1074-
}
1076+
let needed_total = sync_state
1077+
.need
1078+
.values()
1079+
.map(|needed| needed.len() as u64)
1080+
.sum::<u64>();
1081+
gauge!("corro.sync.client.needed.v2", "traffic" => "sync").set(needed_total as f64);
1082+
1083+
let head_max = sync_state
1084+
.heads
1085+
.values()
1086+
.map(|version| version.0)
1087+
.max()
1088+
.unwrap_or_default();
1089+
gauge!("corro.sync.client.head.v2", "traffic" => "sync").set(head_max as f64);
10751090

10761091
let chosen: Vec<(ActorId, SocketAddr)> = {
10771092
let candidates = {

crates/corro-agent/src/api/peer/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ pub async fn parallel_sync(
10881088
}
10891089
trace!(%actor_id, self_actor_id = %agent.actor_id(), "read clock payload");
10901090

1091-
counter!("corro.sync.client.member", "id" => actor_id.to_string(), "addr" => addr.to_string()).increment(1);
1091+
counter!("corro.sync.client.member", "traffic" => "sync").increment(1);
10921092

10931093
let needs = our_sync_state.compute_available_needs(&their_sync_state);
10941094

@@ -1117,9 +1117,8 @@ pub async fn parallel_sync(
11171117
Err(e) => {
11181118
counter!(
11191119
"corro.sync.client.handshake.errors",
1120-
"actor_id" => actor_id.to_string(),
1121-
"addr" => addr.to_string(),
1122-
"error" => e.to_string()
1120+
"traffic" => "sync",
1121+
"kind" => "handshake"
11231122
)
11241123
.increment(1);
11251124
match agg {
@@ -1294,7 +1293,8 @@ pub async fn parallel_sync(
12941293
continue 'servers;
12951294
}
12961295

1297-
counter!("corro.sync.client.req.sent", "actor_id" => server_actor_id.to_string()).increment(req_len as u64);
1296+
counter!("corro.sync.client.req.sent", "traffic" => "sync")
1297+
.increment(req_len as u64);
12981298
}
12991299

13001300
if !send_buf.is_empty() {
@@ -1344,7 +1344,7 @@ pub async fn parallel_sync(
13441344
let changes_len = cmp::max(change.len(), 1);
13451345
// tracing::Span::current().record("changes_len", changes_len);
13461346
count += changes_len;
1347-
counter!("corro.sync.changes.recv", "actor_id" => actor_id.to_string())
1347+
counter!("corro.sync.changes.recv", "traffic" => "sync")
13481348
.increment(changes_len as u64);
13491349

13501350
debug!(
@@ -1598,7 +1598,7 @@ pub async fn serve_sync(
15981598

15991599
debug!(actor_id = %agent.actor_id(), "done writing sync messages (count: {count})");
16001600

1601-
counter!("corro.sync.changes.sent", "actor_id" => their_actor_id.to_string()).increment(count as u64);
1601+
counter!("corro.sync.changes.sent", "traffic" => "sync").increment(count as u64);
16021602

16031603
Ok::<_, SyncError>(count)
16041604
}.instrument(info_span!("process_versions_to_send")),
@@ -1649,7 +1649,7 @@ pub async fn serve_sync(
16491649

16501650
debug!(actor_id = %agent.actor_id(), "done reading sync messages");
16511651

1652-
counter!("corro.sync.requests.recv", "actor_id" => their_actor_id.to_string()).increment(count as u64);
1652+
counter!("corro.sync.requests.recv", "traffic" => "sync").increment(count as u64);
16531653

16541654
Ok(count)
16551655
}.instrument(info_span!("process_version_requests"))

crates/corro-agent/src/broadcast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ fn try_transmit_broadcast(
11021102
error!("could not write to uni stream to {addr}: {e}");
11031103
}
11041104
Ok(Ok(_)) => {
1105-
counter!("corro.peer.stream.bytes.sent.total", "type" => "uni")
1105+
counter!("corro.peer.stream.bytes.sent.total", "traffic" => "broadcast")
11061106
.increment(len as u64);
11071107
}
11081108
}

0 commit comments

Comments
 (0)