Skip to content

[ENH]: add request timing to metering #4877

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

Open
wants to merge 15 commits into
base: cooper/chroma-metering-macros-integration
Choose a base branch
from

Conversation

c-gamble
Copy link
Contributor

This PR uses the chroma-metering library introduced in #4868 to add execution timing to requests received on the frontend.

⚠️ #4868 should be merged first.

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

N/A

@c-gamble c-gamble requested review from HammadB and Sicheng-Pan June 18, 2025 17:30
Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

Copy link
Contributor

propel-code-bot bot commented Jun 18, 2025

Integrate New Metering Library and Add Request Execution Timing to Frontend

This major PR removes the legacy metering event system from the Rust frontend and fully adopts the new chroma-metering library (built in #4868) for all metering and request timing logic. Request execution timing is now attached and centrally tracked on all frontend endpoints (read and write). Metering events are now constructed and submitted according to new context-aware patterns, with improved composability and testability. Large sections of the codebase were updated to implement these changes, and the glue code that bound the old tracing/metering is removed. Secondary changes include introducing new serialization helpers for atomic types, plumbing request time metadata, and making related dependency and project structure updates.

Key Changes:
• Adopted chroma-metering for all request metering and execution timing on Rust frontend endpoints
• Removed old tracing/meterevent code and updated usages to the new context pattern
• Added context containers and request timing logic throughout handlers (e.g., fork/add/update/upsert/delete/query/count endpoints)
• Meter events now attach execution metadata and are submitted after response
• Introduced new MeteringAtomicU64 wrapper for reliable atomic metrics serialization
• Updated dependencies, workspace, and build configuration to support new library

Affected Areas:
• Rust frontend service (service_based_frontend.rs, server.rs)
• All collection and record operation APIs/handlers
• Metering event handling
• Project dependency topology (Cargo.toml, Cargo.lock)
• chroma-metering and helper modules

This summary was automatically generated by @propel-code-bot

@c-gamble c-gamble changed the base branch from main to cooper/chroma-metering-macros-integration June 30, 2025 18:16
chroma_metering::with_current(|context| {
context.latest_collection_logical_size_bytes(latest_collection_logical_size_bytes)
context.latest_collection_logical_size_bytes(latest_collection_logical_size_bytes);
context.request_completed_at(Utc::now());
Copy link
Contributor

Choose a reason for hiding this comment

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

given that the event is created in server.rs, should we log the request_completed_at there?

@@ -938,6 +950,12 @@ impl ServiceBasedFrontend {
) -> Result<DeleteCollectionRecordsResponse, DeleteCollectionRecordsError> {
let mut records = Vec::new();

// NOTE(c-gamble): We are using a non-standard metering pattern in which we create a metering context within a
Copy link
Collaborator

@HammadB HammadB Jul 1, 2025

Choose a reason for hiding this comment

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

I think we only need to do latency tracking for

add()/upsert()/update()

get()/query()

Prefer we just do the minimal needed set for the product at hand

@@ -76,16 +84,25 @@ initialize_metering! {
pub tenant: String,
pub database: String,
pub collection_id: String,
pub request_received_at: DateTime<Utc>,
Copy link
Collaborator

@HammadB HammadB Jul 1, 2025

Choose a reason for hiding this comment

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

suggest we only do this for events we intend to display this for

@@ -254,6 +324,21 @@ initialize_metering! {
.log_size_bytes
.store(log_size_bytes, Ordering::SeqCst);
}

/// Handler for [`crate::core::RequestCompletedAt`] capability for collection write contexts
fn __handler_collection_write_request_completed_at(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we be using duration ?

Copy link
Contributor

@Sicheng-Pan Sicheng-Pan Jul 1, 2025

Choose a reason for hiding this comment

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

that can be derived from created_at and completed_at right

Instant works as well

@@ -230,17 +290,27 @@ initialize_metering! {
pub collection_id: String,
#[serde(flatten)]
pub action: WriteAction,
pub request_received_at: DateTime<Utc>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make more sense to either

  • have a start() mutator, that internally sets this, and a finish() mutator that ends it
  • directly hydrate a time_elapsed capability ?

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.

3 participants