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: change gateway code as RFC-0003 #219

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

giangndm
Copy link
Contributor

@giangndm giangndm commented Feb 4, 2024

This PR implement gateway as described in RFC-0003
Changes: now we have only one type gateway node, which works for both global and inner

Copy link

coderabbitai bot commented Feb 4, 2024

Walkthrough

The recent updates focus on streamlining and renaming key components within the system. The "Inner-Gateway" module has been renamed to "Gateway" and now features an updated address format. Similarly, "WebRTC" and "RTMP" modules are now referred to as nodes. New constants have been introduced, enhancing the service architecture. Additionally, scripts and server functionalities have been adjusted to align with these changes, including modifications to parameters and the handling of zones instead of groups, reflecting a more intuitive and simplified structure.

Changes

File Path Change Summary
README.md Renamed modules to nodes, updated address format.
packages/cluster/src/define/... Renamed constants, added new constants for services.
packages/cluster/src/.../gateway.rs Updated struct fields and added new fields in RPC functionality.
packages/cluster/src/implement/... Adjusted function calls to include new parameters.
servers/media-server/scripts/... Introduced scripts for running media server as a gateway, adjusted flags for SDN configuration.
servers/media-server/src/.../main.rs, .../server.rs, .../gateway.rs, .../gateway/logic.rs, .../gateway/rpc.rs, .../webrtc_route.rs, .../rtmp.rs, .../webrtc.rs Renamed services and parameters, streamlined logic for service naming, configuration, and handling zone-specific operations.

"In the digital meadow, beneath the byte-sized sun,
🐰 CodeRabbit hopped around, as changes were spun.
From gateway to node, in scripts and in code,
A streamlined path, now brightly glowed."

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.
  • 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 from git 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.

@giangndm giangndm marked this pull request as ready for review February 4, 2024 09:14
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a74da8a and 91af3e9.
Files ignored due to path filters (2)
  • Cargo.lock is excluded by: !**/*.lock
  • servers/media-server/Cargo.toml is excluded by: !**/*.toml
Files selected for processing (20)
  • README.md (1 hunks)
  • packages/cluster/src/define/mod.rs (1 hunks)
  • packages/cluster/src/define/rpc/gateway.rs (2 hunks)
  • packages/cluster/src/implement/mod.rs (4 hunks)
  • packages/cluster/src/implement/server.rs (2 hunks)
  • servers/media-server/scripts/gateway.sh (1 hunks)
  • servers/media-server/scripts/gateway_other.sh (1 hunks)
  • servers/media-server/scripts/media_rtmp.sh (1 hunks)
  • servers/media-server/scripts/media_sip.sh (1 hunks)
  • servers/media-server/scripts/media_webrtc.sh (1 hunks)
  • servers/media-server/src/main.rs (4 hunks)
  • servers/media-server/src/server/gateway.rs (12 hunks)
  • servers/media-server/src/server/gateway/logic.rs (8 hunks)
  • servers/media-server/src/server/gateway/logic/global_registry.rs (9 hunks)
  • servers/media-server/src/server/gateway/logic/inner_registry.rs (5 hunks)
  • servers/media-server/src/server/gateway/rpc.rs (1 hunks)
  • servers/media-server/src/server/gateway/rpc/http.rs (1 hunks)
  • servers/media-server/src/server/gateway/webrtc_route.rs (4 hunks)
  • servers/media-server/src/server/rtmp.rs (5 hunks)
  • servers/media-server/src/server/webrtc.rs (5 hunks)
Additional comments: 54
servers/media-server/scripts/media_rtmp.sh (1)
  • 5-5: Change from --sdn-group to --sdn-zone correctly implements the specified objective.
servers/media-server/scripts/media_webrtc.sh (1)
  • 5-5: Change from --sdn-group to --sdn-zone correctly implements the specified objective.
servers/media-server/scripts/media_sip.sh (1)
  • 5-5: Change from --sdn-group to --sdn-zone correctly implements the specified objective.
servers/media-server/scripts/gateway.sh (1)
  • 5-5: Addition of --sdn-zone correctly implements the specified objective.
