Skip to content

check if the pod is terminating in the healthcheck#431

Merged
Ian-Nara merged 12 commits intomainfrom
ian-UID2-5188-check-if-pod-terminating
May 2, 2025
Merged

check if the pod is terminating in the healthcheck#431
Ian-Nara merged 12 commits intomainfrom
ian-UID2-5188-check-if-pod-terminating

Conversation

@Ian-Nara
Copy link
Contributor

@Ian-Nara Ian-Nara commented May 1, 2025

No description provided.

Copy link
Contributor

@asloobq asloobq left a comment

Choose a reason for hiding this comment

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

Can you add unit tests

private AtomicReference<List<IHealthComponent>> componentList = new AtomicReference(new ArrayList<IHealthComponent>());
private AtomicReference<Boolean> cachedPodTerminating = new AtomicReference<>(false);
private long lastPodCheckTime = 0;
private static final long FILE_CHECK_INTERVAL_MS = 3000;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make this a configurable setting ?

boolean componentsHealthy = list.stream().filter(c -> !c.isHealthy()).count() == 0;
File file = new File("/app/pod_terminating");
boolean podTerminating = file.exists();
boolean podTerminating = checkPodTerminating();
Copy link
Contributor

Choose a reason for hiding this comment

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

probably don't need a new boolean variable

return componentsHealthy && !checkPodTerminating();
}

private boolean checkPodTerminating() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think checking for a pod termination file should be a responsibility of HealthManager. This could be done as its own health check component.

Copy link
Contributor Author

@Ian-Nara Ian-Nara May 1, 2025

Choose a reason for hiding this comment

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

If we reuse the pattern of the named components, then that would have us register to health manager by some string ID. Then we need some background thread monitoring continuously to update the health component right?

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need a background thread, you could use a period timer. A simple implementation:

private void periodicallyCheckForShutdownFile(Duration interval, String file) {
    this.vertx.setPeriodic(interval.toMillis(), l -> {
        if (vertx.fileSystem().existsBlocking(file)) {
            healthComponent.setHealthStatus(false, "shutting down");
        }
    });
}

@Ian-Nara Ian-Nara merged commit b91ce5e into main May 2, 2025
3 checks passed
@Ian-Nara Ian-Nara deleted the ian-UID2-5188-check-if-pod-terminating branch May 2, 2025 16:32
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