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

GO-3453: progress bars protocol #1274

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

AnastasiaShemyakinskaya
Copy link
Member

Copy link

coderabbitai bot commented May 27, 2024

Walkthrough

The changes primarily involve refactoring how progress messages are handled across various processes such as file downloads, imports, and exports. The Type field in progress structures has been replaced with a Message field to accommodate more specific message types. Additionally, new subscription and unsubscription mechanisms for processes have been added, allowing sessions to be dynamically included or excluded from receiving process updates.

Changes

File(s) Change Summary
core/block/editor/file/file.go, core/block/export/export.go Replaced Type field with Message field in progress structures.
core/block/files.go Changed progress variable type to &pb.ModelProcessMessageOfSaveFile{}.
core/block/import/csv/converter_test.go, core/block/import/html/converter_test.go, core/block/import/pb/converter_test.go, core/block/import/txt/converter_test.go Updated test functions to use process.NewProgress(&pb.ModelProcessMessageOfImport{}).
core/block/import/importer.go Changed progressBarType and updated progress initialization.
core/block/import/notion/api/search/search_test.go Updated test function to use process.NewProgress(&pb.ModelProcessMessageOfImport{}).
core/block/process/progress.go Modified NewProgress function and progress struct to use pb.IsModelProcessMessage type.
core/block/process/queue.go Replaced Type field with Message field in Info() function.
core/block/process/service.go, core/block/process/service_test.go Added subscription and unsubscription methods and related tests.
core/event/event.go, core/event/event_grpc.go Added BroadcastExceptSessions method to broadcast events excluding specific sessions.
core/process.go Added methods for subscribing and unsubscribing to processes.
pb/protos/commands.proto Added Subscribe and Unsubscribe message types with corresponding Request and Response messages.
pb/protos/events.proto Replaced Type enum in Process message with individual message types.
pb/protos/service/service.proto Added new RPC methods ProcessSubscribe and ProcessUnsubscribe.
util/builtinobjects/builtinobjects.go Updated setupProgress method to use &pb.ModelProcessMessageOfImport{}.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Client
    participant Server
    participant ProcessService

    Client->>Server: ProcessSubscribe(Request)
    Server->>ProcessService: Subscribe(token)
    ProcessService->>Server: Subscribe(Response)
    Server->>Client: ProcessSubscribe(Response)

    Client->>Server: ProcessUnsubscribe(Request)
    Server->>ProcessService: Unsubscribe(token)
    ProcessService->>Server: Unsubscribe(Response)
    Server->>Client: ProcessUnsubscribe(Response)
Loading

In the code, where progress flows,
A rabbit hops, where logic grows.
With messages clear, and types refined,
Processes now, are well-aligned.
Subscribe and leave, with ease and grace,
In this digital, hopping space. 🐇


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

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the 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 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.
  • 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.

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: 5

Outside diff range and nitpick comments (3)
core/block/process/queue.go (1)

189-189: The update to the Info method to use the new Message field aligns with the refactoring of process message handling. Consider adding a comment to clarify the purpose and expected content of the Message field for future maintainers.

core/block/editor/file/file.go (1)

382-382: The update to the Info method to use the new Message field aligns with the refactoring of process message handling. Consider adding a comment to clarify the purpose and expected content of the Message field for future maintainers.

pb/protos/service/service.proto (1)

295-296: Ensure the new RPC methods ProcessSubscribe and ProcessUnsubscribe are properly documented.

Adding comments to describe the purpose and usage of these new RPC methods would improve maintainability and clarity for other developers.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d44af3e and b3cb8c7.
Files ignored due to path filters (6)
  • clientlibrary/service/service.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • core/event/mock_event/mock_Sender.go is excluded by !**/mock_*.go
  • docs/proto.md is excluded by !**/proto.md
  • pb/commands.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • pb/events.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • pb/service/service.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