servers/media-server/scripts/gateway_other.sh (1)
  • 5-5: Addition of --sdn-zone with a different zone value correctly demonstrates the system's flexibility and scalability.
servers/media-server/src/server/gateway/rpc.rs (1)
  • 9-9: Renaming BestNodest to BestNodes corrects a typo and improves code clarity.
packages/cluster/src/define/mod.rs (1)
  • 64-64: Consolidation and addition of service constants correctly implement the specified objectives and enhance system modularity.
packages/cluster/src/define/rpc/gateway.rs (1)
  • 23-23: Using zone instead of group in NodePing and adding service_id in QueryBestNodesResponse correctly implement the specified objectives.
packages/cluster/src/implement/server.rs (2)
  • 52-52: Returning an additional PubsubSdk instance from the new function of ServerSdn correctly implements the specified objectives.
  • 106-106: Cloning the pubsub_sdk field in the struct initialization correctly implements the specified objectives.
servers/media-server/src/server/gateway/webrtc_route.rs (2)
  • 22-22: Adding RouteResult to the import list correctly implements the specified objectives.
  • 111-111: Modifying the route_to_node function signature to remove the dest_service_id parameter and handle the service ID within the function correctly implements the specified objectives.
servers/media-server/src/main.rs (3)
  • 11-11: Renaming services to a unified GATEWAY_SERVICE correctly implements the specified objectives.
  • 45-47: Renaming the sdn_group parameter to sdn_zone correctly implements the specified objectives.
  • 106-107: Simplifying the logic for setting local_tags and connect_tags correctly implements the specified objectives.
servers/media-server/src/server/rtmp.rs (3)
  • 15-15: Renaming INNER_GATEWAY_SERVICE to GATEWAY_SERVICE correctly implements the specified objectives.
  • 67-67: Adding a new parameter zone to the run_rtmp_server function correctly implements the specified objectives.
  • 192-195: Adding a new parameter zone to the ping_gateway function correctly implements the specified objectives.
README.md (2)
  • 130-130: Renaming the "Inner-Gateway" module to the "Gateway" node in the documentation correctly implements the specified objectives.
  • 137-137: Renaming the "WebRTC" and "RTMP" modules to nodes in the documentation correctly implements the specified objectives.
servers/media-server/src/server/gateway/logic.rs (8)
  • 14-19: The RouteResult enum is correctly defined and aligns with the described changes.
  • 23-24: The method signatures for on_ping and best_nodes in the ServiceRegistry trait have been updated to include new parameters and return types. Ensure all implementations of this trait are updated accordingly.
Verification successful

The review comment mentioned updates to the method signatures for on_ping and best_nodes in the ServiceRegistry trait, specifically including new parameters and return types. The verification process involved checking the implementations of these methods in ServiceInnerRegistry and ServiceGlobalRegistry.

From the provided script outputs, it's clear that both ServiceInnerRegistry and ServiceGlobalRegistry have implemented the on_ping and best_nodes methods with the updated signatures as described in the review comment. The on_ping method includes parameters such as now_ms, zone, location, node_id, usage, live, and max. The best_nodes method includes parameters such as location, max_usage, max_usage_fallback, and size, and returns a RouteResult.

Given this information, it can be concluded that all implementations of the ServiceRegistry trait have been updated accordingly with the new parameters and return types for both on_ping and best_nodes methods.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify all implementations of ServiceRegistry have updated method signatures.
rg "impl ServiceRegistry" -A 10

Length of output: 2641



Script:

#!/bin/bash
# View the implementations of on_ping and best_nodes methods in ServiceInnerRegistry
rg "fn on_ping\(&mut self" servers/media-server/src/server/gateway/logic/inner_registry.rs -A 10
rg "fn best_nodes\(&mut self" servers/media-server/src/server/gateway/logic/inner_registry.rs -A 10

# View the implementations of on_ping and best_nodes methods in ServiceGlobalRegistry
rg "fn on_ping\(&mut self" servers/media-server/src/server/gateway/logic/global_registry.rs -A 10
rg "fn best_nodes\(&mut self" servers/media-server/src/server/gateway/logic/global_registry.rs -A 10

