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

feat(s2n-quic-core): add aggregate metrics support #2364

Merged
merged 2 commits into from
Nov 4, 2024

Conversation

camshaft
Copy link
Contributor

@camshaft camshaft commented Nov 1, 2024

Description of changes:

This change adds an initial generated metric aggregator for all events that are emitted. This makes it easy to automatically pick up new metrics once they are added without doing any initial work in the subscriber implementation.

Events are emitted as counters automatically. Additionally, they can specify how to aggregate individual fields into the various metric types.

I've also added an example probe metric registry that uses s2n_quic_core::probe::define to emit metrics, which provides USDTs in the compiled application. There are 2 different types of registries. One is dynamic in that it emits register calls with the names and units, and then later calls record for the actual data. The other one is a static mode where all of the probes are defined for each event and known at build time.

Call-outs:

The s2n-quic-events script and its generated output was growing a bit beyond maintainable so I took a minute to refactor it a bit to make things a bit more sustainable. I'll do a follow-up to refactor it the rest of the way.

Testing:

I wired up the new subscriber to the map events tests and verified it printed out, as expected.

$ S2N_LOG=trace cargo test -p s2n-quic-core -p s2n-quic-dc --features probe-tracing 2024-11-01T23:48:30.111761Z 2024-11-02T01:45:46.416029Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=0 name="application_write" units=""
2024-11-02T01:45:46.416065Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=2 name="application_write.bytes.total" units="b"
2024-11-02T01:45:46.416073Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=4 name="application_read" units=""
2024-11-02T01:45:46.416079Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=6 name="application_read.bytes.total" units="b"
2024-11-02T01:45:46.416085Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=8 name="endpoint_initialized" units=""
2024-11-02T01:45:46.416091Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=9 name="path_secret_map_initialized" units=""
2024-11-02T01:45:46.416097Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=11 name="path_secret_map_uninitialized" units=""
2024-11-02T01:45:46.416126Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=14 name="path_secret_map_background_handshake_requested" units=""
2024-11-02T01:45:46.416133Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=15 name="path_secret_map_entry_inserted" units=""
2024-11-02T01:45:46.416139Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=16 name="path_secret_map_entry_ready" units=""
2024-11-02T01:45:46.416145Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=17 name="path_secret_map_entry_replaced" units=""
2024-11-02T01:45:46.416218Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=18 name="unknown_path_secret_packet_sent" units=""
2024-11-02T01:45:46.416238Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=19 name="unknown_path_secret_packet_received" units=""
2024-11-02T01:45:46.416245Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=20 name="unknown_path_secret_packet_accepted" units=""
2024-11-02T01:45:46.416251Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=21 name="unknown_path_secret_packet_rejected" units=""
2024-11-02T01:45:46.416257Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=22 name="unknown_path_secret_packet_dropped" units=""
2024-11-02T01:45:46.416263Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=23 name="replay_definitely_detected" units=""
2024-11-02T01:45:46.416269Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=24 name="replay_potentially_detected" units=""
2024-11-02T01:45:46.416275Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=26 name="replay_detected_packet_sent" units=""
2024-11-02T01:45:46.416281Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=27 name="replay_detected_packet_received" units=""
2024-11-02T01:45:46.416287Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=28 name="replay_detected_packet_accepted" units=""
2024-11-02T01:45:46.416293Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=29 name="replay_detected_packet_rejected" units=""
2024-11-02T01:45:46.416373Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=30 name="replay_detected_packet_dropped" units=""
2024-11-02T01:45:46.416379Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=31 name="stale_key_packet_sent" units=""
2024-11-02T01:45:46.416611Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=32 name="stale_key_packet_received" units=""
2024-11-02T01:45:46.416623Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=33 name="stale_key_packet_accepted" units=""
2024-11-02T01:45:46.416629Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=34 name="stale_key_packet_rejected" units=""
2024-11-02T01:45:46.416636Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::register: id=35 name="stale_key_packet_dropped" units=""
2024-11-02T01:45:46.416644Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::register: id=1 name="application_write.bytes.provided" units="b"
2024-11-02T01:45:46.416651Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::register: id=3 name="application_write.bytes" units="b"
2024-11-02T01:45:46.416657Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::register: id=5 name="application_read.bytes.capacity" units="b"
2024-11-02T01:45:46.416663Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::register: id=7 name="application_read.bytes" units="b"
2024-11-02T01:45:46.416684Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::register: id=10 name="path_secret_map_initialized.capacity" units=""
2024-11-02T01:45:46.416696Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::register: id=12 name="path_secret_map_uninitialized.capacity" units=""
2024-11-02T01:45:46.416703Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::register: id=13 name="path_secret_map_uninitialized.entries" units=""
2024-11-02T01:45:46.416710Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::register: id=25 name="replay_potentially_detected.gap" units=""
2024-11-02T01:45:46.417110Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::path_secret_map_initialized: value=1
2024-11-02T01:45:46.417122Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=9 name="path_secret_map_initialized" units="" value=1
2024-11-02T01:45:46.417132Z TRACE s2n_quic_dc::event::generated::metrics::probe::measure::path_secret_map_initialized__capacity: value=10
2024-11-02T01:45:46.417137Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::record: id=10 name="path_secret_map_initialized.capacity" units="" value=10
2024-11-02T01:45:46.417201Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::path_secret_map_initialized: value=1
2024-11-02T01:45:46.417209Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=9 name="path_secret_map_initialized" units="" value=1
2024-11-02T01:45:46.417217Z TRACE s2n_quic_dc::event::generated::metrics::probe::measure::path_secret_map_initialized__capacity: value=10
2024-11-02T01:45:46.417221Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::record: id=10 name="path_secret_map_initialized.capacity" units="" value=10
2024-11-02T01:45:46.417283Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::path_secret_map_entry_inserted: value=1
2024-11-02T01:45:46.417290Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=15 name="path_secret_map_entry_inserted" units="" value=1
2024-11-02T01:45:46.417331Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::path_secret_map_entry_ready: value=1
2024-11-02T01:45:46.417345Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=16 name="path_secret_map_entry_ready" units="" value=1
2024-11-02T01:45:46.417381Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::path_secret_map_entry_inserted: value=1
2024-11-02T01:45:46.417388Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=15 name="path_secret_map_entry_inserted" units="" value=1
2024-11-02T01:45:46.417399Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::path_secret_map_entry_ready: value=1
2024-11-02T01:45:46.417403Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=16 name="path_secret_map_entry_ready" units="" value=1
2024-11-02T01:45:46.417431Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::unknown_path_secret_packet_received: value=1
2024-11-02T01:45:46.417436Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=19 name="unknown_path_secret_packet_received" units="" value=1
2024-11-02T01:45:46.417448Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::unknown_path_secret_packet_dropped: value=1
2024-11-02T01:45:46.417453Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=22 name="unknown_path_secret_packet_dropped" units="" value=1
2024-11-02T01:45:46.417468Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::stale_key_packet_received: value=1
2024-11-02T01:45:46.417473Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=32 name="stale_key_packet_received" units="" value=1
2024-11-02T01:45:46.417482Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::stale_key_packet_dropped: value=1
2024-11-02T01:45:46.417487Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=35 name="stale_key_packet_dropped" units="" value=1
2024-11-02T01:45:46.417501Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::replay_detected_packet_received: value=1
2024-11-02T01:45:46.417506Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=27 name="replay_detected_packet_received" units="" value=1
2024-11-02T01:45:46.417515Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::replay_detected_packet_dropped: value=1
2024-11-02T01:45:46.417520Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=30 name="replay_detected_packet_dropped" units="" value=1
2024-11-02T01:45:46.417529Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::unknown_path_secret_packet_received: value=1
2024-11-02T01:45:46.417534Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=19 name="unknown_path_secret_packet_received" units="" value=1
2024-11-02T01:45:46.417544Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::unknown_path_secret_packet_rejected: value=1
2024-11-02T01:45:46.417549Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=21 name="unknown_path_secret_packet_rejected" units="" value=1
2024-11-02T01:45:46.417559Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::stale_key_packet_received: value=1
2024-11-02T01:45:46.417563Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=32 name="stale_key_packet_received" units="" value=1
2024-11-02T01:45:46.417575Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::stale_key_packet_rejected: value=1
2024-11-02T01:45:46.417580Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=34 name="stale_key_packet_rejected" units="" value=1
2024-11-02T01:45:46.417591Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::replay_detected_packet_received: value=1
2024-11-02T01:45:46.417595Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=27 name="replay_detected_packet_received" units="" value=1
2024-11-02T01:45:46.417607Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::replay_detected_packet_rejected: value=1
2024-11-02T01:45:46.417613Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=29 name="replay_detected_packet_rejected" units="" value=1
2024-11-02T01:45:46.417621Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::unknown_path_secret_packet_received: value=1
2024-11-02T01:45:46.417626Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=19 name="unknown_path_secret_packet_received" units="" value=1
2024-11-02T01:45:46.417634Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::unknown_path_secret_packet_accepted: value=1
2024-11-02T01:45:46.417639Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=20 name="unknown_path_secret_packet_accepted" units="" value=1
2024-11-02T01:45:46.417660Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::path_secret_map_background_handshake_requested: value=1
2024-11-02T01:45:46.417665Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=14 name="path_secret_map_background_handshake_requested" units="" value=1
2024-11-02T01:45:46.417675Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::stale_key_packet_received: value=1
2024-11-02T01:45:46.417698Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=32 name="stale_key_packet_received" units="" value=1
2024-11-02T01:45:46.417719Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::stale_key_packet_rejected: value=1
2024-11-02T01:45:46.417724Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=34 name="stale_key_packet_rejected" units="" value=1
2024-11-02T01:45:46.417737Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::replay_detected_packet_received: value=1
2024-11-02T01:45:46.417741Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=27 name="replay_detected_packet_received" units="" value=1
2024-11-02T01:45:46.417773Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::replay_detected_packet_rejected: value=1
2024-11-02T01:45:46.417778Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=29 name="replay_detected_packet_rejected" units="" value=1
2024-11-02T01:45:46.417788Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::unknown_path_secret_packet_received: value=1
2024-11-02T01:45:46.417792Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=19 name="unknown_path_secret_packet_received" units="" value=1
2024-11-02T01:45:46.417910Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::unknown_path_secret_packet_rejected: value=1
2024-11-02T01:45:46.417942Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=21 name="unknown_path_secret_packet_rejected" units="" value=1
2024-11-02T01:45:46.417986Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::stale_key_packet_received: value=1
2024-11-02T01:45:46.418004Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=32 name="stale_key_packet_received" units="" value=1
2024-11-02T01:45:46.418068Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::stale_key_packet_accepted: value=1
2024-11-02T01:45:46.418082Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=33 name="stale_key_packet_accepted" units="" value=1
2024-11-02T01:45:46.418111Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::replay_detected_packet_received: value=1
2024-11-02T01:45:46.418122Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=27 name="replay_detected_packet_received" units="" value=1
2024-11-02T01:45:46.418228Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::replay_detected_packet_accepted: value=1
2024-11-02T01:45:46.418236Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=28 name="replay_detected_packet_accepted" units="" value=1
2024-11-02T01:45:46.418260Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::path_secret_map_background_handshake_requested: value=1
2024-11-02T01:45:46.418265Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=14 name="path_secret_map_background_handshake_requested" units="" value=1
2024-11-02T01:45:46.418302Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::path_secret_map_uninitialized: value=1
2024-11-02T01:45:46.418313Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=11 name="path_secret_map_uninitialized" units="" value=1
2024-11-02T01:45:46.418323Z TRACE s2n_quic_dc::event::generated::metrics::probe::measure::path_secret_map_uninitialized__capacity: value=10
2024-11-02T01:45:46.418328Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::record: id=12 name="path_secret_map_uninitialized.capacity" units="" value=10
2024-11-02T01:45:46.418336Z TRACE s2n_quic_dc::event::generated::metrics::probe::measure::path_secret_map_uninitialized__entries: value=1
2024-11-02T01:45:46.418340Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::record: id=13 name="path_secret_map_uninitialized.entries" units="" value=1
2024-11-02T01:45:46.418448Z TRACE s2n_quic_dc::event::generated::metrics::probe::counter::path_secret_map_uninitialized: value=1
2024-11-02T01:45:46.418457Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::counter::record: id=11 name="path_secret_map_uninitialized" units="" value=1
2024-11-02T01:45:46.418465Z TRACE s2n_quic_dc::event::generated::metrics::probe::measure::path_secret_map_uninitialized__capacity: value=10
2024-11-02T01:45:46.418470Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::record: id=12 name="path_secret_map_uninitialized.capacity" units="" value=10
2024-11-02T01:45:46.418477Z TRACE s2n_quic_dc::event::generated::metrics::probe::measure::path_secret_map_uninitialized__entries: value=1
2024-11-02T01:45:46.418481Z TRACE s2n_quic_core::event::metrics::aggregate::probe::dynamic::measure::record: id=13 name="path_secret_map_uninitialized.entries" units="" value=1

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@camshaft camshaft force-pushed the camshaft/event-aggregate branch 2 times, most recently from 9a46404 to 2b346d1 Compare November 1, 2024 22:27
@camshaft camshaft marked this pull request as ready for review November 1, 2024 22:36
@camshaft camshaft force-pushed the camshaft/event-aggregate branch 3 times, most recently from 14fe512 to 628a2ab Compare November 2, 2024 01:38
total_len: usize,