Files selected for processing (20)
  • core/block/editor/file/file.go (1 hunks)
  • core/block/export/export.go (1 hunks)
  • core/block/files.go (1 hunks)
  • core/block/import/csv/converter_test.go (18 hunks)
  • core/block/import/html/converter_test.go (1 hunks)
  • core/block/import/importer.go (2 hunks)
  • core/block/import/notion/api/search/search_test.go (1 hunks)
  • core/block/import/pb/converter_test.go (7 hunks)
  • core/block/import/txt/converter_test.go (1 hunks)
  • core/block/process/progress.go (3 hunks)
  • core/block/process/queue.go (1 hunks)
  • core/block/process/service.go (4 hunks)
  • core/block/process/service_test.go (1 hunks)
  • core/event/event.go (2 hunks)
  • core/event/event_grpc.go (2 hunks)
  • core/process.go (2 hunks)
  • pb/protos/commands.proto (1 hunks)
  • pb/protos/events.proto (1 hunks)
  • pb/protos/service/service.proto (1 hunks)
  • util/builtinobjects/builtinobjects.go (1 hunks)
Additional comments not posted (22)
core/event/event.go (1)

16-17: The addition of BroadcastExceptSessions to the Sender interface enhances the flexibility of event broadcasting by allowing exceptions. Good design choice.

core/block/import/txt/converter_test.go (1)

20-20: Updated progress initialization to use &pb.ModelProcessMessageOfImport{} aligns with the new protocol for process messages. This change enhances flexibility and maintainability.

core/process.go (2)

30-42: The implementation of ProcessSubscribe is robust, handling context initialization, subscription logic, and error management effectively.


44-56: The implementation of ProcessUnsubscribe effectively manages the unsubscribe logic with proper error handling and context management.

core/block/files.go (1)

29-29: Updated progress initialization to &pb.ModelProcessMessageOfSaveFile{} is consistent with the new protocol for process messages, enhancing flexibility and maintainability.

core/block/process/service_test.go (2)

62-86: The TestService_Subscribe function effectively tests the subscription logic, ensuring that tokens are managed correctly in the disabledProcessEvent map.


88-101: The TestService_Unsubscribe function effectively tests the unsubscribe logic, ensuring that tokens are correctly added to the disabledProcessEvent map.

core/block/process/progress.go (1)

25-30: Refactoring of the NewProgress function and the progress struct to use the processMessage field aligns with the new protocol for process messages, enhancing flexibility and maintainability.

Also applies to: 39-41, 137-137

core/block/process/service.go (1)

Line range hint 101-111: The update to use BroadcastExceptSessions in the monitor method enhances the functionality by allowing selective broadcasting. Ensure that the getExcludedSessions method is thoroughly tested to handle concurrent modifications safely.

core/block/import/html/converter_test.go (1)

32-32: The update to use ModelProcessMessageOfImport in the test setup is consistent with the new progress message handling. Consider adding more test cases to cover different scenarios and error conditions.

core/block/import/pb/converter_test.go (1)

46-46: The update to use ModelProcessMessageOfImport in the test setup is consistent with the new progress message handling. Consider adding more test cases to cover different scenarios and error conditions.

Also applies to: 66-66, 93-93, 111-111, 124-124, 144-144, 180-180

core/block/import/importer.go (2)

244-246: The refactoring of setupProgressBar to use pb.IsModelProcessMessage aligns with the overall PR objectives to enhance flexibility in process message handling.


281-281: The update in ImportWeb to use &pb.ModelProcessMessageOfImport{} for progress initialization is consistent with the refactoring strategy outlined in the PR.

core/block/import/notion/api/search/search_test.go (1)

35-35: The update in Test_GetDatabaseSuccess to use &pb.ModelProcessMessageOfImport{} for progress initialization is consistent with the refactoring strategy outlined in the PR.

util/builtinobjects/builtinobjects.go (1)

539-539: LGTM! The update to use &pb.ModelProcessMessageOfImport{} in setupProgress aligns with the refactoring of process messages.

core/block/import/csv/converter_test.go (1)

25-25: LGTM! The updates to use &pb.ModelProcessMessageOfImport{} in various test functions align with the refactoring of process messages.

Also applies to: 50-50, 83-83, 112-112, 153-153, 172-172, 212-212, 240-240, 287-287, 342-342, 363-363, 384-384, 412-412, 458-458, 564-564, 606-606, 674-674, 712-712

core/block/export/export.go (5)

102-104: Update to use new pb.ModelProcessMessageOfExport for process message initialization.

