Add `/healthz` endpoint for basic health check in S3Proxy

- Implemented a new `/healthz` endpoint to handle GET requests.
- Added the `handleVersionRequest` method to return a JSON response with health status:
  - Response: `{ "status": "OK" }`
- Updated `S3ProxyHandler` to route requests to `/healthz` and handle responses effectively.
- The endpoint provides a simple mechanism for health monitoring and status validation.
pull/763/head
Azmy 2025-01-21 14:22:16 +02:00
rodzic b8bd258dcd
commit e0a1cf7657
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 717577B06E2592C1
1 zmienionych plików z 18 dodań i 0 usunięć

Wyświetl plik

@ -293,6 +293,12 @@ public class S3ProxyHandler {
String uri = request.getRequestURI();
String originalUri = request.getRequestURI();
// Check for the /version endpoint
if ("/healthz".equals(uri) && "GET".equalsIgnoreCase(method)) {
handleVersionRequest(response);
return;
}
if (!this.servicePath.isEmpty()) {
if (uri.length() > this.servicePath.length()) {
uri = uri.substring(this.servicePath.length());
@ -2029,6 +2035,18 @@ public class S3ProxyHandler {
response.addHeader(HttpHeaders.ETAG, maybeQuoteETag(eTag));
}
private void handleVersionRequest(HttpServletResponse response) throws IOException {
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
String versionInfo = "{ \"status\": \"OK\"}";
try (PrintWriter writer = response.getWriter()) {
writer.write(versionInfo);
writer.flush();
}
}
private void handlePostBlob(HttpServletRequest request,
HttpServletResponse response, InputStream is, BlobStore blobStore,