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(ledger): add metadata at ledger level #1353

Merged
merged 4 commits into from Mar 25, 2024
Merged

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Mar 25, 2024

Add PUT /{ledger}/metadata urls to add metadata to ledgers.
Add DELETE /{ledger}/metadata/{key} to remove keys from metadata.

Fixes ENG-868

Summary by CodeRabbit

  • New Features
    • Enhanced ledger management with the ability to update and delete metadata, improving metadata handling capabilities.
    • Expanded SDK functionality to support new operations for managing ledger metadata effectively.
  • Tests
    • Implemented comprehensive tests, including integration tests for creating, updating, and deleting ledger metadata.
  • Documentation
    • Updated SDK documentation to include detailed information on new metadata management features, offering examples and parameter details.
  • Refactor
    • Improved test structure for ledger creation with various configurations, ensuring thorough testing.
  • Chores
    • Updated internal storage models to accommodate ledger metadata, including necessary database column additions.

@gfyrag gfyrag requested a review from a team as a code owner March 25, 2024 12:21
Copy link
Contributor

coderabbitai bot commented Mar 25, 2024

Walkthrough

The recent modifications introduce the capability to manage ledger metadata, including updating and deleting specific metadata entries. This enhancement is reflected across various components of the system, from the backend logic and API controllers to integration with storage drivers and SDK updates. The changes facilitate more dynamic and flexible ledger configurations, allowing for a richer set of metadata operations.

Changes

Files Change Summary
.../api/backend/backend.go
.../api/backend/backend_generated.go
Added methods for updating and deleting ledger metadata in backend interfaces and mocks.
.../api/v2/controllers_*.go
.../api/v2/controllers_*_test.go
Implemented functionality and tests for updating and deleting ledger metadata in API controllers.
.../storage/.../ledgers.go
.../storage/driver/driver.go
Updated storage components to handle ledger metadata operations effectively.
.../sdks/go/...
.../sdks/go/docs/pkg/...
Enhanced SDKs and documentation to support managing ledger metadata efficiently.
tests/integration/suite/... Added integration tests for creating, updating, and deleting ledger metadata with metadata.

Poem

🎉🐰🎉

In the land of code and data so wide,

A rabbit hopped with a joyful stride.

"Behold!" it cheered, with eyes so bright,

"Ledger metadata, now update and delete outright!"

With every hop, it spread the news,

Of features new, for all to use. 🌟

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b73a9a9 and 4346f79.
Files ignored due to path filters (2)
  • components/ledger/openapi.yaml is excluded by: !**/*.yaml
  • components/ledger/openapi/v2.yaml is excluded by: !**/*.yaml
Files selected for processing (31)
  • components/ledger/internal/api/backend/backend.go (2 hunks)
  • components/ledger/internal/api/backend/backend_generated.go (4 hunks)
  • components/ledger/internal/api/v2/controllers_create_ledger_test.go (1 hunks)
  • components/ledger/internal/api/v2/controllers_ledgers.go (2 hunks)
  • components/ledger/internal/api/v2/controllers_ledgers_test.go (1 hunks)
  • components/ledger/internal/api/v2/routes.go (1 hunks)
  • components/ledger/internal/storage/driver/driver.go (3 hunks)
  • components/ledger/internal/storage/systemstore/ledgers.go (5 hunks)
  • components/ledger/internal/storage/systemstore/ledgers_test.go (3 hunks)
  • components/ledger/internal/storage/systemstore/migrations.go (1 hunks)
  • releases/sdks/go/.speakeasy/gen.lock (7 hunks)
  • releases/sdks/go/README.md (2 hunks)
  • releases/sdks/go/docs/pkg/models/operations/v2deleteledgermetadatarequest.md (1 hunks)
  • releases/sdks/go/docs/pkg/models/operations/v2deleteledgermetadataresponse.md (1 hunks)
  • releases/sdks/go/docs/pkg/models/operations/v2getledgerresponse.md (1 hunks)
  • releases/sdks/go/docs/pkg/models/operations/v2updateledgermetadatarequest.md (1 hunks)
  • releases/sdks/go/docs/pkg/models/operations/v2updateledgermetadataresponse.md (1 hunks)
  • releases/sdks/go/docs/pkg/models/shared/v2createledgerrequest.md (1 hunks)
  • releases/sdks/go/docs/pkg/models/shared/v2getledgerresponse.md (1 hunks)
  • releases/sdks/go/docs/pkg/models/shared/v2ledger.md (1 hunks)
  • releases/sdks/go/docs/sdks/ledger/README.md (6 hunks)
  • releases/sdks/go/ledger.go (3 hunks)
  • releases/sdks/go/pkg/models/operations/v2deleteledgermetadata.go (1 hunks)
  • releases/sdks/go/pkg/models/operations/v2getledger.go (2 hunks)
  • releases/sdks/go/pkg/models/operations/v2updateledgermetadata.go (1 hunks)
  • releases/sdks/go/pkg/models/shared/v2createledgerrequest.go (2 hunks)
  • releases/sdks/go/pkg/models/shared/v2getledgerresponse.go (1 hunks)
  • releases/sdks/go/pkg/models/shared/v2ledger.go (2 hunks)
  • tests/integration/suite/ledger-create.go (2 hunks)
  • tests/integration/suite/ledger-delete-metadata.go (1 hunks)
  • tests/integration/suite/ledger-update-metadata.go (1 hunks)
