Skip to content

feat: Add subnet-node-diff command to dre CLI #1567

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pietrodimarco-dfinity
Copy link
Contributor

This commit introduces a new command subnet-node-diff to the dre CLI tool.

The command takes two registry versions (--version1 and --version2) as input and an optional output file path (-o or --output). It then calculates the number of nodes assigned to each subnet for every registry version from version1 + 1 up to version2.

If the node count for a subnet changes at a particular version (compared to the immediately preceding version), or if a subnet is newly added or removed, this change is recorded.

The output is a JSON array, where each element represents a subnet that experienced at least one change in its node count within the specified version range. Each subnet object includes its ID and a list of "changes," where each change entry specifies the registry version and the new node count at that version.

Key changes:

  • Added rs/cli/src/commands/subnet_node_diff.rs implementing the command logic.
  • Defined SubnetNodeDiff, ChangeEntry, and SubnetChangeLog structs for command arguments and JSON serialization.
  • Implemented get_subnet_node_counts helper to fetch and count nodes per subnet for a given registry version.
  • Integrated the command into rs/cli/src/commands/mod.rs and rs/cli/src/commands/main_command.rs.
  • Added a comprehensive suite of unit tests with mocking for DreContext and LocalStoreImpl to validate various scenarios, including node count changes, subnet additions/removals, and error conditions.

This commit introduces a new command `subnet-node-diff` to the `dre` CLI tool.

The command takes two registry versions (`--version1` and `--version2`) as input and an optional output file path (`-o` or `--output`). It then calculates the number of nodes assigned to each subnet for every registry version from `version1 + 1` up to `version2`.

If the node count for a subnet changes at a particular version (compared to the immediately preceding version), or if a subnet is newly added or removed, this change is recorded.

The output is a JSON array, where each element represents a subnet that experienced at least one change in its node count within the specified version range. Each subnet object includes its ID and a list of "changes," where each change entry specifies the registry version and the new node count at that version.

Key changes:
- Added `rs/cli/src/commands/subnet_node_diff.rs` implementing the command logic.
- Defined `SubnetNodeDiff`, `ChangeEntry`, and `SubnetChangeLog` structs for command arguments and JSON serialization.
- Implemented `get_subnet_node_counts` helper to fetch and count nodes per subnet for a given registry version.
- Integrated the command into `rs/cli/src/commands/mod.rs` and `rs/cli/src/commands/main_command.rs`.
- Added a comprehensive suite of unit tests with mocking for `DreContext` and `LocalStoreImpl` to validate various scenarios, including node count changes, subnet additions/removals, and error conditions.
@pietrodimarco-dfinity pietrodimarco-dfinity requested a review from a team as a code owner May 28, 2025 10:46
@pietrodimarco-dfinity pietrodimarco-dfinity marked this pull request as draft May 28, 2025 10:46
google-labs-jules bot and others added 2 commits May 28, 2025 11:13
Here's a summary:
- I removed the `tempfile` and `assert_json_diff` dependencies from `rs/cli/Cargo.toml`.
- The main logic of the `SubnetNodeDiff::execute` method is now in a new private method called `fetch_and_collate_subnet_changes`. This new method gathers and organizes the data. The `execute` method now calls this function and then writes the output.
- I updated the unit tests in `rs/cli/src/commands/subnet_node_diff.rs`:
    - The `run_and_get_json_output` test helper now directly calls the new `fetch_and_collate_subnet_changes` method to get the `SubnetNodeDiffOutput` data.
    - For comparing JSON in tests, I'm now using `assert_eq!` on `serde_json::Value` objects instead of the `assert_json_eq` macro.
    - This means I no longer need to create temporary files during the core logic tests or use a direct JSON diffing library.
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