feat(#5352): healthgroups endpoint#5416
Conversation
| * specific data in {@link HealthGroupsCache} on receiving an | ||
| * {@link InstanceDeregisteredEvent}. | ||
| */ | ||
| public class HealthGroupsCacheCleanupTrigger extends AbstractEventHandler<InstanceDeregisteredEvent> { |
There was a problem hiding this comment.
This seems a bit an overkill to me.
It would be enough to invoke the deletion in the StatusUpdater with a doOnNext as it's already done to persist the groups (actually, it's enough to add an if there to check the event type and either call the save or the delete method).
We're scheduling a thread to constantly check for a single even type, which barely happens, where the StatusUpdater is already handling all of them anyway.
There was a problem hiding this comment.
StatusUpdater polls the /health endpoint — it does not receive InstanceDeregisteredEvent. A deregistered instance simply stops being polled (doUpdateStatus returns early if !instance.isRegistered()), so eviction would never fire there.
I'll investigate a little further and probably will either
(a) keep a lightweight event subscription but reuse an existing handler/scheduler, or
(b) accept the small overhead since cleanup-on-deregister is the established pattern in SBA
There was a problem hiding this comment.
StatusUpdater polls the /health endpoint — it does not receive InstanceDeregisteredEvent.
Indeed. For a moment I had the impression it's handled there because the journal view shows all of them.
I'll investigate a little further and probably will either
(a) keep a lightweight event subscription but reuse an existing handler/scheduler, or
(b) accept the small overhead since cleanup-on-deregister is the established pattern in SBA
Wouldn't be enough to have a Spring Boot's @EventListener for the specific application event and remove the entry from the cache when it's received?
|
|
||
| describe('SSE reactive updates', () => { | ||
| it('should call fetchHealth once on mount, not on SSE version changes', async () => { | ||
| it('should call fetchCachedHealthGroups once on mount, not on SSE version changes', async () => { |
There was a problem hiding this comment.
Actually I think we should call the fetchHealthGroups when an SSE is received now, otherwise stale data may be potentially used.
This comment is not specifically related to this test case, but it's a more general statement.
There was a problem hiding this comment.
Good catch, and agreed in principle. The current else branch only invalidates the per-group details (group.data = null) but keeps the previously fetched group list, so a group added/removed at runtime would indeed show stale entries until the instance id changes or the view is remounted (although this seems to be an edge case).
I'll update onInstanceChanged so the same-instance branch also calls fetchHealthGroups() (which already resets healthGroupOpenStatus/healthGroupLoadingMap and clears stale data), making the displayed group list self-correcting on SSE updates.
There was a problem hiding this comment.
Yep.
Also because, from @SteKoe in a previous PR about a Thymeleaf fix, I discovered that the configuration properties can be changed at runtime from SBA.
Probably, to cover this case as well, we would need SSE also for the health groups, but I don't know how much worthy it really is. Unless a STATUS_CHANGED even is also created when the health response body changes in general and not just by the status (UP, DOWN and so on).
Performance and code clearity wise, it would then indeed be better to update the model of the instance to also have the health groups in it.
| this.cache.remove(instanceId); | ||
| } | ||
| else { | ||
| this.cache.put(instanceId, List.copyOf(groups)); |
There was a problem hiding this comment.
I think we should ensure that groups are unique, either here by using a LinkedHashSet instead of a List or in the UI to avoid potentially duplicated entries.
| if (Array.isArray(res.data.groups)) { | ||
| this.healthGroups = res.data.groups.map((name: string) => ({ | ||
| if (Array.isArray(res.data)) { | ||
| this.healthGroups = res.data.map((name: string) => ({ |
There was a problem hiding this comment.
Hi @ulischulte.
Will this assignment trigger a UI re-rendering?
If it's so, we should maybe check the content of the response first and set the new state (health groups + reset of state of the accorditions) only if there is indeed a change in the collection of the returned group names.
Otherwise, on every fetch, we'll be re-rendering the UI for nothing if nothing really has changed in the context of the health groups.
There was a problem hiding this comment.
Yes, it will trigger a re-rendering of UI. I will add a check to prevent this in terms of UX, as it will also reset the collapsed state. Changing groups in backend will not happen that often, though.
There was a problem hiding this comment.
Changing groups in backend will not happen that often, though.
I was wondering exactly because their update will be very rare.
# Conflicts: # spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/services/StatusUpdaterTest.java
…in/server/services/StatusUpdater.java Co-authored-by: Cosimo Damiano Prete <8491864+cdprete@users.noreply.github.com>
fa4bcf7 to
ffe3250
Compare
|
Hi @ulischulte. What do you think about the idea of adding a metadata boolean property that the applications under monitoring can populate to indicate if they use health groups or not? Moreover, another optimization (to be verified if it's indeed possible; for now it's just an idea) would be to not just return the group names, but the name of the health indicators they include as well. For example: I'm still in favour of adding them to the |
| this.healthGroupLoadingMap = {}; | ||
| } | ||
| // Re-fetch the (server-cached) group list on every instance change | ||
| this.fetchHealthGroups(); |
There was a problem hiding this comment.
We should do this only if the instance has changed in some meaningful way regarding its status, which means to not do it if the event that gets sent is INFO_UPDATED.
If the process InfoContributor is enabled, the data returned by https://docs.spring.io/spring-boot/api/rest/actuator/info.html changes on every poll, which would mean we're re-fetching the health groups over and over for no real reason.
Closes #5352:
Added caching and a dedicated REST endpoint for health groups.
When SBA polls an application's /health endpoint, the response may include a groups field (e.g., ["liveness", "readiness"]). Previously this data was fetched on-the-fly from the client. Now:
Key design decisions