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: snapshot tests during CI #137

Merged
merged 24 commits into from
Mar 7, 2025
Merged

feat: snapshot tests during CI #137

merged 24 commits into from
Mar 7, 2025

Conversation

jeluard
Copy link
Contributor

@jeluard jeluard commented Mar 6, 2025

Summary by CodeRabbit

  • New Features

    • Added automated snapshot testing to the CI pipeline with improved caching and extended execution time.
    • Introduced new build commands to simplify snapshot data management and node initialisation, including environment configuration checks.
    • Enhanced test concurrency by allowing multiple tests to access shared database snapshots safely.
    • Implemented a database pruning step in the CI workflow to manage storage effectively.
  • Bug Fixes

    • Updated test cases to ensure compatibility with the new snapshot interface.

Copy link

coderabbitai bot commented Mar 6, 2025

Walkthrough

This pull request introduces a new job to the CI workflow and a comprehensive Makefile. The CI configuration now includes a snapshots job that runs on ubuntu-latest, executing steps such as repository checkout, caching, bootstrapping, and snapshot testing when the pull request is not a draft. The Makefile adds several targets for managing snapshot downloads, importing snapshots, headers, and nonces, enforcing the peer address, and running the node.

Changes

File Path Change Summary
.github/workflows/CI.yml Added a new snapshots job that runs on ubuntu-latest, conditioned on non-draft PRs. Includes steps for checkout, caching (rust-cache and ledger/chain DB caches), bootstrapping the node when caches are missed, and running tests with a 30-minute timeout.
Makefile Introduced multiple targets: all (help), snapshots, download-haskell-config, import-snapshots, import-headers, import-nonces, bootstrap, enforce-peer-address, and run. These targets coordinate snapshot handling, header/nonce import, and node bootstrapping using AMARU_PEER_ADDRESS.
crates/amaru-stores/src/rocksdb/mod.rs Added a new public method for_epoch_with in RocksDB, refactoring for_epoch to use this new method for instance creation, improving code structure without altering functionality.
crates/amaru/tests/rewards.rs Replaced open_db with a new function db for concurrent access to database snapshots, ensuring thread safety. Updated test cases to use db, commented out some tests for future re-enablement, and modified import statements accordingly.
.github/workflows/NightlySynchronization.yml Removed a step generating a timestamp for cache keys, simplifying the key to cardano-node-ogmios-${{ matrix.network }} and added a step to prune old immutable chunks from the database.

Sequence Diagram(s)

sequenceDiagram
    participant PR as "Pull Request"
    participant CI as "CI Runner"
    participant Checkout as "actions/checkout"
    participant Cache as "actions/cache & rust-cache"
    participant Bootstrap as "Bootstrap Step"
    participant Test as "Cargo Test (snapshot tests)"

    PR->>CI: Trigger CI Job (if not draft)
    CI->>Checkout: Checkout code
    CI->>Cache: Execute caching steps for ledger.db & chain.db
    Cache-->>CI: Cache hit/miss signal
    alt Cache Miss
      CI->>Bootstrap: Run amaru bootstrap step
    end
    CI->>Test: Run node process and execute cargo test
Loading
sequenceDiagram
    participant User as "User (Make Command)"
    participant Enforce as "enforce-peer-address"
    participant Download as "download-snapshots"
    participant ImportSnap as "import-snapshots"
    participant ImportHead as "import-headers"
    participant ImportNonce as "import-nonces"
    participant Node as "Node Process"

    User->>Enforce: Run peer address enforcement
    Enforce-->>User: Validate AMARU_PEER_ADDRESS
    User->>Download: Execute download-snapshots target
    Download-->>User: Create snapshot directory and fetch data
    User->>ImportSnap: Trigger import-snapshots
    User->>ImportHead: Trigger import-headers
    User->>ImportNonce: Trigger import-nonces
    User->>Node: Run node with snapshots, headers, and nonces imported
Loading

Poem

In our CI lane, a snapshot’s born anew,
With targets in the Makefile shining through.
From caching tricks to bootstrapping delight,
Our node runs in style, everything feels right.
Cheers to progress, a fine code brew—huzzah, old sport!
🚀✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bcf08da and 919fbaa.