/// The amount that was written
#[measure("bytes", "b")]
#[counter("bytes.total", "b")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: total being less than provided feels like a bit of a weird "total" measurement? Maybe "committed" bytes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i like committed better

impl<'a> Str<'a> {
/// # Safety
///
/// The provided value must end in a `\0` character
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: safety condition includes no interior null bytes as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes good call


/// A str that is also a [`CStr`]
#[derive(Clone, Copy)]
pub struct Str<'a>(usize, &'a CStr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: at least today the length is already stored in CStr as a separate field, so we're duplicating that storage here. Technically there's desire to change that in some future Rust release, but it seems unlikely to happen all that soon. Maybe we should store as &'a str with the knowledge that there's a null terminator at the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I didn't want to rely on the CStr::count_bytes being constant time: https://doc.rust-lang.org/std/ffi/struct.CStr.html#method.count_bytes.

Maybe we should store as &'a str with the knowledge that there's a null terminator at the end?

I wouldn't be able to impl AsRef<CStr> at that point, though, right?

In either case this is always a 'static so I'm not super worries about the extra storage size.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can still impl AsRef with this same code? The lifetimes should still match up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up making it a Str(str) which seems to work

#[inline(always)]
fn count(&self, info: usize, id: usize, value: u64) {
let info = unsafe { INFO.get_unchecked(info) };
let counter = unsafe { self.counters.get_unchecked(id) };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to either have unsafe fn count or a wrapper around the indices that guarantees they've been checked already. AFAICT we always have constant arguments, right? So maybe we can even make this safe and instead just rely on the compiler to drop useless comparisons if we store counters, measures, etc. as Box<[...; length]> -- it seems like we know the needed capacity statically already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The INFO len should be a known value. But the counters aren't currently, though I could make them a Box<[...; length]>, it's just a bit trickier to initialize. Let me try to refactor it to an array and then i can get rid of the unsafe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up just using TryInto<[T; LEN]> for Vec<T> and it worked! Thanks for the suggestion :)

@@ -85,6 +87,8 @@ struct FrameReceived<'a> {
struct PacketLost<'a> {
packet_header: PacketHeader,
path: Path<'a>,
#[measure("bytes_lost", "b")]
#[counter("bytes_lost.total", "b")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to incorporate lost in the name here? It seems like this ought to be already behind some path in any metric etc. (e.g., packet_lost.bytes.total or equivalent).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's a good point. i'll just do bytes and bytes.total

));

record.extend(quote!(
self.recorder.increment_counter(#snake, self.#counter #counter_load as _);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll want counter_swap(0) or something like that here -- I guess it depends on the metric system, some want each counter emission to have distinct counts (e.g., if you have +1, +1, +0, +1 and publishing every 60 seconds you'd emit =1, =1, =0, =1, not =1, =2, =2, =3). Others want the running sum (e.g., Prometheus largely expects a running sum).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These metrics are connection level metrics that we have today, which are recorded once at the end of the connection. I just refactored the code to be in a single location rather than spread across everything. See

self.recorder.increment_counter(#snake, self.#counter #counter_load as _);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so swap or load is the same since we expect this to be terminal (i.e. no more increments afterwards).

@camshaft camshaft enabled auto-merge (squash) November 4, 2024 17:54
@camshaft camshaft merged commit 6369ef3 into main Nov 4, 2024
131 of 132 checks passed
@camshaft camshaft deleted the camshaft/event-aggregate branch November 4, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants