Skip to content

spqr-ping #1168

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

Merged
merged 8 commits into from
May 12, 2025
Merged

spqr-ping #1168

merged 8 commits into from
May 12, 2025

Conversation

Denchick
Copy link
Collaborator

@Denchick Denchick commented May 5, 2025

The main idea is to add a fast ping handler without tls requirements.

➜  spqr git:(ping-idea) ✗ psql "host=localhost port=8432 dbname=spqr-ping user=spqr-ping sslmode=disable"
psql (14.17 (Homebrew), server 0.0.0)
Type "help" for help.

spqr-ping=> --fweq;
spqr-ping=> ;
spqr-ping=?> ;
no connection to the server
The connection to the server was lost. Attempting reset: Succeeded.
psql (14.17 (Homebrew), server 0.0.0)
spqr-ping=> qwef;
spqr-ping=?> fweqf;
no connection to the server
The connection to the server was lost. Attempting reset: Succeeded.
psql (14.17 (Homebrew), server 0.0.0)
spqr-ping=> ;fqwe
spqr-ping-?> ;fqw
no connection to the server
The connection to the server was lost. Attempting reset: Succeeded.
psql (14.17 (Homebrew), server 0.0.0)
spqr-ping-> 

@Denchick Denchick requested a review from Copilot May 5, 2025 16:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a fast ping handler that bypasses TLS requirements for quick health checks.

  • Added ping detection logic in the router to route “spqr-ping” requests to a dedicated ping handler.
  • Introduced a new preRoutePingPong function to assign the ping rule and process ping requests.
  • Implemented a Ping method in the client interactor to send back a “pong” response.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
router/rulerouter/rulerouter.go Added debug logging and ping detection logic along with a dedicated preRoutePingPong function.
router/instance/instance.go Extended connection handling to process ping requests and send appropriate backend messages.
pkg/clientinteractor/interactor.go Implemented the Ping method to handle ping requests by writing header and data row messages.

@Denchick Denchick force-pushed the ping-idea branch 2 times, most recently from 6f75f44 to 8ac1d7a Compare May 5, 2025 17:34
@Denchick Denchick requested a review from Copilot May 5, 2025 17:39
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a fast ping handler for connections with "spqr-ping" that bypasses TLS checks. Key changes include:

  • Routing logic updates to detect "spqr-ping" in both the RuleRouter and Instance implementations.
  • Implementation of a new preRoutePingPong function to assign rules and handle ping-specific authentication.
  • An added ReadyForQuery method in the PSQLInteractor for sending backend messages during ping.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
router/rulerouter/rulerouter.go Adds spqr-ping routing support via preRoutePingPong function.
router/instance/instance.go Integrates spqr-ping handling by sending ping messages and processing responses.
pkg/clientinteractor/interactor.go Introduces a new ReadyForQuery method for ping response handling.

@Denchick Denchick force-pushed the ping-idea branch 2 times, most recently from 893b70d to e5c6cfa Compare May 8, 2025 10:46
@Denchick
Copy link
Collaborator Author

Denchick commented May 8, 2025

It works

spqr-ping=> gqwe;
SPQR router is alive

spqr-ping=> fwqe;
SPQR router is alive

spqr-ping=> weqf;
SPQR router is alive

spqr-ping=> --qwef;
spqr-ping=> wegf;
SPQR router is alive

spqr-ping=> ;
SPQR router is alive

spqr-ping=> ;
SPQR router is alive

spqr-ping=> qwef;
SPQR router is alive

@Denchick
Copy link
Collaborator Author

Denchick commented May 8, 2025

Take into account sslmode:

root@regress_tests:/regress# psql "host=regress_router port=6432 user=spqr-ping dbname=spqr-ping sslmode=disable"
SPQR router is alive
psql (13.20 (Ubuntu 13.20-1.pgdg20.04+1), server 0.0.0)
Type "help" for help.

spqr-ping=> gqwefrq;
SPQR router is alive

spqr-ping=> \c spqr-console
connection to server at "regress_router" (172.18.0.8), port 6432 failed: ERROR:  SSL IS REQUIRED
Previous connection kept
spqr-ping=> 

@reshke reshke enabled auto-merge (squash) May 12, 2025 11:54
@reshke reshke merged commit 32aa725 into master May 12, 2025
62 checks passed
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.

3 participants