This change aligns with the PR's objective to refactor process message handling using the new protocol buffer definitions. It enhances type safety and clarity in the code.


102-104: Refactored process message initialization in Export method.

The refactoring to use pb.ModelProcessMessageOfExport instead of a generic type or enum improves the clarity and type safety of the process message handling. This change is consistent with the overall PR objectives of enhancing the process message protocol.


102-104: Concurrency handling in exportDocs.

The use of atomic operations for incrementing the success count and the structured handling of concurrent tasks ensure that the export process is both efficient and thread-safe. This is a good practice in handling concurrency in Go.


102-104: Improved error handling in sendNotification.

The method now appropriately determines the type of notification to send based on the presence of an error, which enhances the robustness and user-friendliness of the export functionality.


102-104: Robust file cleanup in cleanupFile.

The method ensures that files are properly closed and deleted if necessary, which prevents resource leakage and maintains the integrity of the file system during export operations.

pb/protos/events.proto (1)

1079-1093: The addition of specific message types for process actions enhances the granularity and specificity of process handling.

Comment on lines +6433 to +6435
message Unsubscribe {
message Request {}

Copy link

Choose a reason for hiding this comment

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

Add documentation for the Unsubscribe method.

Similar to the Subscribe method, the Unsubscribe method is missing documentation. Adding detailed comments will help developers understand the purpose and usage of this method more clearly.

Comment on lines +6415 to +6432
message Subscribe {
message Request {}

message Response {
Error error = 1;

message Error {
Code code = 1;
string description = 2;

enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
}
}
}
}
Copy link

Choose a reason for hiding this comment

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

Add documentation for the Subscribe method.

The Subscribe method lacks documentation. It's important to maintain comprehensive documentation, especially for public APIs, to ensure they are easily understandable and usable by developers. Consider adding a brief description of what the method does, its parameters, and what it returns.

Comment on lines +105 to +115
// BroadcastExceptSessions broadcasts the event to session except provided
func (es *GrpcSender) BroadcastExceptSessions(event *pb.Event, exceptTokens []string) {
es.ServerMutex.RLock()
defer es.ServerMutex.RUnlock()

for _, s := range es.Servers {
if !slices.Contains(exceptTokens, s.Token) {
es.sendEvent(s, event)
}
}
}
Copy link

Choose a reason for hiding this comment

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

The implementation of BroadcastExceptSessions method looks correct and thread-safe.

Would you like me to help create a unit test for this method to ensure it behaves as expected under various scenarios?

Comment on lines +37 to +40
// Subscribe remove session from the map of disabled sessions
Subscribe(token string)
// Unsubscribe add session to the map of disabled sessions
Unsubscribe(token string)
Copy link

Choose a reason for hiding this comment

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

The implementation of Subscribe and Unsubscribe methods along with the getExcludedSessions helper function is correct. However, consider adding more robust synchronization or using concurrent-safe data structures to manage the disabledProcessEvent map to prevent potential race conditions.

- map[string]struct{}
+ sync.Map

Also applies to: 179-199


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// Subscribe remove session from the map of disabled sessions
Subscribe(token string)
// Unsubscribe add session to the map of disabled sessions
Unsubscribe(token string)
// Subscribe remove session from the map of disabled sessions
Subscribe(token string)
// Unsubscribe add session to the map of disabled sessions
Unsubscribe(token string)

Comment on lines +55 to +57
func (es *CallbackSender) BroadcastExceptSessions(event *pb.Event, exceptTokens []string) {
es.callback(event)
}
Copy link

Choose a reason for hiding this comment

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

The implementation of BroadcastExceptSessions should exclude the specified sessions. Currently, it broadcasts to all sessions.

- es.callback(event)
+ for _, session := range es.sessions {
+     if !contains(exceptTokens, session.token) {
+         es.callback(event)
+     }
+ }

Please ensure that sessions and contains logic is implemented to handle the exclusion properly.

Committable suggestion was skipped due low confidence.

Copy link

github-actions bot commented May 27, 2024

New Coverage 47.2% of statements
Patch Coverage 29.2% of changed statements (19/65)

Coverage provided by https://github.com/seriousben/go-patch-cover-action

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