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

Feature: add absolute timestamp RaftMetrics::last_quorum_acked #94

Closed
wants to merge 1 commit into from

Conversation

drmingdrmer
Copy link
Owner

@drmingdrmer drmingdrmer commented Jul 24, 2024

RaftMetrics::last_quorum_acked is the absolute timestamp of the most recent time point that is accepted by a quorum via AppendEntries RPC. This field is a wrapped Instant type: SerdeInstant which support serde for Instant. This field is added as a replacement of millis_since_quorum_ack, which is a relative time.

SerdeInstant serialize Instant into a string formatted as "%Y-%m-%dT%H:%M:%S%.9f%z", e.g., "2024-07-24T04:07:32.567025000+0000".

Note: Serialization and deserialization are not perfectly accurate and can be indeterministic, resulting in minor variations each time. These deviations(could be smaller or greater) are typically less than a microsecond (10^-6 seconds).

Checklist

  • Updated guide with pertinent info (may not always apply).
  • Squash down commits to one or two logical commits which clearly describe the work you've done.
  • Unittest is a friend:)

Summary by CodeRabbit

  • New Features

    • Enhanced metrics handling in the Raft protocol with improved serialization for time-related metrics.
    • Introduced a new field, last_quorum_acked, to track leader acknowledgment timing in RaftMetrics and RaftDataMetrics.
    • Added a new module for handling serialization of time instances.
  • Bug Fixes

    • Improved error handling structure by removing deprecated enhancement comments.
  • Tests

    • Expanded test coverage for leader acknowledgment timing in single and multi-node scenarios.
  • Chores

    • Modified KDL script to ensure command output panes remain open after execution for better debugging.

`RaftMetrics::last_quorum_acked` is the absolute timestamp of the most
recent time point that is accepted by a quorum via `AppendEntries` RPC.
This field is a wrapped `Instant` type: `SerdeInstant` which support
serde for `Instant`. This field is added as a replacement of
`millis_since_quorum_ack`, which is a relative time.

`SerdeInstant` serialize `Instant` into a string formatted as
"%Y-%m-%dT%H:%M:%S%.9f%z", e.g., "2024-07-24T04:07:32.567025000+0000".

Note: Serialization and deserialization are not perfectly accurate and
can be indeterministic, resulting in minor variations each time. These
deviations(could be smaller or greater) are typically less than a
microsecond (10^-6 seconds).
Copy link

coderabbitai bot commented Jul 24, 2024

Walkthrough

The recent changes enhance the Raft protocol's metrics handling and error management, introducing better serialization for time-related metrics and refining error documentation. Key updates include the implementation of SerdeInstant for timestamp metrics, deprecation of older fields, and improved logging mechanisms. These modifications aim to increase performance and reliability while maintaining backward compatibility and clarity in error reporting.

Changes

Files Change Summary
openraft/src/core/raft_core.rs Updated RaftMetrics and RaftDataMetrics to use SerdeInstant for last_quorum_acked, enhancing time metrics serialization.
openraft/src/error.rs Removed comments regarding future error subtype enhancements, simplifying error handling.
openraft/src/metrics/mod.rs Introduced serde_instant module and exported SerdeInstant type for improved modularity.
openraft/src/metrics/raft_metrics.rs Added last_quorum_acked field to RaftMetrics and RaftDataMetrics, deprecated millis_since_quorum_ack. Updated documentation and Display implementation.
openraft/src/metrics/serde_instant.rs Implemented SerdeInstant struct for Instant serialization, including conversion and testing functionalities.
openraft/src/metrics/wait_test.rs Added #[allow(deprecated)] to maintain compatibility and initialized last_quorum_acked in metrics.
scripts/check.kdl Removed close_on_exit option from pane definitions to keep output visible after command execution.
tests/tests/fixtures/mod.rs Enhanced set_panic_hook and log_panic for structured logging of panic information.
tests/tests/metrics/t10_leader_last_ack.rs Added leader_last_ack_3_nodes_abs_time test; updated assertions in existing tests for acknowledgment timing validation.

Sequence Diagram(s)

sequenceDiagram
    participant Leader
    participant Quorum
    participant Metrics

    Leader->>Quorum: Sends heartbeat
    Quorum-->>Leader: Acknowledgment received
    Leader->>Metrics: Update last_quorum_acked timestamp
    Metrics-->>Leader: Store updated timestamp
Loading

