You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds serialization/deserialization duration and byte-size metrics to rivetkit-core, wrapping hot paths in persist.rs and registry/http.rs via a new serde_metrics module. The approach (LazyLock collector struct, measure_serialize/measure_deserialize helpers) is consistent with how actor/metrics.rs works, and the crate::time::Instant alias ensures WASM compatibility.
serde_metrics.rs:153 — register_metric is already defined in actor/metrics.rs
actor/metrics.rs contains an identical generic helper (same bounds, same body) differing only in the log message. Two copies of this helper will drift over time. The helper should be extracted to a shared location (e.g. a metrics submodule or the existing actor/metrics.rs re-exported) and reused here.
serde_metrics.rs:25 — serde_size_buckets() should be a constant in engine/packages/metrics/src/buckets.rs, not a private fn
CLAUDE.md: "Add a new constant to buckets.rs only if no existing constant covers the value range." The byte-size range (16–16M bytes) has no existing constant there; MICRO_BUCKETS/BUCKETS/PAGE_COUNT_BUCKETS are all time-domain or page-count values. The fix is to add pub const BYTE_SIZE_BUCKETS: &[f64] to buckets.rs (same as this PR's values). As a private fn it can't be reused from other crates that add byte-size histograms later.
serde_metrics.rs:26 — Missing 512-byte bucket creates a 4× gap between 256 and 1024
The sequence jumps 256.0 → 1024.0. Every other adjacent step in the array is 2–4×, but this particular gap is 4× in a byte range where typical actor state and action payloads land. Adding 512.0 between those two entries brings the resolution in line with the rest of the buckets without changing anything else.
registry/http.rs:778 — encoding_format_label duplicates the HttpResponseEncoding-to-string match already in content_type_for_encoding
Two separate match arms over the same enum mean adding a new HttpResponseEncoding variant requires updating two free functions. While exhaustive matching catches the missing arm at compile time, the string used in metrics and the string used in content-type headers live in different places. An impl HttpResponseEncoding { fn format_label(&self) -> &'static str } method (or a single shared helper) would co-locate the knowledge.
serde_metrics.rs:91,116 — serialize_size and deserialize_size have asymmetric success semantics
serialize_size records bytes only on Ok (output bytes of successful encodes). deserialize_size records bytes unconditionally before the closure runs (input bytes for all attempts, including failures). Both histograms are named *_size and look symmetric on a dashboard, but a failed-decode retry will inflate deserialize_size without a corresponding serialize_size entry. The module doc comment mentions this for deserialize but does not explain why the two differ, making it easy for dashboard authors to treat them as equivalent when they are not. Consider either: (a) making deserialize only record on success too, or (b) adding a result label (ok/err) so the asymmetry becomes explicit and queryable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.