Skip to content

Commit

Permalink
BE: Make gh version check timeout configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerdv committed Jul 31, 2024
1 parent 8c70126 commit 254bf0c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions api/src/main/java/io/kafbat/ui/util/GithubReleaseInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -24,17 +22,17 @@ static GithubReleaseDto empty() {

private final Mono<Void> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 254bf0c

Please sign in to comment.