codecentric / spring-boot-admin

Admin UI for administration of spring boot applications
Apache License 2.0
12.32k stars 3.07k forks source link

Problem on getting latest application list programatically #3358

Closed Muyangmin closed 3 months ago

Muyangmin commented 4 months ago

Spring Boot Admin Server information

Client information

Description

Sorry but I've really read the issue notes and asked a question on StackOverflow(Question Link Here) before, but got no answers for 10 days. This problem is really important for me so hope I can get some help here, Thanks!

Below is the question copy:

We have integrated spring-boot-admin into many projects. Now, due to some tricky network reasons, I am unable to access the built-in UI interface of SBA. Therefore, I would like to periodically retrieve the equivalent information from its interface programmatically and write it to the database, so that I can read and present it from another program.

The simplest way seems to be to curl the application interface, but considering the timing logic and SBA are in the same program, I want to minimize unnecessary network calls. After some preliminary research, I wrote the following code(in Kotlin):

Environment: Kotlin 1.9.22, SpringBoot 2.7.10, SpringBootAdmin 2.7.14.

//Autowired
private val registry: ApplicationRegistry

fun refreshAppRegistry() {
    //I want get it synchronously, so Flux etc is not needed
    val applications = registry.applications.collectList().block()?.filterNotNull().orEmpty()

    //Handle data, the way I retrieve fields just like:
    appName = app.name,
    serviceUrl = it.registration.serviceUrl.orEmpty(),
    managementUrl = it.registration.managementUrl,
    buildVersion = it.buildVersion?.value,
    instanceStatus = it.statusInfo.status,
}

However, I found that the information I retrieved seems to be somewhat delayed: changes in the actuator/info information (such as build.version) of the monitored application are NOT reflected in my program. I have to restart the admin program to get the latest information. Please advise me on what went wrong, thank you!

erikpetzold commented 4 months ago

Hi @Muyangmin,

using registry.getApplications() should be the correct way to access this information, this is also what the frontend calls to display the data (via ApplicationsController).

First you wrote the changes are delayed (showing up a bit later), then you wrote you have to restart (otherwise there will be no updates at all?).

Also check if the data that is not being updated is coming from the monitored applications or from eureka. Maybe the Admin Server itself does not fetch updates from eureka (registryFetchIntervalSeconds)?

As you can see, there could be many reasons. If you do not find a solution please provide more information (logs, configuration, more code, runnable example, ...)

Muyangmin commented 4 months ago

Thanks for your detailed response. From the previous investigation, I can confirm that the information from SBA itself can be updated in a timely manner. Your reply has given me some new insights, and perhaps there are some potential issues in the infinite loop I use for updates. I will focus on investigating this aspect, and will reply here with any progress. 👍

Muyangmin commented 3 months ago

I'm sorry for the delayed response. After carefully rechecking our program, we found that in some very rare scenarios, our update operation would fail, and there was no exception handling in the loop (what a foolish mistake). After modifying the program and redeploying it, we no longer observed the previous issue, so the problem should be resolved. Thank you very much for your support!