Skip to content

refactor: custom HTTP endpoint registration#2380

Merged
tac0turtle merged 4 commits into
mainfrom
refactor/custom-http-endpoints
Jun 19, 2025
Merged

refactor: custom HTTP endpoint registration#2380
tac0turtle merged 4 commits into
mainfrom
refactor/custom-http-endpoints

Conversation

@tac0turtle

@tac0turtle tac0turtle commented Jun 19, 2025

Copy link
Copy Markdown
Contributor

Overview

This commit introduces a new file pkg/rpc/server/http.go to provide a centralized location for registering custom, non-gRPC, plain HTTP endpoints.

A new function RegisterCustomHTTPEndpoints(mux *http.ServeMux) is defined in this file. The existing /health/live endpoint has been moved into this function. The NewServiceHandler in pkg/rpc/server/server.go now calls RegisterCustomHTTPEndpoints to include these custom routes.

This change helps to keep the server.go file cleaner and makes it easier to manage and add new custom HTTP endpoints in the future.

A test file pkg/rpc/server/http_test.go has been added with TestRegisterCustomHTTPEndpoints to ensure that endpoints registered via this new structure are correctly served.

closes #2375

Summary by CodeRabbit

  • New Features
    • Introduced a new liveness health check endpoint at /health/live, returning a 200 OK status and "OK" response.
  • Tests
    • Added tests to verify the correct registration and response of the /health/live endpoint.

This commit introduces a new file `pkg/rpc/server/http.go` to provide a centralized location for registering custom, non-gRPC, plain HTTP endpoints.

A new function `RegisterCustomHTTPEndpoints(mux *http.ServeMux)` is defined in this file.
The existing `/health/live` endpoint has been moved into this function.
The `NewServiceHandler` in `pkg/rpc/server/server.go` now calls `RegisterCustomHTTPEndpoints` to include these custom routes.

This change helps to keep the `server.go` file cleaner and makes it easier to manage and add new custom HTTP endpoints in the future.

A test file `pkg/rpc/server/http_test.go` has been added with `TestRegisterCustomHTTPEndpoints` to ensure that endpoints registered via this new structure are correctly served.
@coderabbitai

coderabbitai Bot commented Jun 19, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@tac0turtle has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 59 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5393147 and 3a611c0.

📒 Files selected for processing (2)
  • pkg/rpc/server/http.go (1 hunks)
  • test/docker-e2e/doc.go (1 hunks)

Walkthrough

A new HTTP GET endpoint /health/live has been introduced for health checks. The endpoint is registered in the HTTP server mux, returns a 200 OK status, and responds with "OK". Corresponding tests have been added to verify the endpoint's behavior. Integration of the endpoint occurs within the existing service handler setup.

Changes

File(s) Change Summary
pkg/rpc/server/http.go Added RegisterCustomHTTPEndpoints to register custom HTTP endpoints, including /health/live.
pkg/rpc/server/http_test.go Added tests for RegisterCustomHTTPEndpoints, verifying /health/live endpoint functionality.
pkg/rpc/server/server.go Integrated RegisterCustomHTTPEndpoints into service handler setup.
pkg/rpc/server/server_test.go Added integration test for /health/live endpoint.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant HTTPServer
    participant ServiceHandler

    Client->>HTTPServer: GET /health/live
    HTTPServer->>ServiceHandler: Handle /health/live
    ServiceHandler-->>HTTPServer: 200 OK, "OK"
    HTTPServer-->>Client: 200 OK, "OK"
Loading

Assessment against linked issues