Length of output: 2326

* 44-46: The split of service registries into `global_gateways` and `inner_services` based on service types is a logical reorganization. Ensure that the logic handling these registries is correctly updated throughout the file.
Verification successful

The examination of the logic.rs file reveals that both global_gateways and inner_services are actively utilized and managed throughout the file. This includes their initialization, iteration, modification, and assertions in test scenarios, indicating a comprehensive and correct update of the logic handling these registries as per the split into two separate HashMaps based on service types. Therefore, the changes mentioned in the review comment have been successfully verified.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for correct handling of global_gateways and inner_services throughout the file.
rg "global_gateways|inner_services"

Length of output: 1657

* 80-88: The `on_node_ping` method correctly handles pings for different service types by delegating to `on_node_ping_service`. Ensure that the logic within `on_node_ping_service` correctly updates the respective service registry based on the service type.
Verification successful

The on_node_ping_service method's implementation confirms that it correctly updates the service registry based on the service type, provided the ping is from the correct zone. This aligns with the expectations set in the review comment, verifying that the method functions as intended for handling pings for different service types. Therefore, the logic within on_node_ping_service is implemented as expected to update the respective service registry based on the service type.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Ensure on_node_ping_service updates the correct service registry.
rg "on_node_ping_service" -A 10

Length of output: 2813

* 100-110: The `on_gateway_ping` method's implementation mirrors that of `on_node_ping`, appropriately handling pings for gateway services. This consistency in handling pings is good practice. * 126-139: The `best_nodes` method's logic to first check global gateways and then inner services for routing decisions is sound. The use of `RouteResult` enum for the return type enhances readability and maintainability. * 151-158: The `on_node_ping_service` and `on_gateway_ping_service` methods correctly differentiate handling based on the zone. This zone-based logic is crucial for the intended functionality. Ensure that zone comparisons are case-sensitive or not based on the application's requirements. * 201-207: The tests have been updated to reflect the changes in the gateway logic. Ensure that all new logic paths introduced are covered by these tests.
servers/media-server/src/server/gateway/logic/inner_registry.rs (3)
  • 82-82: The renaming of _group to _zone in the on_ping function parameters aligns with the shift towards zone-based logic. Ensure consistency in the use of the zone parameter across all related functions.
Verification successful

The review comment regarding the renaming of _group to _zone in the on_ping function and ensuring consistency in the use of the zone parameter across all related functions is supported by the evidence from the codebase. The usage of _zone in various parts of the application, including server configuration and logic, indicates a consistent shift towards zone-based logic. Therefore, the changes align with the broader application context.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for consistent use of the `zone` parameter across related functions.
rg "_zone" -A 3 -B 3

Length of output: 14621

* 101-132: The refactoring of the `best_nodes` function to use `RouteResult` enum improves the clarity of return types. Ensure that all callers of `best_nodes` correctly handle the new enum-based return values.
Verification successful

The review of the best_nodes function and its callers indicates that the new enum-based return values are being correctly handled across the codebase. The explicit checks for RouteResult enum variants in both the application logic and tests confirm that the refactoring has been successfully integrated. Based on the provided script output, there is no evidence of issues with how the new return types are managed by the callers of best_nodes.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Ensure callers of best_nodes handle the new enum-based return values.
rg "best_nodes" -A 5 -B 5

Length of output: 19342

* 271-277: The assertion modifications in tests to accommodate the updated `RouteResult` structure are appropriate. Verify that all relevant test cases have been updated to reflect these changes.
packages/cluster/src/implement/mod.rs (1)
  • 29-29: The addition of the _pubsub parameter in the ServerSdn::new function call is consistent across test functions. Ensure that the _pubsub parameter is correctly utilized or documented if it's intended for future use.
servers/media-server/src/server/gateway/logic/global_registry.rs (6)
  • 27-27: The addition of the zone field to the Zone struct aligns with the shift towards zone-based logic. Ensure that the zone field is correctly utilized in all relevant logic.
Verification successful

