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

Proto payloads between RR and PHP Worker #23

Merged
merged 11 commits into from
Apr 1, 2024
Merged

Conversation

msmakouz
Copy link
Member

@msmakouz msmakouz commented Mar 11, 2024

Q A
Bugfix?
Breaks BC?
New feature? ✔️
Issues roadrunner-php/issues#13

@msmakouz msmakouz added the enhancement New feature or request label Mar 11, 2024
@msmakouz msmakouz self-assigned this Mar 11, 2024
Copy link

coderabbitai bot commented Mar 11, 2024

Walkthrough

The recent update introduces enhancements to the HTTP worker system, focusing on better handling of HTTP requests and responses. Key improvements include the introduction of HTTP DTO classes, a new isProto property for protocol checks, and refined methods for processing payloads and responses. Additionally, there's an upgrade in how headers are managed, ensuring more precise and secure operations.

Changes

Files Summary
src/HttpWorker.php Added new private static ?int $codec property, codec type determination, adjusted respond methods, new header methods
tests/Unit/HttpWorkerTest.php Introduces test cases for HttpWorker class covering request parsing, codec responses, attribute processing
tests/Unit/PSR7WorkerTest.php Added strict types declaration, changed class to final, removed TODO in tearDown method
tests/Unit/StreamResponseTest.php Changed class to final, no parent::tearDown() call in tearDown method

Poem

🐇✨
In the land of code, where the bytes do roam,
The HTTP workers, in their digital home,
Enhanced they stand, with DTOs in hand,
Parsing requests, responses grand.
With headers precise, and protocols known,
They hop through the net, in bytes they've grown. 🌐💻
🎉🐰

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

@msmakouz msmakouz marked this pull request as draft March 11, 2024 16:32
@msmakouz msmakouz changed the title Feature proto payloads Proto payloads between RR and PHP Worker Mar 11, 2024
Copy link

codecov bot commented Mar 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.55%. Comparing base (0bd1ef8) to head (8b35fd9).

Additional details and impacted files
@@              Coverage Diff              @@
##                3.x      #23       +/-   ##
=============================================
+ Coverage     21.46%   53.55%   +32.08%     
- Complexity       61       72       +11     
=============================================
  Files             4        4               
  Lines           177      211       +34     
=============================================
+ Hits             38      113       +75     
+ Misses          139       98       -41     

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

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0bd1ef8 and 7ea1cff.
Files ignored due to path filters (1)
  • composer.json is excluded by: !**/*.json
Files selected for processing (2)
  • src/HttpWorker.php (10 hunks)
  • src/HttpWorkerInterface.php (1 hunks)
Additional comments: 7
src/HttpWorkerInterface.php (1)
  • 29-31: The update to the $headers parameter in the respond method enhances type safety and clarity, which is a positive change. Ensure that all classes implementing HttpWorkerInterface are updated accordingly to match this new signature.
src/HttpWorker.php (6)
  • 8-11: New imports for HTTP DTO classes have been added to support proto payloads. Ensure these classes are used appropriately throughout the file and that their versions are compatible with the project's dependencies.
  • 41-41: Introduced a new isProto static property to determine if the payload is in proto format. This approach is efficient for payload type checking but ensure thread safety and consistency across multiple requests.
  • 65-70: The waitRequest method now includes logic to handle proto payloads. Ensure that the RequestProto class's mergeFromString method correctly parses the payload header and that requestFromProto accurately constructs a Request object from the proto message.
  • 163-200: The requestFromProto method constructs a Request object from a proto message. Verify that all fields are correctly mapped from the proto message to the Request object, especially considering type conversions and error handling for missing or malformed data.
  • 261-268: The createRespondPayload method has been modified to support creating payloads in proto format. Ensure that the conditional logic correctly determines when to use proto format and that the serialization to proto is accurate and efficient.
  • 271-277: The isProtoPayload method determines if the current payload is in proto format. This method relies on json_validate to check the format. Ensure that this approach reliably distinguishes between JSON and proto formats, considering potential edge cases.

composer.json Outdated Show resolved Hide resolved
@msmakouz msmakouz marked this pull request as ready for review March 28, 2024 15:49
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 7ea1cff and 8cb1887.
Files ignored due to path filters (1)
  • composer.json is excluded by !**/*.json