Objective Addressed Explanation
Add HTTP GET endpoint /health/live for health checks (returns 200 OK, standard headers) (#2375)
Accept GET requests and do not require custom headers or request bodies for health check (#2375)
Endpoint returns standard HTTP status codes for health check (#2375)
Endpoint returns expected JSON response: {"status": "PASS"} (#2375) Response is plain text "OK", not JSON as specified in the issue.

Assessment against linked issues: Out-of-scope changes

Code Change (file_path) Explanation
Response body is "OK" instead of JSON {"status":"PASS"} (pkg/rpc/server/http.go, http_test.go, server_test.go) The implementation uses a plain text response, whereas the issue specifies a JSON object response.

Poem

In the server's warren, a new path appears,
/health/live responds to all probing ears.
"OK" is its answer, so simple and bright,
For rabbits and ops teams, a beacon of light.
Hop along, little packets, your health check is here!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

@github-actions

github-actions Bot commented Jun 19, 2025

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow CI and Release / buf-check (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped✅ passed✅ passedJun 19, 2025, 12:47 PM

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary of Changes

Hello @tac0turtle, 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 refactors the RPC server's HTTP endpoint registration by creating a new, dedicated file for custom, non-gRPC HTTP routes. This change aims to improve code organization and maintainability within the server.go file, making it cleaner and easier to manage and add new custom HTTP endpoints in the future. The existing /health/live endpoint has been migrated to this new structure, and comprehensive tests have been added to ensure its continued functionality.

Highlights

  • Centralized HTTP Endpoint Registration: A new file, pkg/rpc/server/http.go, has been introduced to provide a dedicated and centralized location for registering custom, non-gRPC, plain HTTP endpoints.
  • Moved Health Endpoint: The existing /health/live endpoint definition has been moved from pkg/rpc/server/server.go into the new RegisterCustomHTTPEndpoints function within pkg/rpc/server/http.go.
  • Integration with Service Handler: The NewServiceHandler function in pkg/rpc/server/server.go (at line 241) now calls RegisterCustomHTTPEndpoints(mux) to ensure that all custom HTTP routes are properly included and served by the main HTTP server.
  • Enhanced Testing: A new test file, pkg/rpc/server/http_test.go, has been added to specifically test the RegisterCustomHTTPEndpoints function. Additionally, pkg/rpc/server/server_test.go has been updated (starting at line 227) with TestHealthLiveEndpoint to verify the /health/live endpoint's functionality through the full service handler.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/rpc/server/http.go (1)

11-15: Consider restricting HTTP methods for the health endpoint.

The /health/live endpoint currently accepts all HTTP methods. For better REST semantics, it should only respond to GET requests.

Apply this diff to restrict to GET method only:

 mux.HandleFunc("/health/live", func(w http.ResponseWriter, r *http.Request) {
+    if r.Method != http.MethodGet {
+        w.WriteHeader(http.StatusMethodNotAllowed)
+        return
+    }
     w.Header().Set("Content-Type", "text/plain")
     w.WriteHeader(http.StatusOK)
     fmt.Fprintln(w, "OK")
 })
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cc7e0b and 108553e.

📒 Files selected for processing (4)
  • pkg/rpc/server/http.go (1 hunks)
  • pkg/rpc/server/http_test.go (1 hunks)
  • pkg/rpc/server/server.go (1 hunks)
  • pkg/rpc/server/server_test.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: test / Run Integration Tests
  • GitHub Check: test / Go Mod Tidy Check
  • GitHub Check: test / Run Unit Tests
  • GitHub Check: test / Build All Rollkit Binaries
  • GitHub Check: test / Build Docker Image
  • GitHub Check: lint / golangci-lint
  • GitHub Check: lint / markdown-lint
  • GitHub Check: Analyze (actions)
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (4)
pkg/rpc/server/server.go (1)

240-241: LGTM! Clean integration of centralized HTTP endpoint registration.

The placement of RegisterCustomHTTPEndpoints(mux) is ideal - after all gRPC service handlers are registered but before the h2c wrapper, ensuring custom HTTP endpoints are properly integrated into the service multiplexer.

pkg/rpc/server/server_test.go (1)

227-255: Excellent integration test coverage.

The test properly validates the /health/live endpoint through the full service handler integration, using appropriate mocks and verifying both HTTP status and response content. The test structure follows Go testing best practices.

pkg/rpc/server/http_test.go (1)

12-37: Well-structured unit test for the registration function.

This test effectively validates the RegisterCustomHTTPEndpoints function in isolation, providing good coverage for the /health/live endpoint behavior without requiring full service handler setup.

pkg/rpc/server/http.go (1)

8-23: Excellent centralization approach with clear documentation.

The function provides a clean, centralized location for custom HTTP endpoint registration. The documentation and example comments will help future developers understand how to add new endpoints properly.

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

Copy link
Copy Markdown
Contributor

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 centralizes the registration of custom HTTP endpoints, improving modularity and manageability. The changes include introducing pkg/rpc/server/http.go and the RegisterCustomHTTPEndpoints function, along with a new /health/live endpoint and associated tests. Suggestions include establishing robust error handling, clarifying mock roles in tests, and streamlining test assertions. Consider updating pkg/rpc/README.md to reflect the addition of plain HTTP endpoints.

Comment thread pkg/rpc/server/http.go
Comment thread pkg/rpc/server/server_test.go
Comment thread pkg/rpc/server/server_test.go
@tac0turtle tac0turtle changed the title refactor: centralize custom HTTP endpoint registration refactor: custom HTTP endpoint registration Jun 19, 2025
Comment thread pkg/rpc/server/http.go
// RegisterCustomHTTPEndpoints is the designated place to add new, non-gRPC, plain HTTP handlers.
// Additional custom HTTP endpoints can be registered on the mux here.
func RegisterCustomHTTPEndpoints(mux *http.ServeMux) {
mux.HandleFunc("/health/live", func(w http.ResponseWriter, r *http.Request) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

livez is a grpc/http post method, but most tooling does gets. this is a simple get method for existing devop tooling

@codecov

codecov Bot commented Jun 19, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.27%. Comparing base (2cc7e0b) to head (3a611c0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2380      +/-   ##
==========================================
+ Coverage   71.72%   72.27%   +0.54%     
==========================================
  Files          64       65       +1     
  Lines        6306     6315       +9     
==========================================
+ Hits         4523     4564      +41     
+ Misses       1381     1349      -32     
  Partials      402      402              
Flag Coverage Δ
combined 72.27% <100.00%> (+0.54%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tac0turtle
tac0turtle added this pull request to the merge queue Jun 19, 2025
Merged via the queue into main with commit bc16469 Jun 19, 2025
26 checks passed
@tac0turtle
tac0turtle deleted the refactor/custom-http-endpoints branch June 19, 2025 13:19
@github-project-automation github-project-automation Bot moved this to Done in Evolve Jun 19, 2025
@tac0turtle tac0turtle removed this from Evolve Aug 25, 2025
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.

[FEATURE] Add HTTP GET endpoint for health checks

2 participants