Skip to content

Add ConditionedCounter#6295

Merged
JojiiOfficial merged 1 commit intodevfrom
conditioned_counter
Apr 3, 2025
Merged

Add ConditionedCounter#6295
JojiiOfficial merged 1 commit intodevfrom
conditioned_counter

Conversation

@JojiiOfficial
Copy link
Contributor

@JojiiOfficial JojiiOfficial commented Apr 2, 2025

Adds a new wrapper for HwCounterCell that allows conditioned counting.
This is needed in places where we can't use a multiplier of 0 to disable counting, like mmap bool index.

An example of how this can be used can be found in #6296.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 2, 2025

📝 Walkthrough

Walkthrough

The changes update the hardware counter system by introducing new components and extending existing ones. A new structure, ConditionedCounter, is added to conditionally accumulate measurement data into a parent counter. This structure implements the Deref and Drop traits and includes unit tests to validate its behavior. A new method hw_data is introduced in the hardware measurement accumulator, HwMeasurementAcc, to atomically load multiple hardware counter values and return a HardwareData instance. The HardwareCounterCell now implements the From trait, enabling conversion from a reference of a hardware counter cell to a consolidated HardwareData object. Additionally, the HardwareData struct gains an implementation of the Add trait, allowing its instances to be summed field-wise. Lastly, the module’s export list has been updated to include the new conditioned_counter module.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/common/common/src/counter/conditioned_counter.rs (1)

1-114: Consider adding multi-thread safety documentation.

The code appears to handle synchronization through the use of atomic operations in the underlying counters, but it would be helpful to explicitly document whether ConditionedCounter is thread-safe and any constraints on its usage in concurrent contexts.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d107b8 and 4cc2c2e.