Files skipped from review as they are similar to previous changes (21)
  • components/ledger/internal/api/backend/backend.go
  • components/ledger/internal/api/backend/backend_generated.go
  • components/ledger/internal/api/v2/controllers_create_ledger_test.go
  • components/ledger/internal/api/v2/controllers_ledgers.go
  • components/ledger/internal/api/v2/controllers_ledgers_test.go
  • components/ledger/internal/api/v2/routes.go
  • components/ledger/internal/storage/driver/driver.go
  • components/ledger/internal/storage/systemstore/ledgers_test.go
  • components/ledger/internal/storage/systemstore/migrations.go
  • releases/sdks/go/.speakeasy/gen.lock
  • releases/sdks/go/docs/sdks/ledger/README.md
  • releases/sdks/go/ledger.go
  • releases/sdks/go/pkg/models/operations/v2deleteledgermetadata.go
  • releases/sdks/go/pkg/models/operations/v2getledger.go
  • releases/sdks/go/pkg/models/operations/v2updateledgermetadata.go
  • releases/sdks/go/pkg/models/shared/v2createledgerrequest.go
  • releases/sdks/go/pkg/models/shared/v2getledgerresponse.go
  • releases/sdks/go/pkg/models/shared/v2ledger.go
  • tests/integration/suite/ledger-create.go
  • tests/integration/suite/ledger-delete-metadata.go
  • tests/integration/suite/ledger-update-metadata.go
Additional comments: 17
releases/sdks/go/docs/pkg/models/shared/v2createledgerrequest.md (1)
  • 9-9: The addition of the Metadata field to V2CreateLedgerRequest is well-documented and aligns with the PR's objectives. Ensure that the formatting, especially around the Metadata field, adheres to the documentation standards for consistency and readability.
releases/sdks/go/docs/pkg/models/operations/v2deleteledgermetadatarequest.md (1)
  • 8-9: The introduction of Key and Ledger fields in V2DeleteLedgerMetadataRequest is well-documented and supports the PR's objectives for managing ledger metadata. Ensure that the formatting adheres to the documentation standards for consistency and readability.
releases/sdks/go/docs/pkg/models/operations/v2updateledgermetadatarequest.md (1)
  • 8-9: The introduction of RequestBody and Ledger fields in V2UpdateLedgerMetadataRequest is well-documented and supports the PR's objectives for updating ledger metadata. Ensure that the formatting adheres to the documentation standards for consistency and readability.
releases/sdks/go/docs/pkg/models/shared/v2getledgerresponse.md (1)
  • 1-8: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-12]

Ensure that the formatting in V2GetLedgerResponse adheres to the documentation standards for consistency and readability. The structure appears to align with the PR's objectives, but a detailed review of any specific changes was not possible based on the provided context.

releases/sdks/go/docs/pkg/models/shared/v2ledger.md (1)
  • 10-10: The addition of the Metadata field to V2Ledger is well-documented and aligns with the PR's objectives for managing ledger metadata. Ensure that the formatting, especially around the Metadata field, adheres to the documentation standards for consistency and readability.
releases/sdks/go/docs/pkg/models/operations/v2deleteledgermetadataresponse.md (1)
  • 8-11: The documentation of the response structure in V2DeleteLedgerMetadataResponse is clear and supports the PR's objectives for managing ledger metadata. Ensure that the formatting adheres to the documentation standards for consistency and readability.
