Skip to content

Commit

Permalink
Merge pull request #3257 from nscuro/log-nvd-mirror-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
nscuro authored Dec 3, 2023
2 parents 47edbd7 + 63927a9 commit 2f16cae
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/org/dependencytrack/tasks/NistApiMirrorTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static io.github.jeremylong.openvulnerability.client.nvd.NvdCveClientBuilder.aNvdCveApi;
import static java.util.stream.Collectors.groupingBy;
Expand Down Expand Up @@ -143,6 +144,7 @@ public void inform(final Event e) {
final var executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), factory);

final long startTimeNs = System.nanoTime();
final var numMirrored = new AtomicInteger(0);
ZonedDateTime lastModified;
try (final NvdCveClient client = createApiClient(apiUrl, apiKey, lastModifiedEpochSeconds)) {
try {
Expand All @@ -166,6 +168,12 @@ public void inform(final Event e) {
synchronizeVulnerableSoftware(qm, persistentVuln, vsList);
} catch (Exception ex) {
LOGGER.error("An unexpected error occurred while processing %s".formatted(vuln.getVulnId()), ex);
} finally {
final int currentNumMirrored = numMirrored.incrementAndGet();
if (currentNumMirrored % 2000 == 0) { // Max page size of NVD API responses is 2000.
final int currentMirroredPercentage = (currentNumMirrored * 100) / client.getTotalAvailable();
LOGGER.info("Mirrored %d/%d CVEs (%d%%)".formatted(currentNumMirrored, client.getTotalAvailable(), currentMirroredPercentage));
}
}
});
}
Expand Down Expand Up @@ -199,7 +207,7 @@ public void inform(final Event e) {
LOGGER.error("An unexpected error occurred while mirroring the contents of the National Vulnerability Database", ex);
return;
} finally {
LOGGER.info("Mirroring completed in %s".formatted(Duration.ofNanos(System.nanoTime() - startTimeNs)));
LOGGER.info("Mirroring of %d CVEs completed in %s".formatted(numMirrored.get(), Duration.ofNanos(System.nanoTime() - startTimeNs)));
}

if (updateLastModified(lastModified)) {
Expand Down

0 comments on commit 2f16cae

Please sign in to comment.