🐰 Hop, hop, let’s give a cheer,
For metrics bright and changes clear!
With SerdeInstant now in sight,
Our Raft’s performance takes to flight!
From bugs and errors, we shall part,
And celebrate with all our heart! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@mergify mergify bot mentioned this pull request Jul 24, 2024
3 tasks
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ec284cb and 908b5c0.

Files selected for processing (9)
  • openraft/src/core/raft_core.rs (3 hunks)
  • openraft/src/error.rs (1 hunks)
  • openraft/src/metrics/mod.rs (2 hunks)
  • openraft/src/metrics/raft_metrics.rs (7 hunks)
  • openraft/src/metrics/serde_instant.rs (1 hunks)
  • openraft/src/metrics/wait_test.rs (2 hunks)
  • scripts/check.kdl (1 hunks)
  • tests/tests/fixtures/mod.rs (2 hunks)
  • tests/tests/metrics/t10_leader_last_ack.rs (4 hunks)
Files skipped from review due to trivial changes (2)
  • openraft/src/error.rs
  • scripts/check.kdl
Additional context used
GitHub Check: lint
tests/tests/fixtures/mod.rs

[failure] 157-157:
single-character string constant used as pattern


[failure] 164-164:
single-character string constant used as pattern


[failure] 157-157:
single-character string constant used as pattern


[failure] 164-164:
single-character string constant used as pattern


[failure] 157-157:
single-character string constant used as pattern


[failure] 164-164:
single-character string constant used as pattern

Additional comments not posted (28)
openraft/src/metrics/mod.rs (2)

35-35: Addition of serde_instant module looks good.

The new module serde_instant is correctly added to the list of modules.


46-46: Export of SerdeInstant looks good.

The SerdeInstant type is correctly exported for use in other modules.

openraft/src/metrics/serde_instant.rs (8)

1-7: Imports look good.

The necessary modules and traits are correctly imported.


8-23: SerdeInstant struct definition looks good.

The struct is correctly defined with necessary traits.


25-33: Deref implementation looks good.

The Deref trait is correctly implemented for SerdeInstant.


35-41: From implementation looks good.

The From trait is correctly implemented for SerdeInstant.


43-49: fmt::Display implementation looks good.

The fmt::Display trait is correctly implemented for SerdeInstant.


51-61: SerdeInstant methods look good.

The methods for creating a new instance and extracting the inner type are correctly implemented.


63-201: serde_impl module looks good.

The module correctly implements serialization and deserialization for SerdeInstant.


162-201: Tests for SerdeInstant look good.

The tests are comprehensive and cover edge cases.

tests/tests/metrics/t10_leader_last_ack.rs (4)

Line range hint 17-104:
Updates to leader_last_ack_3_nodes look good.

The function correctly includes assertions for millis_since_quorum_ack.


119-210: New function leader_last_ack_3_nodes_abs_time looks good.

The function correctly tests the last_quorum_acked timestamp in a three-node configuration.


Line range hint 216-254:
Updates to leader_last_ack_1_node look good.

The function correctly includes assertions for last_quorum_acked.


256-258: timeout function looks good.

The function correctly provides a timeout duration for the tests.

openraft/src/metrics/wait_test.rs (3)

252-252: LGTM! Suppressing deprecated warnings is acceptable here.

The #[allow(deprecated)] attribute is necessary to maintain functionality without addressing deprecation immediately.


265-265: LGTM! The addition of the last_quorum_acked field enhances metrics tracking.

The last_quorum_acked field provides more precise information about the leader's synchronization status with the cluster.


Line range hint 252-265: LGTM! Initialization of last_quorum_acked to None maintains consistency.

The init_wait_test function correctly initializes the last_quorum_acked field to None, ensuring consistency in the structure's state.

openraft/src/metrics/raft_metrics.rs (6)

10-11: LGTM! Importing SerdeInstant is necessary for serialization and deserialization.

The SerdeInstant type is required for handling the new last_quorum_acked field.


78-78: LGTM! Deprecating millis_since_quorum_ack is appropriate.

The deprecation of millis_since_quorum_ack in favor of last_quorum_acked provides a more precise representation of acknowledgment timing.


93-93: LGTM! Adding last_quorum_acked enhances metrics tracking.

The last_quorum_acked field provides more precise information about the leader's synchronization status with the cluster.


132-141: LGTM! Updating fmt::Display implementation to include last_quorum_acked is correct.

The fmt::Display implementation is correctly updated to format and display the new last_quorum_acked field.


208-208: LGTM! Deprecating millis_since_quorum_ack is appropriate.