releases/sdks/go/docs/pkg/models/operations/v2updateledgermetadataresponse.md (1)
  • 8-11: The documentation of the response structure in V2UpdateLedgerMetadataResponse is clear and supports the PR's objectives for updating ledger metadata. Ensure that the formatting adheres to the documentation standards for consistency and readability.
releases/sdks/go/docs/pkg/models/operations/v2getledgerresponse.md (1)
  • 12-12: The renaming of the V2Ledger field to V2GetLedgerResponse is well-documented and aligns with the PR's objectives for updating SDKs and internal APIs. Ensure that the formatting adheres to the documentation standards for consistency and readability.
components/ledger/internal/storage/systemstore/ledgers.go (6)
  • 22-22: Adding a Metadata field of type map[string]string to the Ledger struct is a straightforward way to store key-value pairs. However, consider documenting the expected use of this field, especially regarding the size and type of data expected to be stored. Large or complex metadata could impact performance or storage.
  • 44-44: The inclusion of "metadata" in the column list for the ListLedgers query ensures that metadata is fetched along with other ledger details. This is consistent with the objective of enhancing ledger functionality with metadata management. Ensure that the performance implications of fetching potentially large JSONB columns are considered, especially in listings with many ledgers.
  • 67-67: Similar to the ListLedgers method, including "metadata" in the GetLedger query ensures consistency in how ledger details are fetched. This aligns with the goal of comprehensive metadata management. Again, be mindful of the potential performance impact when fetching large metadata objects.
  • 76-82: The UpdateLedgerMetadata method correctly updates the metadata for a given ledger. It's important to ensure that the metadata.Metadata type is compatible with the map[string]string type expected by the Ledger struct. Additionally, consider handling potential conflicts or merges with existing metadata entries.
  • 85-91: The DeleteLedgerMetadata method uses a PostgreSQL-specific operation (metadata = metadata - ?) to remove a key from the JSONB metadata field. This is an efficient way to handle the deletion of metadata entries. Ensure that this operation is supported by the database version in use and consider adding error handling for cases where the key does not exist.
  • 95-97: Initializing the Metadata field in the RegisterLedger method if it is nil is a good practice to ensure that the ledger object is always in a valid state. This preemptive initialization avoids potential null pointer exceptions when interacting with the Metadata field.
releases/sdks/go/README.md (3)
  • 110-116: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-11]

The introduction section provides a good overview of the SDK's purpose and initial steps for customization and local development. However, it might be beneficial to clarify that while the SDK is generated based on the OpenAPI spec, users are encouraged to contribute or report issues for further improvements.

Consider adding a sentence encouraging users to contribute to the SDK or report issues for enhancements, making it clear that community feedback is valued.

  • 110-116: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [113-127]

The addition of V2DeleteLedgerMetadata and V2UpdateLedgerMetadata methods to the SDK is clearly documented, providing users with the necessary functions to manage ledger metadata. This aligns with the PR objectives to enhance metadata management capabilities.

Ensure that examples or further documentation on how to use these new methods effectively are also provided, either in this README or in linked detailed documentation.

  • 110-116: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-500]

There are several grammatical and typographical errors identified by static analysis, such as possible spelling mistakes and repeated whitespaces. While some of these may be false positives, especially in code blocks or URLs, it's important to review and correct genuine errors in the documentation text.

Review the document for genuine grammatical and typographical errors and correct them to improve readability. For example, ensure consistent use of spaces after periods and correct any spelling mistakes in the non-code text.

