Skip to content

Commit

Permalink
Expose the default HealthCheckUpdateHandler (#6002)
Browse files Browse the repository at this point in the history
Motivation:

When implementing a custom `HealthCheckUpdateHandler`, I just wanted to
add validation in front of the default implementation. However, it
wasn't possible because the default implementation has package-private
visibility.

Modifications:

- Expose the default `HealthCheckUpdateHandler` via
`HealthCheckUpdateHandler.of()`

Result:

You can now use the default `HealthCheckUpdateHandler` via
`HealthCheckUpdateHandler.of()`

---------

Co-authored-by: minux <songmw725@gmail.com>
  • Loading branch information
ikhoon and minwoox authored Dec 3, 2024
1 parent 2134872 commit 04e3a2a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,11 @@ public HealthCheckServiceBuilder longPolling(long maxLongPollingTimeoutMillis,
*
* @return {@code this}
* @see #updatable(HealthCheckUpdateHandler)
* @see HealthCheckUpdateHandler#of()
*/
public HealthCheckServiceBuilder updatable(boolean updatable) {
if (updatable) {
return updatable(DefaultHealthCheckUpdateHandler.INSTANCE);
return updatable(HealthCheckUpdateHandler.of());
}

updateHandler = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.concurrent.CompletionStage;

import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.annotation.UnstableApi;
import com.linecorp.armeria.server.HttpResponseException;
import com.linecorp.armeria.server.HttpStatusException;
import com.linecorp.armeria.server.Server;
Expand All @@ -28,6 +29,30 @@
*/
@FunctionalInterface
public interface HealthCheckUpdateHandler {

/**
* Returns the default {@link HealthCheckUpdateHandler} that accepts a JSON object which has a boolean
* property named {@code "healthy"} for a {@code PUT} or {@code POST} request. A JSON patch in a
* {@code PATCH} request is also accepted.
*
* <p>For example:
* <pre>{@code
* // Update healthiness of the server to unhealthy
* POST /internal/health HTTP/2.0
*
* { "healthy": false }
*
* // Patch healthiness of the server to unhealthy
* PATCH /internal/health HTTP/2.0
*
* [ { "op": "replace", "path": "/healthy", "value": false } ]
* }</pre>
*/
@UnstableApi
static HealthCheckUpdateHandler of() {
return DefaultHealthCheckUpdateHandler.INSTANCE;
}

/**
* Determines if the healthiness of the {@link Server} needs to be changed or not from the given
* {@link HttpRequest}.
Expand Down

0 comments on commit 04e3a2a

Please sign in to comment.