Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static void main(String[] args) {
Properties properties = new Properties();
properties.put("spring.codec.max-in-memory-size", "1GB");
properties.put("management.endpoints.web.exposure.include", "info,prometheus,health");
properties.put("management.metrics.enable.http.client.requests", "false");
application.setDefaultProperties(properties);
application.run(args);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.ripe.rpki.rsyncit.rrdp;

public class NotificationStructureException extends Exception {
public class NotificationStructureException extends RuntimeException {
public NotificationStructureException(String msg) {
super(msg);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.ripe.rpki.rsyncit.rrdp;

import com.google.common.util.concurrent.AtomicDouble;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
Expand All @@ -8,6 +9,7 @@

public final class RRDPFetcherMetrics {
private final AtomicInteger rrdpSerial = new AtomicInteger();
private final AtomicDouble snapshotDownloadMs = new AtomicDouble();
private final Counter successfulUpdates;
private final Counter failedUpdates;
private final Counter timeoutUpdates;
Expand All @@ -20,6 +22,10 @@ public RRDPFetcherMetrics(MeterRegistry meterRegistry) {
Gauge.builder("rsyncit.fetcher.rrdp.serial", rrdpSerial::get)
.description("Serial of the RRDP notification.xml at the given URL")
.register(meterRegistry);

Gauge.builder("rsyncit.fetcher.rrdp.snapshot.download.time", snapshotDownloadMs::get)
.description("Time to download snapshot")
.register(meterRegistry);
}

public void success(int serial) {
Expand All @@ -42,4 +48,7 @@ private static Counter buildCounter(String statusTag, MeterRegistry registry) {
.register(registry);
}

public void snapshotDownloadTime(long time) {
this.snapshotDownloadMs.set(time);
}
}
17 changes: 9 additions & 8 deletions src/main/java/net/ripe/rpki/rsyncit/rrdp/RrdpFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ public class RrdpFetcher {
private final Config config;
private final WebClient httpClient;
private final State state;
private final RRDPFetcherMetrics metrics;

public RrdpFetcher(Config config, WebClient httpClient, State state) {
public RrdpFetcher(Config config, WebClient httpClient, State state, RRDPFetcherMetrics metrics) {
this.config = config;
this.httpClient = httpClient;
this.state = state;
this.metrics = metrics;
log.info("RrdpFetcher for {}", config.rrdpUrl());
}

Expand All @@ -79,7 +81,7 @@ private Downloaded blockForHttpGetRequest(String uri, Duration timeout) {
/**
* Load snapshot and validate hash
*/
private Downloaded loadSnapshot(String snapshotUrl, String expectedSnapshotHash) throws SnapshotStructureException {
private Downloaded loadSnapshot(String snapshotUrl, String expectedSnapshotHash) {
log.info("loading RRDP snapshot from {}", snapshotUrl);

var snapshot = blockForHttpGetRequest(snapshotUrl, config.requestTimeout());
Expand Down Expand Up @@ -121,17 +123,16 @@ public FetchResult fetchObjectsEx() {
return new NoUpdates(notification.sessionId(), notification.serial());
}

long begin = System.currentTimeMillis();
var snapshot = loadSnapshot(notification.snapshotUrl(), notification.expectedSnapshotHash());
long end = System.currentTimeMillis();
log.info("Downloaded snapshot in {}ms", (end - begin));
var snapshot = Time.timed(() -> loadSnapshot(notification.snapshotUrl(), notification.expectedSnapshotHash()));
log.info("Downloaded snapshot in {}ms", snapshot.getTime());
metrics.snapshotDownloadTime(snapshot.getTime());

final Document snapshotXmlDoc = documentBuilder.parse(new ByteArrayInputStream(snapshot.content()));
final Document snapshotXmlDoc = documentBuilder.parse(new ByteArrayInputStream(snapshot.getResult().content()));
var doc = snapshotXmlDoc.getDocumentElement();

validateSnapshotStructure(notification.serial(), notification.snapshotUrl(), doc);

var processPublishElementResult = processPublishElements(doc, snapshot.lastModified());
var processPublishElementResult = processPublishElements(doc, snapshot.getResult().lastModified());

return new SuccessfulFetch(processPublishElementResult.objects, notification.sessionId(), notification.serial());
} catch (NotificationStructureException |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.ripe.rpki.rsyncit.rrdp;

public class SnapshotStructureException extends Exception {
public class SnapshotStructureException extends RuntimeException {
public SnapshotStructureException(String url, String msg) {
super("Structure of snapshot at %s did not match expected structure: %s".formatted(url, msg));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SyncService(WebClientBuilderFactory webClientFactory,

public void sync() {
var config = appConfig.getConfig();
var rrdpFetcher = new RrdpFetcher(config, webClientFactory.builder().build(), state);
var rrdpFetcher = new RrdpFetcher(config, webClientFactory.builder().build(), state, metrics);

var t = Time.timed(rrdpFetcher::fetchObjects);
final RrdpFetcher.FetchResult fetchResult = t.getResult();
Expand Down