Comment on lines 110 to 116
* [V2CreateLedger](docs/sdks/ledger/README.md#v2createledger) - Create a ledger
* [V2CreateTransaction](docs/sdks/ledger/README.md#v2createtransaction) - Create a new transaction to a ledger
* [V2DeleteAccountMetadata](docs/sdks/ledger/README.md#v2deleteaccountmetadata) - Delete metadata by key
* [V2DeleteLedgerMetadata](docs/sdks/ledger/README.md#v2deleteledgermetadata) - Delete ledger metadata by key
* [V2DeleteTransactionMetadata](docs/sdks/ledger/README.md#v2deletetransactionmetadata) - Delete metadata by key
* [V2GetAccount](docs/sdks/ledger/README.md#v2getaccount) - Get account by its address
* [V2GetBalancesAggregated](docs/sdks/ledger/README.md#v2getbalancesaggregated) - Get the aggregated balances from selected accounts
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-500]

Throughout the document, there are several instances of unpaired symbols, mostly related to markdown links. This could potentially break the formatting when viewed on platforms like GitHub or in markdown editors.

Ensure all markdown links are correctly formatted with no unpaired symbols. For example:

- [CreatePolicy](docs/sdks/reconciliation/README.md#cre
+ [CreatePolicy](docs/sdks/reconciliation/README.md#createpolicy)

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4346f79 and d1d374e.
Files selected for processing (1)
  • components/ledger/internal/storage/systemstore/migrations.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • components/ledger/internal/storage/systemstore/migrations.go

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d1d374e and b7a6f80.
Files selected for processing (8)
  • components/fctl/cmd/ledger/accounts/delete_metadata.go (1 hunks)
  • components/fctl/cmd/ledger/create.go (3 hunks)
  • components/fctl/cmd/ledger/delete_metadata.go (1 hunks)
  • components/fctl/cmd/ledger/list.go (2 hunks)
  • components/fctl/cmd/ledger/root.go (1 hunks)
  • components/fctl/cmd/ledger/set_metadata.go (1 hunks)
  • components/fctl/cmd/ledger/transactions/delete_metadata.go (1 hunks)
  • components/ledger/internal/storage/systemstore/ledgers.go (5 hunks)
Additional comments: 9
components/fctl/cmd/ledger/root.go (1)
  • 22-23: The addition of NewSetMetadataCommand and NewDeleteMetadataCommand to the ledger command suite is a logical extension for managing ledger metadata. Ensure that these commands are thoroughly tested and documented to align with the PR objectives.
components/fctl/cmd/ledger/accounts/delete_metadata.go (1)
  • 31-31: The change to NewDeleteMetadataCommand to accept only a single <key> parameter simplifies the interface but limits batch deletion capabilities. Ensure that this behavior change is documented and communicated to users, especially if batch deletion was previously supported.
components/fctl/cmd/ledger/list.go (1)
  • 73-76: The inclusion of the creation timestamp and metadata in the ledger list enhances the information provided to users. Ensure that the metadata is presented in a concise and readable format, considering its potential complexity. It might be helpful to limit the amount of metadata displayed or provide a summarized view.
components/fctl/cmd/ledger/delete_metadata.go (1)
  • 29-36: The implementation of NewDeleteMetadataCommand for ledgers aligns with the PR objectives of enhancing metadata management. Ensure that error handling is robust and user feedback is clear, especially in cases where the specified metadata key does not exist.
components/fctl/cmd/ledger/transactions/delete_metadata.go (1)
  • 31-31: The modification to NewDeleteMetadataCommand to accept only a single <key> parameter for transaction metadata deletion simplifies the command interface. As with similar changes in other components, ensure that the implications of this limitation are well-documented and communicated to users.
components/fctl/cmd/ledger/set_metadata.go (1)
  • 31-38: The implementation of NewSetMetadataCommand for ledgers is a valuable addition, enhancing the ledger's metadata management capabilities. Ensure that the parsing of metadata key-value pairs is robust and that clear error messages are provided for invalid inputs.
components/fctl/cmd/ledger/create.go (1)
  • 45-45: The introduction of a metadata flag in the ledger creation command is a significant enhancement, allowing users to specify metadata at creation time. Ensure that the metadata is correctly parsed and validated, providing clear error messages for invalid formats.
components/ledger/internal/storage/systemstore/ledgers.go (2)
  • 22-22: The addition of the Metadata field to the Ledger struct is a key enhancement for supporting metadata management at the ledger level. Ensure that metadata is correctly validated and sanitized before storage to prevent potential security issues.
  • 76-92: The implementation of UpdateLedgerMetadata and DeleteLedgerMetadata methods provides the necessary functionality for managing ledger metadata. Ensure comprehensive testing of these methods, particularly edge cases such as attempting to delete non-existent metadata keys or updating metadata with invalid data types.

@gfyrag gfyrag enabled auto-merge March 25, 2024 13:43
@gfyrag gfyrag added this pull request to the merge queue Mar 25, 2024
Merged via the queue into main with commit 3fc328a Mar 25, 2024
10 checks passed
@gfyrag gfyrag deleted the feat/ledger-add-metadata branch March 25, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants