Skip to content

Conversation

@ViktorT-11
Copy link
Contributor

If there are no RPCParamsJson set for an action, the value is represented differently in KVDB vs SQL.
In the SQL DB, empty RPCParamsJson are represented as nil, while they are represented as an empty array in the KVDB version. This PR addresses that issue, by overriding the RPCParamsJson in that scenario, so that they are set to the same representation when a KVDB and an SQL action is compared.

If there are no RPCParamsJson set for an action, the value is
represented differently in KVDB vs SQL.
In the SQL DB, empty RPCParamsJson are represented as nil, while they
are represented as an empty array in the KVDB version. Therefore, we
need to override the RPCParamsJson in that scenario, so that they are
set to the same representation when a KVDB and an SQL action is
compared.
@gemini-code-assist
Copy link

Summary of Changes

Hello @ViktorT-11, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical data representation discrepancy encountered during the migration of firewall actions from KVDB to SQL. Specifically, it rectifies the inconsistent handling of empty RPCParamsJson fields, which were stored as an empty array in KVDB but as nil in SQL. By introducing a new override mechanism and corresponding test cases, the PR ensures that these fields are uniformly represented across both database systems, thereby maintaining data integrity and preventing validation failures during the migration process.

Highlights

  • Data Consistency Fix: Resolved an inconsistency in how empty RPCParamsJson values are represented between KVDB (as an empty array) and SQL (as nil), ensuring uniform data representation during migration.
  • New Override Function: Introduced overrideRPCParamsJson in firewalldb/sql_migration.go to explicitly set sqlAction.RPCParamsJson to an empty byte slice ([]byte{}) when the KVDB action's RPCParamsJson is empty and the SQL action's is nil, standardizing the representation.
  • Enhanced Test Coverage: Added a new test case, action with empty RPCParamsJson, to TestFirewallDBMigration to validate the correct handling of actions where RPCParamsJson is empty, along with a new helper function actionEmptyRPCParamsJson.
  • Test Helper Adjustments: Modified the addAction helper to ensure that when actionReq.RPCParamsJson is empty, the action.RPCParamsJson is correctly set to nil for SQL representation in tests. Also, randomJSON was updated to handle zero-length JSON generation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses the discrepancy in representing empty RPCParamsJson between KVDB and SQL databases during migration by overriding the value for comparison. The main logic in sql_migration.go is sound. However, I've found a couple of issues in the test files that need to be addressed. One is an incorrect modification in a test helper function that affects the validation logic, and another is a helper function that generates invalid JSON. My review provides specific suggestions to resolve these points.

Comment on lines +2000 to +2005
// In case the actionReq's RPCParamsJson wasn't set, we need to set the
// expected action's RPCParamsJson to nil as that's how such
// RPCParamsJson are represented in
if len(actionReq.RPCParamsJson) == 0 {
action.RPCParamsJson = nil
}

Choose a reason for hiding this comment

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

high

This logic incorrectly sets action.RPCParamsJson to nil for the expected action. According to the pull request description, an empty RPCParamsJson in KVDB is represented as an empty slice ([]byte{}), not nil. The expected action (kvAction) used for validation should reflect the state as it is in KVDB. This change wrongly aligns the expected KVDB action with the SQL representation, which undermines the purpose of the overrideRPCParamsJson function and could lead to incorrect test outcomes. Additionally, the comment on line 2002 is incomplete.

This block should be removed to ensure the test correctly validates the migration logic.

func randomJSON(n int) (string, error) {
// When 0 pairs are requested, we can return immediately.
if n <= 0 {
return "", nil

Choose a reason for hiding this comment

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

medium

The function randomJSON should return a valid JSON string. For n=0, it should return "{}" (an empty JSON object), but it currently returns "" (an empty string), which is not a valid JSON representation for an object. This is problematic as the StructuredJsonData field is expected to contain a serialized JSON string.

If the intention is to test cases with empty RPCParamsJson, it would be cleaner to handle this explicitly in the randomActions test helper, rather than having randomJSON produce invalid data.

Suggested change
return "", nil
return "{}", nil

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