The examination of the zone field usage across various parts of the system confirms its broad and consistent integration. This includes server configuration, gateway logic, and node pinging processes, aligning with the initial review comment about ensuring the correct utilization of the zone field in all relevant logic. Therefore, the changes related to the addition of the zone field and its utilization are verified to be correctly implemented.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for correct utilization of the `zone` field in all relevant logic.
rg "zone:" -A 3 -B 3

Length of output: 15153

* 38-38: The addition of the `zone` field to the `ServiceGlobalRegistry` struct is appropriate for supporting zone-based operations. Verify that this field is consistently used where zone differentiation is required.
Verification successful

The script output confirms the addition of the zone field to the ServiceGlobalRegistry struct and its active use in initializing the struct and within the on_ping method for zone-specific logic. This indicates that the zone field is indeed being utilized where zone differentiation is required, aligning with the intent of supporting zone-based operations as mentioned in the review comment. Based on the available evidence, it appears that the zone field is consistently used in the parts of the codebase examined.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify consistent use of the `zone` field in ServiceGlobalRegistry operations.
rg "zone:" -A 3 -B 3 servers/media-server/src/server/gateway/logic/global_registry.rs

Length of output: 1571

* 45-52: The modification of the `new` method in `ServiceGlobalRegistry` to accept a `zone` parameter is correctly implemented. Ensure that all instances of `ServiceGlobalRegistry::new` are updated to pass the `zone` parameter.
Verification successful

The instances of ServiceGlobalRegistry::new found in the codebase correctly pass the zone parameter as required. This confirms that the modification to include a zone parameter in the new method has been properly implemented and adopted across various parts of the code, aligning with the initial review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Ensure all instances of ServiceGlobalRegistry::new pass the `zone` parameter.
rg "ServiceGlobalRegistry::new" -A 3

Length of output: 3237

* 93-96: The update to the `on_ping` method to use the `zone` parameter is correctly implemented. This change is crucial for supporting zone-based logic in service registries. * 126-140: > 📝 **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [119-137]

The modification of the best_nodes method to return a RouteResult and the logic to determine the closest zone or fallback zone is sound. This enhances the flexibility and accuracy of node selection based on zones.

  • 154-156: The tests have been updated to reflect changes in the ServiceGlobalRegistry methods. Ensure that all new logic paths introduced are covered by these tests.
servers/media-server/src/server/gateway.rs (11)
  • 73-78: The addition of zone: &str and pubsub: PubsubSdk parameters to run_gateway_server function aligns with the summary. Ensure all calls to this function are updated accordingly.
Verification successful

The search for calls to run_gateway_server with a broader pattern successfully identified a call in ./servers/media-server/src/main.rs:112. This call includes the parameters args.http_port, args.http_tls, &args.sdn_zone, opts, ctx, cluster, rpc_endpoint, and pubsub, which aligns with the updated function signature that includes zone: &str and pubsub: PubsubSdk as mentioned in the review comment. Therefore, it can be concluded that the call to run_gateway_server has been updated accordingly to include the new parameters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if all calls to run_gateway_server have been updated to include the new parameters.
ast-grep --lang rust --pattern $'run_gateway_server($_, $_, $_, $_, $_, $_, $_, $_, $_)'

Length of output: 89



Script:

#!/bin/bash
# Broaden the search to find any calls to run_gateway_server, regardless of the number of parameters.
ast-grep --lang rust --pattern $'run_gateway_server($$$)'

Length of output: 241

* 123-123: The instantiation of `GatewayLogic` with the `zone` parameter is correct and aligns with the summary. * 126-129: The logic for handling pubsub channels and messages is correctly implemented as per the summary. * 137-147: The updated logic for handling node pings through pubsub channels is correct. Ensure serialization and deserialization of `ping` are compatible with expected data structures. * 152-162: The updated logic for handling gateway pings through pubsub channels is correct. Similar to node pings, ensure serialization compatibility. * 165-165: The renaming of `ping_global_gateway` to `ping_other_gateways` and its invocation is correctly implemented as per the summary. * 179-179: The logic for broadcasting a node ping to other nodes in the same zone is correctly implemented. * 194-208: > 📝 **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [184-201]

