Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add info metric that allows us to track the config #14

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions src/main/java/net/ripe/rpki/rsyncit/config/AppConfig.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -64,5 +82,17 @@ static Function<String, String> 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()
));
}
}
Loading