Skip to content

Commit 254bf0c

Browse files
committed
BE: Make gh version check timeout configurable
1 parent 8c70126 commit 254bf0c

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

api/src/main/java/io/kafbat/ui/service/ApplicationInfoService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
import java.util.Optional;
1414
import java.util.Properties;
1515
import org.springframework.beans.factory.annotation.Autowired;
16+
import org.springframework.beans.factory.annotation.Value;
1617
import org.springframework.boot.info.BuildProperties;
1718
import org.springframework.boot.info.GitProperties;
1819
import org.springframework.scheduling.annotation.Scheduled;
1920
import org.springframework.stereotype.Service;
20-
import reactor.core.publisher.Mono;
2121

2222
@Service
2323
public class ApplicationInfoService {
24+
@Value("${github.release.info.timeout:10}")
25+
private int githubApiMaxWaitTime;
2426

25-
private final GithubReleaseInfo githubReleaseInfo = new GithubReleaseInfo();
27+
private final GithubReleaseInfo githubReleaseInfo = new GithubReleaseInfo(githubApiMaxWaitTime);
2628

2729
private final DynamicConfigOperations dynamicConfigOperations;
2830
private final BuildProperties buildProperties;

api/src/main/java/io/kafbat/ui/util/GithubReleaseInfo.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public class GithubReleaseInfo {
1111
private static final String GITHUB_LATEST_RELEASE_RETRIEVAL_URL =
1212
"https://api.github.com/repos/kafbat/kafka-ui/releases/latest";
1313

14-
private static final Duration GITHUB_API_MAX_WAIT_TIME = Duration.ofSeconds(10);
15-
1614
public record GithubReleaseDto(String html_url, String tag_name, String published_at) {
1715

1816
static GithubReleaseDto empty() {
@@ -24,17 +22,17 @@ static GithubReleaseDto empty() {
2422

2523
private final Mono<Void> refreshMono;
2624

27-
public GithubReleaseInfo() {
28-
this(GITHUB_LATEST_RELEASE_RETRIEVAL_URL);
25+
public GithubReleaseInfo(int githubApiMaxWaitTime) {
26+
this(GITHUB_LATEST_RELEASE_RETRIEVAL_URL, githubApiMaxWaitTime);
2927
}
3028

3129
@VisibleForTesting
32-
GithubReleaseInfo(String url) {
30+
GithubReleaseInfo(String url, int githubApiMaxWaitTime) {
3331
this.refreshMono = new WebClientConfigurator().build()
3432
.get()
3533
.uri(url)
3634
.exchangeToMono(resp -> resp.bodyToMono(GithubReleaseDto.class))
37-
.timeout(GITHUB_API_MAX_WAIT_TIME)
35+
.timeout(Duration.ofSeconds(githubApiMaxWaitTime))
3836
.doOnError(th -> log.trace("Error getting latest github release info", th))
3937
.onErrorResume(th -> true, th -> Mono.just(GithubReleaseDto.empty()))
4038
.doOnNext(release -> this.release = release)

api/src/test/java/io/kafbat/ui/util/GithubReleaseInfoTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void test() {
3737
"""));
3838
var url = mockWebServer.url("repos/kafbat/kafka-ui/releases/latest").toString();
3939

40-
var infoHolder = new GithubReleaseInfo(url);
40+
var infoHolder = new GithubReleaseInfo(url, 10);
4141
infoHolder.refresh().block();
4242

4343
var i = infoHolder.get();

0 commit comments

Comments
 (0)