diff --git a/src/main/java/net/ripe/rpki/rsyncit/config/AppConfig.java b/src/main/java/net/ripe/rpki/rsyncit/config/AppConfig.java index 7cd28c1..75be4ef 100644 --- a/src/main/java/net/ripe/rpki/rsyncit/config/AppConfig.java +++ b/src/main/java/net/ripe/rpki/rsyncit/config/AppConfig.java @@ -1,23 +1,29 @@ package net.ripe.rpki.rsyncit.config; +import io.micrometer.core.instrument.Gauge; +import io.micrometer.core.instrument.MeterRegistry; +import jakarta.annotation.PostConstruct; import lombok.Getter; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.actuate.info.Info; +import org.springframework.boot.actuate.info.InfoContributor; import org.springframework.boot.info.GitProperties; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; import java.time.Duration; +import java.util.Map; import java.util.function.Function; @Component @Getter -public class AppConfig { +public class AppConfig implements InfoContributor { private final String rrdpUrl; private final String rrdpReplaceHostWith; private final String rsyncPath; private final String cron; - private final String requestTimeout; + private final Duration requestTimeout; private final ApplicationInfo info; private final long targetDirectoryRetentionPeriodMs; private final int targetDirectoryRetentionCopiesCount; @@ -28,12 +34,13 @@ public AppConfig(@Value("${rrdpUrl}") String rrdpUrl, // Run every 10 minutes @Value("${cron:0 0/10 * * * ?}") String cron, // 3 minutes by default - @Value("${requestTimeout:PT180S}") String requestTimeout, + @Value("${requestTimeout:PT180S}") Duration requestTimeout, // delete rsync directories older than 1 hour @Value("${targetDirectoryRetentionPeriodMs:3600000}") long targetDirectoryRetentionPeriodMs, // do not keep more than 8 copies of rsync directories at once @Value("${targetDirectoryRetentionCopiesCount:8}") int targetDirectoryRetentionCopiesCount, - ApplicationInfo info) { + ApplicationInfo info, + MeterRegistry registry) { this.rrdpUrl = rrdpUrl; this.rrdpReplaceHostWith = rrdpReplaceHostWith; this.rsyncPath = rsyncPath; @@ -42,10 +49,21 @@ public AppConfig(@Value("${rrdpUrl}") String rrdpUrl, this.info = info; this.targetDirectoryRetentionPeriodMs = targetDirectoryRetentionPeriodMs; this.targetDirectoryRetentionCopiesCount = targetDirectoryRetentionCopiesCount; + + Gauge.builder("rsyncit.configuration", () -> 1.0) + .baseUnit("info") + .tag("rrdp_url", rrdpUrl) + .tag("rrdp_override_host", rrdpReplaceHostWith) + .tag("request_timeout_seconds", String.valueOf(requestTimeout.toSeconds())) + .tag("retention_period_minutes", String.valueOf(Duration.ofMillis(targetDirectoryRetentionPeriodMs).toMinutes())) + .tag("retention_copies", String.valueOf(targetDirectoryRetentionCopiesCount)) + .tag("build", info.gitCommitId()) + .strongReference(true) + .register(registry); } public Config getConfig() { - return new Config(rrdpUrl, substitutor(rrdpReplaceHostWith), rsyncPath, cron, Duration.parse(requestTimeout), + return new Config(rrdpUrl, substitutor(rrdpReplaceHostWith), rsyncPath, cron, requestTimeout, targetDirectoryRetentionPeriodMs, targetDirectoryRetentionCopiesCount); } @@ -64,5 +82,17 @@ static Function substitutor(String rrdpReplaceHostWith) { public static ApplicationInfo appInfo(GitProperties gitProperties) { return new ApplicationInfo(gitProperties.getShortCommitId()); } - + @Override + public void contribute(Info.Builder builder) { + builder.withDetail("config", Map.of( + "cron", cron, + "rrdp_url", rrdpUrl, + "rrdp_replace_host", rrdpReplaceHostWith, + "rsync_path", rsyncPath, + "request_timeout_seconds", String.valueOf(requestTimeout.toSeconds()), + "retention_period_minutes", String.valueOf(Duration.ofMillis(targetDirectoryRetentionPeriodMs).toMinutes()), + "retention_copies", String.valueOf(targetDirectoryRetentionCopiesCount), + "build", info.gitCommitId() + )); + } }