The deprecation of millis_since_quorum_ack in favor of last_quorum_acked provides a more precise representation of acknowledgment timing.


223-223: LGTM! Adding last_quorum_acked enhances metrics tracking.

The last_quorum_acked field provides more precise information about the leader's synchronization status with the cluster.

tests/tests/fixtures/mod.rs (2)

135-138: LGTM! Enhancing set_panic_hook to store and call the previous hook is correct.

Storing the previous panic hook and calling it after logging ensures that the original behavior is preserved while adding logging functionality.


157-164: LGTM! Adjusting log_panic to improve log readability and use structured logging is correct.

Replacing newline characters with spaces in the panic message improves readability. Using tracing::error! for structured logging enhances error reporting.

Tools
GitHub Check: lint

[failure] 157-157:
single-character string constant used as pattern


[failure] 164-164:
single-character string constant used as pattern


[failure] 157-157:
single-character string constant used as pattern


[failure] 164-164:
single-character string constant used as pattern


[failure] 157-157:
single-character string constant used as pattern


[failure] 164-164:
single-character string constant used as pattern

openraft/src/core/raft_core.rs (3)

63-63: Import of SerdeInstant is correct.

The import statement is necessary for the changes made to the RaftMetrics and RaftDataMetrics structures.


574-574: Change to last_quorum_acked field in RaftMetrics is correct.

The change to use SerdeInstant for the last_quorum_acked field enhances timestamp serialization capabilities.

However, ensure that all references to last_quorum_acked in the codebase are updated to handle SerdeInstant.

Verification successful

Change to last_quorum_acked field in RaftMetrics is correct.

The change to use SerdeInstant for the last_quorum_acked field enhances timestamp serialization capabilities. The references to last_quorum_acked in the core implementation files (raft_core.rs, leader.rs, raft_metrics.rs) have been updated to handle the new SerdeInstant type correctly.

  • openraft/src/core/raft_core.rs: References to last_quorum_acked have been updated to use SerdeInstant.
  • openraft/src/proposer/leader.rs: Functions related to last_quorum_acked_time handle SerdeInstant.
  • openraft/src/metrics/raft_metrics.rs: The last_quorum_acked field is correctly defined as SerdeInstant.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to `last_quorum_acked` in the codebase are updated to handle `SerdeInstant`.

# Test: Search for the `last_quorum_acked` references. Expect: Only occurances of the new type.
rg --type rust -A 5 $'last_quorum_acked'

Length of output: 14969


589-589: Change to last_quorum_acked field in RaftDataMetrics is correct.

The change to use SerdeInstant for the last_quorum_acked field enhances timestamp serialization capabilities.

However, ensure that all references to last_quorum_acked in the codebase are updated to handle SerdeInstant.

Verification successful

All references to last_quorum_acked in the codebase are correctly updated to handle SerdeInstant.

  • The references in the following files are correctly updated:
    • tests/tests/metrics/t10_leader_last_ack.rs
    • openraft/src/core/raft_core.rs
    • openraft/src/proposer/leader.rs
    • openraft/src/metrics/wait_test.rs
    • openraft/src/metrics/raft_metrics.rs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to `last_quorum_acked` in the codebase are updated to handle `SerdeInstant`.

# Test: Search for the `last_quorum_acked` references. Expect: Only occurances of the new type.
rg --type rust -A 5 $'last_quorum_acked'

Length of output: 14969


Script:

#!/bin/bash
# Description: Verify that all references to `last_quorum_acked` in the codebase are updated to handle `SerdeInstant`.

# Check if `SerdeInstant` is used correctly in the context of `last_quorum_acked` references.
rg --type rust -A 5 'last_quorum_acked' | rg 'SerdeInstant'

Length of output: 465


Script:

#!/bin/bash
# Description: Verify that the references to `last_quorum_acked` in `tests/tests/metrics/t10_leader_last_ack.rs` are updated to handle `SerdeInstant`.

# Check the usages of `last_quorum_acked` in the test file.
rg --type rust 'last_quorum_acked' tests/tests/metrics/t10_leader_last_ack.rs

Length of output: 1160


Script:

#!/bin/bash
# Description: Verify that the references to `last_quorum_acked` in `tests/tests/metrics/t10_leader_last_ack.rs` are updated to handle `SerdeInstant`.

# Display the context around each reference to `last_quorum_acked` in the test file.
rg --type rust -A 5 -B 5 'last_quorum_acked' tests/tests/metrics/t10_leader_last_ack.rs

Length of output: 2998

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.

1 participant