feat: Add subnet-node-diff command to dre CLI#1567
Draft
pietrodimarco-dfinity wants to merge 3 commits intomainfrom
Draft
feat: Add subnet-node-diff command to dre CLI#1567pietrodimarco-dfinity wants to merge 3 commits intomainfrom
pietrodimarco-dfinity wants to merge 3 commits intomainfrom
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit introduces a new command
subnet-node-diffto thedreCLI tool.The command takes two registry versions (
--version1and--version2) as input and an optional output file path (-oor--output). It then calculates the number of nodes assigned to each subnet for every registry version fromversion1 + 1up toversion2.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:
rs/cli/src/commands/subnet_node_diff.rsimplementing the command logic.SubnetNodeDiff,ChangeEntry, andSubnetChangeLogstructs for command arguments and JSON serialization.get_subnet_node_countshelper to fetch and count nodes per subnet for a given registry version.rs/cli/src/commands/mod.rsandrs/cli/src/commands/main_command.rs.DreContextandLocalStoreImplto validate various scenarios, including node count changes, subnet additions/removals, and error conditions.