📒 Files selected for processing (2)
  • .github/workflows/CI.yml (1 hunks)
  • .github/workflows/NightlySynchronization.yml (1 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

🪧 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 resolve resolve all the CodeRabbit review comments.
  • @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.

@jeluard jeluard marked this pull request as ready for review March 6, 2025 16:37
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

🧹 Nitpick comments (8)
.github/workflows/CI.yml (3)

108-116: Caching Ledger DB: Update the Action Version

The caching step for ledger.db uses actions/cache@v3, which static analysis flags as a tad outdated. Consider updating it (if a newer version is available) to benefit from bug fixes and improvements.

🧰 Tools
🪛 actionlint (1.7.4)

110-110: the runner of "actions/cache@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


117-122: Caching Chain DB: A Similar Upgrade is Warranted

As with the ledger cache, the chain cache also employs actions/cache@v3. It might be a good idea to update this action too, ensuring the CI workflow remains robust and up-to-date.

🧰 Tools
🪛 actionlint (1.7.4)

117-117: the runner of "actions/cache@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


128-139: Run Node Block: Piped Process ID Caution

The approach of running make and piping its output into a whilst loop to monitor for a shutdown signal is inventive. However, using $! inside a piped loop can sometimes be a bit dodgy due to subshell behaviour. It might be worth verifying that the correct process ID is being captured so that the stop signal is effectively delivered.

Makefile (5)

4-7: Help Target: Friendly Guidance at Your Fingertips

The help target is a delightful addition, offering users a quick reference for available commands. The awk magic is clever, though a brief comment explaining its mechanics might save future maintainers from scratching their heads.


8-17: Download Snapshots: Consider Robust Error Handling

This target efficiently creates a snapshots directory and fetches snapshot data. A small suggestion: adding error checking (perhaps via curl’s -f option or verifying exit statuses) could make the process even more resilient if the network gets a bit cheeky.


18-23: Import Snapshots: Hard-Coded Paths—Might Need a Softening

The logic here is sound, but the snapshot file paths are hard-coded. If these filenames are subject to change, consider parameterising them. That way, future tweaks won’t turn into a right faff.


24-33: Import Headers: Duplicate Invocations Require a Note

Two separate invocations for importing headers with different starting points are intriguing. If both are necessary, a brief comment explaining the rationale would be grand, helping others understand the need for the dual calls.


34-41: Import Nonces: Keep an Eye on Hard-Coded Parameters

The nonces import command is precise but heavily hard-coded. Should those values ever need tweaking, adding a comment or refactoring to make them configurable could save a lot of future bother.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 07871e1 and c250b71.

📒 Files selected for processing (2)
  • .github/workflows/CI.yml (1 hunks)
  • Makefile (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/CI.yml

110-110: the runner of "actions/cache@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


117-117: the runner of "actions/cache@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build on windows-latest with target x86_64-pc-windows-msvc
  • GitHub Check: Build on macos-latest with target aarch64-apple-darwin
  • GitHub Check: Build on ubuntu-latest with target x86_64-unknown-linux-gnu
  • GitHub Check: Sanity
  • GitHub Check: Snapshots
🔇 Additional comments (6)
.github/workflows/CI.yml (3)

99-105: Snapshots Job Addition: Neat and Conditional!

The new snapshots job is a smart addition—it ensures that snapshot tests run only when the pull request isn’t still in draft mode. Jolly good move to prevent any premature resource usage.


123-127: Bootstrap Amaru Step: Clever Conditional Execution

The conditional execution of make bootstrap when the cache isn’t hit is a smart strategy. Just have a quick gander to ensure the bootstrap target in your Makefile gracefully handles any edge cases.


140-141: Run Tests Step: Straightforward and Spot On

The step to execute tests is succinct and clear. No worries here—everything appears to be in order.

Makefile (3)

42-42: Bootstrap Target: Neat Orchestration of Steps

Combining the import-headers, import-snapshots, and import-nonces into a single bootstrap target is a smart touch. Just ensure that if any sub-target fails, it’s handled as intended.


44-48: Enforce Peer Address: A Solid Safety Check

This target neatly guards against running the node without a defined AMARU_PEER_ADDRESS. It’s a simple yet effective barrier against potential misconfigurations.


50-51: Run Target: All Systems Go!

The run target, by building on the enforce-peer-address check, is crisp and functional. It sets the node rolling with clarity.

@KtorZ KtorZ changed the base branch from main to jeluard/dreps March 7, 2025 08:12
@KtorZ KtorZ force-pushed the jeluard/ci-snapshots branch from c250b71 to 4ab0004 Compare March 7, 2025 08:23
@KtorZ KtorZ changed the base branch from jeluard/dreps to main March 7, 2025 08:29
KtorZ and others added 3 commits March 7, 2025 09:35
  This is the default behaviour when running 'cargo test', and it's been slightly annoying to have to run them one by one every time. Now, they happily all run at once by sharing and reusing connections to the on-disk snapshots.

Signed-off-by: KtorZ <[email protected]>
@KtorZ KtorZ force-pushed the jeluard/ci-snapshots branch 2 times, most recently from b8a8cc9 to 9fb2111 Compare March 7, 2025 08:44
KtorZ added 4 commits March 7, 2025 10:03
  Interstingly enough, a 'cache-hit' value of 'false' does not indicate
  a miss. It indicates a hit on a restore key (and not a _direct_ hit).

  A miss is denoted by an empty string. :|

Signed-off-by: KtorZ <[email protected]>
@KtorZ KtorZ force-pushed the jeluard/ci-snapshots branch 2 times, most recently from d4c731b to 82efb1e Compare March 7, 2025 09:40
@KtorZ KtorZ force-pushed the jeluard/ci-snapshots branch from b63f086 to 4ff9688 Compare March 7, 2025 10:12
@KtorZ KtorZ force-pushed the jeluard/ci-snapshots branch from ff7f78a to 1cbf29c Compare March 7, 2025 14:25
@KtorZ KtorZ merged commit 543e03e into main Mar 7, 2025
10 checks passed
@KtorZ KtorZ deleted the jeluard/ci-snapshots branch March 7, 2025 16:21
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