-
Notifications
You must be signed in to change notification settings - Fork 51
feat(QTDI-2030): Add health and readiness endpoints to component-server #1245
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
Open
undx
wants to merge
7
commits into
master
Choose a base branch
from
copilot/QTDI-2030_health_readiness_endpoints
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c0a404
feat(QTDI-2030): Add health and readiness endpoints to component-server
undx 95af6b8
fix(QTDI-2030): address review round 1 — architectural refactor liven…
undx 63dbb6c
Merge branch 'master' into copilot/QTDI-2030_health_readiness_endpoints
undx 77896cb
fix(QTDI-2030): address review round 2 — liveness/readiness architect…
undx 919201c
fix(QTDI-2030): add missing configuration mock in ReadinessResourceIm…
undx 7d686b8
fix(QTDI-3020): fix sonar issues
undx 8cb5888
fix(QTDI-2030): reuse vault WebTarget for ping, remove dead RequestCo…
undx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...ponent-server-api/src/main/java/org/talend/sdk/component/server/api/LivenessResource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * Copyright (C) 2006-2026 Talend Inc. - www.talend.com | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.talend.sdk.component.server.api; | ||
|
|
||
| import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
|
|
||
| import javax.ws.rs.GET; | ||
| import javax.ws.rs.Path; | ||
| import javax.ws.rs.Produces; | ||
| import javax.ws.rs.core.Response; | ||
|
|
||
| import org.eclipse.microprofile.openapi.annotations.Operation; | ||
| import org.eclipse.microprofile.openapi.annotations.media.Content; | ||
| import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
| import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; | ||
| import org.eclipse.microprofile.openapi.annotations.tags.Tag; | ||
| import org.talend.sdk.component.server.front.model.HealthStatus; | ||
|
|
||
| @Path("liveness") | ||
| @Tag(name = "Health", description = "Kubernetes liveness probe endpoint.") | ||
| public interface LivenessResource { | ||
|
|
||
| @GET | ||
| @Produces(APPLICATION_JSON) | ||
| @Operation(operationId = "getLiveness", | ||
| description = "Liveness probe: returns 200 when the JVM is healthy (no fatal error recorded). " | ||
| + "Returns 503 with a cause when a VirtualMachineError (e.g. OutOfMemoryError) has been intercepted.") | ||
| @APIResponse(responseCode = "200", | ||
| description = "Application is healthy.", | ||
| content = @Content(mediaType = APPLICATION_JSON, | ||
| schema = @Schema(implementation = HealthStatus.class))) | ||
| @APIResponse(responseCode = "503", | ||
| description = "Application has encountered a fatal error.", | ||
| content = @Content(mediaType = APPLICATION_JSON, | ||
| schema = @Schema(implementation = HealthStatus.class))) | ||
| Response getLiveness(); | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
...onent-server-api/src/main/java/org/talend/sdk/component/server/api/ReadinessResource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * Copyright (C) 2006-2026 Talend Inc. - www.talend.com | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.talend.sdk.component.server.api; | ||
|
|
||
| import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
|
|
||
| import javax.ws.rs.GET; | ||
| import javax.ws.rs.Path; | ||
| import javax.ws.rs.Produces; | ||
| import javax.ws.rs.core.Response; | ||
|
|
||
| import org.eclipse.microprofile.openapi.annotations.Operation; | ||
| import org.eclipse.microprofile.openapi.annotations.media.Content; | ||
| import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
| import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; | ||
| import org.eclipse.microprofile.openapi.annotations.tags.Tag; | ||
| import org.talend.sdk.component.server.front.model.HealthStatus; | ||
|
|
||
| @Path("readiness") | ||
| @Tag(name = "Health", description = "Kubernetes readiness probe endpoint.") | ||
| public interface ReadinessResource { | ||
|
|
||
| @GET | ||
| @Produces(APPLICATION_JSON) | ||
| @Operation(operationId = "getReadiness", | ||
| description = "Readiness probe: returns 200 when the component index is loaded and the server is ready " | ||
| + "to serve traffic. Returns 503 with a cause otherwise.") | ||
| @APIResponse(responseCode = "200", | ||
| description = "Server is ready.", | ||
| content = @Content(mediaType = APPLICATION_JSON, | ||
| schema = @Schema(implementation = HealthStatus.class))) | ||
| @APIResponse(responseCode = "503", | ||
| description = "Server is not ready.", | ||
| content = @Content(mediaType = APPLICATION_JSON, | ||
| schema = @Schema(implementation = HealthStatus.class))) | ||
| Response getReadiness(); | ||
| } |
30 changes: 30 additions & 0 deletions
30
...-server-model/src/main/java/org/talend/sdk/component/server/front/model/HealthStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Copyright (C) 2006-2026 Talend Inc. - www.talend.com | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.talend.sdk.component.server.front.model; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Data | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class HealthStatus { | ||
|
|
||
| private String status; | ||
|
|
||
| private String cause; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...nent-server/src/main/java/org/talend/sdk/component/server/front/LivenessResourceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * Copyright (C) 2006-2026 Talend Inc. - www.talend.com | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.talend.sdk.component.server.front; | ||
|
|
||
| import javax.enterprise.context.ApplicationScoped; | ||
| import javax.inject.Inject; | ||
| import javax.ws.rs.core.Response; | ||
|
|
||
| import org.talend.sdk.component.server.api.LivenessResource; | ||
| import org.talend.sdk.component.server.front.model.HealthStatus; | ||
| import org.talend.sdk.component.server.service.FatalState; | ||
|
|
||
| @ApplicationScoped | ||
| public class LivenessResourceImpl implements LivenessResource { | ||
|
|
||
| private static final String STATUS_UP = "UP"; | ||
|
|
||
| private static final String STATUS_DOWN = "DOWN"; | ||
|
|
||
| @Inject | ||
| private FatalState fatalState; | ||
|
|
||
| @Override | ||
| public Response getLiveness() { | ||
| if (fatalState.hasFatalError()) { | ||
| return Response | ||
| .status(Response.Status.SERVICE_UNAVAILABLE) | ||
| .entity(new HealthStatus(STATUS_DOWN, fatalState.getCause())) | ||
| .build(); | ||
| } | ||
| return Response.ok(new HealthStatus(STATUS_UP, null)).build(); | ||
| } | ||
| } |
99 changes: 99 additions & 0 deletions
99
...ent-server/src/main/java/org/talend/sdk/component/server/front/ReadinessResourceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /** | ||
| * Copyright (C) 2006-2026 Talend Inc. - www.talend.com | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.talend.sdk.component.server.front; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| import javax.enterprise.context.ApplicationScoped; | ||
| import javax.inject.Inject; | ||
| import javax.ws.rs.core.Response; | ||
|
|
||
| import org.talend.sdk.component.server.api.ReadinessResource; | ||
| import org.talend.sdk.component.server.configuration.ComponentServerConfiguration; | ||
| import org.talend.sdk.component.server.front.model.HealthStatus; | ||
| import org.talend.sdk.component.server.service.ComponentManagerService; | ||
| import org.talend.sdk.components.vault.client.VaultClient; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @ApplicationScoped | ||
| public class ReadinessResourceImpl implements ReadinessResource { | ||
|
|
||
| private static final String STATUS_UP = "UP"; | ||
|
|
||
| private static final String STATUS_DOWN = "DOWN"; | ||
|
|
||
| private static final long VAULT_CACHE_TTL_MS = 5_000L; | ||
|
|
||
| @Inject | ||
| private ComponentManagerService componentManagerService; | ||
|
|
||
| @Inject | ||
| private ComponentServerConfiguration configuration; | ||
|
|
||
| @Inject | ||
| private VaultClient vaultClient; | ||
|
|
||
| private final AtomicBoolean cachedVaultResult = new AtomicBoolean(true); | ||
|
|
||
| private final AtomicLong lastVaultCheck = new AtomicLong(0L); | ||
|
|
||
| @Override | ||
| public Response getReadiness() { | ||
| if (!componentManagerService.isStarted()) { | ||
| return Response | ||
| .status(Response.Status.SERVICE_UNAVAILABLE) | ||
| .entity(new HealthStatus(STATUS_DOWN, "Component index not ready")) | ||
| .build(); | ||
| } | ||
| if (configuration.getHealthVaultEnabled()) { | ||
| final HealthStatus vaultStatus = checkVaultCached(); | ||
| if (STATUS_DOWN.equals(vaultStatus.getStatus())) { | ||
| return Response.status(Response.Status.SERVICE_UNAVAILABLE).entity(vaultStatus).build(); | ||
| } | ||
| } | ||
| return Response.ok(new HealthStatus(STATUS_UP, null)).build(); | ||
| } | ||
|
|
||
| private HealthStatus checkVaultCached() { | ||
| final long now = System.currentTimeMillis(); | ||
| if (now - lastVaultCheck.get() < VAULT_CACHE_TTL_MS) { | ||
| return cachedVaultResult.get() | ||
| ? new HealthStatus(STATUS_UP, null) | ||
| : new HealthStatus(STATUS_DOWN, "Vault is not reachable"); | ||
| } | ||
| try { | ||
| final boolean reachable = vaultClient.ping(); | ||
| cachedVaultResult.set(reachable); | ||
| lastVaultCheck.set(now); | ||
| if (!reachable) { | ||
| log.warn("Readiness check: Vault is not reachable"); | ||
| return new HealthStatus(STATUS_DOWN, "Vault is not reachable"); | ||
| } | ||
| } catch (final VirtualMachineError vme) { | ||
| throw vme; | ||
| } catch (final Throwable t) { | ||
| cachedVaultResult.set(false); | ||
| lastVaultCheck.set(now); | ||
| final String cause = "Vault connectivity check failed: " + t.getMessage(); | ||
| log.warn("Readiness check failed: {}", cause); | ||
| return new HealthStatus(STATUS_DOWN, cause); | ||
| } | ||
| return new HealthStatus(STATUS_UP, null); | ||
| } | ||
|
undx marked this conversation as resolved.
Comment on lines
+74
to
+98
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.