diff --git a/api/src/main/java/io/kafbat/ui/service/ApplicationInfoService.java b/api/src/main/java/io/kafbat/ui/service/ApplicationInfoService.java index 0a04ce9d6..11221cd4d 100644 --- a/api/src/main/java/io/kafbat/ui/service/ApplicationInfoService.java +++ b/api/src/main/java/io/kafbat/ui/service/ApplicationInfoService.java @@ -13,16 +13,18 @@ import java.util.Optional; import java.util.Properties; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.GitProperties; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; @Service public class ApplicationInfoService { + @Value("${github.release.info.timeout:10}") + private int githubApiMaxWaitTime; - private final GithubReleaseInfo githubReleaseInfo = new GithubReleaseInfo(); + private final GithubReleaseInfo githubReleaseInfo = new GithubReleaseInfo(githubApiMaxWaitTime); private final DynamicConfigOperations dynamicConfigOperations; private final BuildProperties buildProperties; diff --git a/api/src/main/java/io/kafbat/ui/util/GithubReleaseInfo.java b/api/src/main/java/io/kafbat/ui/util/GithubReleaseInfo.java index e3f546ad8..0db6d3a61 100644 --- a/api/src/main/java/io/kafbat/ui/util/GithubReleaseInfo.java +++ b/api/src/main/java/io/kafbat/ui/util/GithubReleaseInfo.java @@ -11,8 +11,6 @@ public class GithubReleaseInfo { private static final String GITHUB_LATEST_RELEASE_RETRIEVAL_URL = "https://api.github.com/repos/kafbat/kafka-ui/releases/latest"; - private static final Duration GITHUB_API_MAX_WAIT_TIME = Duration.ofSeconds(10); - public record GithubReleaseDto(String html_url, String tag_name, String published_at) { static GithubReleaseDto empty() { @@ -24,17 +22,17 @@ static GithubReleaseDto empty() { private final Mono refreshMono; - public GithubReleaseInfo() { - this(GITHUB_LATEST_RELEASE_RETRIEVAL_URL); + public GithubReleaseInfo(int githubApiMaxWaitTime) { + this(GITHUB_LATEST_RELEASE_RETRIEVAL_URL, githubApiMaxWaitTime); } @VisibleForTesting - GithubReleaseInfo(String url) { + GithubReleaseInfo(String url, int githubApiMaxWaitTime) { this.refreshMono = new WebClientConfigurator().build() .get() .uri(url) .exchangeToMono(resp -> resp.bodyToMono(GithubReleaseDto.class)) - .timeout(GITHUB_API_MAX_WAIT_TIME) + .timeout(Duration.ofSeconds(githubApiMaxWaitTime)) .doOnError(th -> log.trace("Error getting latest github release info", th)) .onErrorResume(th -> true, th -> Mono.just(GithubReleaseDto.empty())) .doOnNext(release -> this.release = release) diff --git a/api/src/test/java/io/kafbat/ui/util/GithubReleaseInfoTest.java b/api/src/test/java/io/kafbat/ui/util/GithubReleaseInfoTest.java index 2f97d7a3a..8d78cedfc 100644 --- a/api/src/test/java/io/kafbat/ui/util/GithubReleaseInfoTest.java +++ b/api/src/test/java/io/kafbat/ui/util/GithubReleaseInfoTest.java @@ -37,7 +37,7 @@ void test() { """)); var url = mockWebServer.url("repos/kafbat/kafka-ui/releases/latest").toString(); - var infoHolder = new GithubReleaseInfo(url); + var infoHolder = new GithubReleaseInfo(url, 10); infoHolder.refresh().block(); var i = infoHolder.get();