📒 Files selected for processing (5)
  • lib/common/common/src/counter/conditioned_counter.rs (1 hunks)
  • lib/common/common/src/counter/hardware_accumulator.rs (1 hunks)
  • lib/common/common/src/counter/hardware_counter.rs (1 hunks)
  • lib/common/common/src/counter/hardware_data.rs (2 hunks)
  • lib/common/common/src/counter/mod.rs (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
lib/common/common/src/counter/hardware_accumulator.rs (1)
lib/common/common/src/counter/hardware_counter.rs (6)
  • cpu_counter (123-125)
  • payload_io_read_counter (128-130)
  • payload_io_write_counter (143-145)
  • vector_io_write_counter (153-155)
  • payload_index_io_read_counter (133-135)
  • payload_index_io_write_counter (138-140)
lib/common/common/src/counter/conditioned_counter.rs (2)
lib/common/common/src/counter/hardware_counter.rs (4)
  • new (42-55)
  • disposable (60-73)
  • from (202-206)
  • cpu_counter (123-125)
lib/common/common/src/counter/hardware_accumulator.rs (4)
  • new (111-117)
  • disposable (122-128)
  • get_cpu (22-24)
  • get_cpu (161-163)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: test-snapshot-operations-s3-minio
  • GitHub Check: test-shard-snapshot-api-s3-minio
  • GitHub Check: test-low-resources
  • GitHub Check: Basic TLS/HTTPS tests
  • GitHub Check: test-consistency
  • GitHub Check: test (macos-latest)
  • GitHub Check: test-consensus-compose
  • GitHub Check: test (windows-latest)
  • GitHub Check: test-consensus
  • GitHub Check: test
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (13)
lib/common/common/src/counter/mod.rs (1)

1-1: LGTM: New module added for the ConditionedCounter

The counter module has been properly updated to export the new conditioned_counter module, making the new functionality accessible to other parts of the codebase.

lib/common/common/src/counter/hardware_counter.rs (1)

201-207: LGTM: Efficient implementation of From trait for HardwareData

The implementation correctly combines hardware counter data from both the counter itself and its accumulator, utilizing the new hw_data() method. This simplifies conversion of counter data to a consolidated HardwareData object.

lib/common/common/src/counter/hardware_data.rs (2)

1-2: LGTM: Add the std::ops::Add import

Correctly imported the Add trait to implement field-wise addition for HardwareData.


15-29: LGTM: Well-implemented Add trait for HardwareData

The implementation correctly performs field-wise addition of all hardware counters, which will be useful for combining data from multiple sources. This supports the new functionality needed by the ConditionedCounter.

lib/common/common/src/counter/hardware_accumulator.rs (1)

189-209: LGTM: Clean implementation of hw_data method

The hw_data() method efficiently retrieves all counter values from the request_drain in a single operation, returning a consolidated HardwareData structure. This reduces code duplication compared to calling individual getters for each counter type.

lib/common/common/src/counter/conditioned_counter.rs (8)

1-14: Structure and documentation look good.

The struct is well-documented with clear comments explaining its purpose and usage. The inclusion of lifetime parameter 'a is appropriate for storing a reference to the parent counter.


16-24: Implementation is concise and correct.

The constructor initializes the struct with a condition flag, parent reference, and a disposable temporary counter. The use of HardwareCounterCell::disposable() is appropriate here as it creates a temporary counter that doesn't persist measurements on its own.


26-32: Deref implementation enables transparent usage.

Good implementation of Deref that allows ConditionedCounter to be used where a HardwareCounterCell is expected. This makes the wrapper non-intrusive to existing code.


34-42: Drop implementation correctly handles conditional accumulation.

The Drop implementation performs accumulation only when the condition is true, effectively implementing the conditional counting behavior. This ensures measurements are only transferred to the parent counter when needed.


44-61: Test cases verify non-accumulation when condition is false.

This test correctly verifies that when the condition is false, no values are accumulated in the parent counter or its accumulator, which is the expected behavior.


63-75: Test cases verify accumulation when condition is true.

This test correctly verifies that when the condition is true, values are properly accumulated in the parent's accumulator, not directly in the parent's counter cells. The comment on line 73 is helpful in clarifying this distinction.


77-94: Test verifies more complex indirect counting scenario.

Good test case that verifies a more complex usage pattern of creating new accumulators and counter cells from the conditioned counter. This helps ensure the wrapper works correctly in real-world usage scenarios.


96-114: Test validates integration with HwMeasurementAcc.

This final test confirms that the ConditionedCounter works correctly when its parent is obtained from a HwMeasurementAcc, ensuring broader compatibility across the measurement system.

@generall generall requested a review from Copilot April 3, 2025 07:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new wrapper, ConditionedCounter, for HardwareCounterCell to enable conditioned accumulation of hardware counter values when counting must be optionally disabled. Key changes include:

  • Adding a new module (conditioned_counter) to the counter module.
  • Defining an Add implementation for HardwareData to support accumulation.
  • Implementing ConditionedCounter with condition-based accumulation and associated tests.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/common/common/src/counter/mod.rs Adds the conditioned_counter module entry to the counter module.
lib/common/common/src/counter/hardware_data.rs Implements the Add trait for HardwareData to enable summing of hardware metrics.
lib/common/common/src/counter/hardware_counter.rs Adds a conversion from HardwareCounterCell to HardwareData for accumulating counter values.
lib/common/common/src/counter/hardware_accumulator.rs Adds a method to extract HardwareData from the hardware accumulator counters.
lib/common/common/src/counter/conditioned_counter.rs Implements the ConditionedCounter wrapper with conditional accumulation and provides tests for various scenarios.
Comments suppressed due to low confidence (1)

lib/common/common/src/counter/conditioned_counter.rs:13

  • [nitpick] Consider renaming 'tmp' to a more descriptive name such as 'disposable_counter' to improve code clarity.
tmp: HardwareCounterCell,

@JojiiOfficial JojiiOfficial merged commit fe42d41 into dev Apr 3, 2025
17 checks passed
@JojiiOfficial JojiiOfficial deleted the conditioned_counter branch April 3, 2025 08:13
pull bot pushed a commit to kp-forks/qdrant that referenced this pull request Apr 21, 2025
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.

5 participants