The logic for handling BestNodes requests, including the use of ip2location for determining the requester's location and routing decisions, is correctly updated.

  • 216-226: > 📝 NOTE

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

The handling of WhipConnect and WhepConnect requests, including routing to the appropriate node based on location, is correctly updated.

  • 241-241: The handling of WebrtcConnect requests, including routing to the appropriate node based on location, is correctly updated.
  • 300-311: The ping_other_gateways function correctly implements the logic for sending pings to other gateways, including the new zone parameter.
servers/media-server/src/server/gateway/rpc/http.rs (1)
  • 62-62: Corrected the method call from BestNodest to BestNodes, aligning with the summary.
servers/media-server/src/server/webrtc.rs (4)
  • 15-15: Renaming INNER_GATEWAY_SERVICE to GATEWAY_SERVICE is correctly implemented as per the summary.
  • 71-71: The addition of the zone: &str parameter to run_webrtc_server function is correct. Ensure all calls to this function are updated accordingly.
Verification successful

Given the lack of output from the initial script, it's necessary to adjust our approach to ensure we're accurately capturing calls to run_webrtc_server with the correct number of parameters, including the newly added zone parameter. Let's broaden the search to capture any calls to this function, regardless of the number of parameters, to verify if they've been updated accordingly.


The verification process has identified a call to run_webrtc_server in ./servers/media-server/src/main.rs:125 that includes the new zone parameter (&args.sdn_zone), indicating that the function's calls have been updated accordingly. This aligns with the requirement mentioned in the review comment. Based on the available evidence, it appears that the addition of the zone: &str parameter to the run_webrtc_server function and the update of its calls have been correctly implemented, at least for the instance found.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if all calls to run_webrtc_server have been updated to include the new `zone` parameter.
ast-grep --lang rust --pattern $'run_webrtc_server($_, $_, $_, $_, $_, $_)'

Length of output: 76



Script:

#!/bin/bash
# Broaden the search to capture any calls to run_webrtc_server, to verify if the new `zone` parameter is included.
ast-grep --lang rust --pattern $'run_webrtc_server($$$)'

Length of output: 231

* 126-126: The `ping_gateway` function correctly includes the new `zone` parameter, aligning with the summary. * 391-394: The `ping_gateway` function's implementation, including the `zone` parameter, is correct and aligns with the summary.

@@ -3,23 +3,24 @@ use std::{sync::Arc, time::Duration};
use async_std::stream::StreamExt;
use clap::Parser;
use cluster::{
atm0s_sdn::{Publisher, PubsubSdk},
Copy link

Choose a reason for hiding this comment

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

Missing removal of NodePong from rpc::gateway imports as mentioned in the summary.

Copy link

codecov bot commented Feb 4, 2024

Codecov Report

Attention: 109 lines in your changes are missing coverage. Please review.

Comparison is base (a74da8a) 50.32% compared to head (91af3e9) 50.25%.

Files Patch % Lines
servers/media-server/src/server/gateway.rs 0.00% 61 Missing ⚠️
servers/media-server/src/server/gateway/logic.rs 50.87% 28 Missing ⚠️
...rs/media-server/src/server/gateway/webrtc_route.rs 0.00% 5 Missing ⚠️
servers/media-server/src/server/rtmp.rs 0.00% 5 Missing ⚠️
servers/media-server/src/server/webrtc.rs 0.00% 5 Missing ⚠️
...-server/src/server/gateway/logic/inner_registry.rs 90.62% 3 Missing ⚠️
servers/media-server/src/main.rs 0.00% 1 Missing ⚠️
...ervers/media-server/src/server/gateway/rpc/http.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #219      +/-   ##
==========================================
- Coverage   50.32%   50.25%   -0.08%     
==========================================
  Files         155      155              
  Lines       13851    13934      +83     
==========================================
+ Hits         6971     7002      +31     
- Misses       6880     6932      +52     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@giangndm giangndm merged commit 686e948 into 8xFF:master Feb 5, 2024
8 of 9 checks passed
@github-actions github-actions bot mentioned this pull request Feb 5, 2024
@giangndm giangndm deleted the feat-simply-gateway branch June 6, 2024 00:44
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.

None yet

1 participant