Files selected for processing (4)
  • src/HttpWorker.php (10 hunks)
  • tests/Unit/HttpWorkerTest.php (1 hunks)
  • tests/Unit/PSR7WorkerTest.php (3 hunks)
  • tests/Unit/StreamResponseTest.php (1 hunks)
Additional comments (3)
tests/Unit/PSR7WorkerTest.php (2)
  • 3-3: Adding declare(strict_types=1); is a good practice for enforcing type safety in PHP files.
  • 13-13: Changing the PSR7WorkerTest class to final is appropriate for test classes, as they typically should not be extended.
tests/Unit/StreamResponseTest.php (1)
  • 13-13: Changing the StreamResponseTest class to final is appropriate for test classes, as they typically should not be extended.

@@ -10,15 +10,14 @@
use Spiral\RoadRunner\Tests\Http\Unit\Stub\TestRelay;
use Spiral\RoadRunner\Worker;

class StreamResponseTest extends TestCase
final class StreamResponseTest extends TestCase
{
private TestRelay $relay;
private Worker $worker;

Copy link

Choose a reason for hiding this comment

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

Consider calling parent::tearDown() in the tearDown method to ensure compatibility with future versions of PHPUnit that might introduce teardown logic.

protected function tearDown(): void
{
    unset($this->relay, $this->worker);
+   parent::tearDown();
}

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
protected function tearDown(): void
{
unset($this->relay, $this->worker);
parent::tearDown();
}

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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8cb1887 and 7f7fa2a.
Files selected for processing (1)
  • composer.json (2 hunks)
Additional Context Used
Additional comments not posted (2)
composer.json (2)

44-47: The updates and additions to the dependencies in the require section are aligned with the PR objectives to enhance efficiency and performance through protocol buffers for payload handling. It's good to see that the versions specified allow for flexibility while ensuring compatibility with newer versions.

  • The update to spiral/roadrunner to support versions ^2023.3 || ^2024.1 is appropriate for ensuring compatibility with the latest features and fixes.
  • The update to spiral/roadrunner-worker to version ^3.5 and the addition of roadrunner-php/roadrunner-api-dto at version ^1.6 are crucial for the new feature implementation.
  • The addition of symfony/polyfill-php83 is a thoughtful inclusion for ensuring compatibility with PHP 8.3 features across different PHP versions.

76-77: The suggestion for ext-protobuf is a valuable addition, guiding users towards enhancing Protocol Buffers support. This aligns well with the PR's goal of introducing proto payload support and ensures users are aware of the optional but recommended extension to maximize performance.

src/HttpWorker.php Outdated Show resolved Hide resolved
composer.json Outdated
@@ -72,7 +73,8 @@
"analyze": "psalm"
},
"suggest": {
"spiral/roadrunner-cli": "Provides RoadRunner installation and management CLI tools"
"spiral/roadrunner-cli": "Provides RoadRunner installation and management CLI tools",
"ext-protobuf": "Provides Protocol Buffers support"
Copy link
Member

Choose a reason for hiding this comment

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

It would be beneficial to include a recommendation about this extension in the documentation. It's important to emphasize that it impacts performance. Without this extension, JSON operates faster than Proto.

src/HttpWorker.php Outdated Show resolved Hide resolved
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: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7f7fa2a and 8b35fd9.
Files selected for processing (2)
  • composer.json (2 hunks)
  • src/HttpWorker.php (10 hunks)
Files skipped from review as they are similar to previous changes (2)
  • composer.json
  • src/HttpWorker.php
Additional Context Used

@msmakouz msmakouz merged commit 2963562 into 3.x Apr 1, 2024
9 checks passed
@msmakouz msmakouz deleted the feature-proto-payloads branch April 1, 2024 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants