Skip to content

Commit 84697d4

Browse files
committed
count total optout files downloaded
1 parent c870e74 commit 84697d4

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

src/main/java/com/uid2/shared/store/salt/RotatingSaltProvider.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public long getVersion(JsonObject metadata) {
7777

7878
@Override
7979
public long loadContent(JsonObject metadata) throws Exception {
80+
final long saltLoadingStart = System.currentTimeMillis();
8081
final JsonArray salts = metadata.getJsonArray("salts");
8182
final String firstLevelSalt = metadata.getString("first_level");
8283
final SaltFileParser saltFileParser = new SaltFileParser(
@@ -99,6 +100,10 @@ public long loadContent(JsonObject metadata) throws Exception {
99100
.sorted(Comparator.comparing(SaltSnapshot::getEffective))
100101
.collect(Collectors.toList()));
101102

103+
final long saltLoadingEnd = System.currentTimeMillis();
104+
LOGGER.info("Salt loading completed in {} ms, {} snapshots loaded, {} total salts",
105+
saltLoadingEnd - saltLoadingStart, snapshots.size(), saltCount);
106+
102107
return saltCount;
103108
}
104109

@@ -129,9 +134,14 @@ private SaltSnapshot loadSnapshot(JsonObject spec, String firstLevelSalt, SaltFi
129134

130135
final String path = spec.getString("location");
131136
Integer size = spec.getInteger("size");
137+
138+
final long downloadStart = System.currentTimeMillis();
132139
SaltEntry[] entries = readInputStream(this.contentStreamProvider.download(path), saltFileParser, size);
133-
134-
LOGGER.info("Loaded {} salts", size);
140+
final long downloadEnd = System.currentTimeMillis();
141+
142+
// Only log filename portion to avoid potential presigned URL exposure
143+
String fileName = path.substring(path.lastIndexOf('/') + 1);
144+
LOGGER.info("Salt file {} downloaded in {} ms, loaded {} salts", fileName, downloadEnd - downloadStart, size);
135145
return new SaltSnapshot(effective, expires, entries, firstLevelSalt);
136146
}
137147

src/main/java/com/uid2/shared/vertx/CloudSyncVerticle.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class CloudSyncVerticle extends AbstractVerticle {
6565
private WorkerExecutor uploadExecutor = null;
6666

6767
private boolean isRefreshing = false;
68+
69+
private long optoutTotalStart = 0;
70+
private final Counter optoutFileCounter;
6871

6972
public CloudSyncVerticle(String name, ICloudStorage cloudStorage, ICloudStorage localStorage,
7073
ICloudSync cloudSync, JsonObject jsonConfig) {
@@ -148,6 +151,11 @@ public CloudSyncVerticle(String name, ICloudStorage cloudStorage, ICloudStorage
148151
.tag("store", name)
149152
.description("gauge for number of consecutive " + name + " store refresh failures")
150153
.register(Metrics.globalRegistry);
154+
155+
this.optoutFileCounter = "optout".equals(name) ? Counter
156+
.builder("uid2_optout_files_downloaded_total")
157+
.description("counter for total optout files downloaded from S3")
158+
.register(Metrics.globalRegistry) : null;
151159
}
152160

153161
@Override
@@ -223,6 +231,10 @@ private Future<Void> cloudRefresh() {
223231
return Future.succeededFuture();
224232
}
225233

234+
if ("optout".equals(this.name)) {
235+
this.optoutTotalStart = System.currentTimeMillis();
236+
}
237+
226238
Promise<Void> refreshPromise = Promise.promise();
227239
this.isRefreshing = true;
228240
vertx.<Void>executeBlocking(blockBromise -> {
@@ -233,6 +245,13 @@ private Future<Void> cloudRefresh() {
233245
return refreshPromise.future()
234246
.onComplete(v -> {
235247
this.isRefreshing = false;
248+
if ("optout".equals(this.name) && this.optoutTotalStart > 0) {
249+
long totalDuration = System.currentTimeMillis() - this.optoutTotalStart;
250+
LOGGER.info("Optout sync completed in {} ms", totalDuration);
251+
Gauge.builder("uid2_optout_total_sync_duration_ms", () -> (double) totalDuration)
252+
.description("Total time taken for complete optout sync operation")
253+
.register(Metrics.globalRegistry);
254+
}
236255
emitRefreshedEvent();
237256
});
238257
}
@@ -373,6 +392,9 @@ private Future<Void> cloudDownloadFile(String s3Path) {
373392
if (ar.succeeded()) {
374393
vertx.eventBus().publish(this.eventDownloaded, this.cloudSync.toLocalPath(s3Path));
375394
this.counterDownloaded.increment();
395+
if (optoutFileCounter != null) {
396+
optoutFileCounter.increment();
397+
}
376398
LOGGER.info("S3 download completed: {} in {} ms", cloudStorage.mask(s3Path), downloadTimeMs);
377399
} else {
378400
this.counterDownloadFailures.increment();
@@ -391,11 +413,22 @@ private Future<Void> cloudDownloadFile(String s3Path) {
391413
}
392414

393415
private void cloudDownloadBlocking(Promise<Void> promise, String s3Path) {
416+
final long fileDownloadStart = System.currentTimeMillis();
394417
try {
395418
String localPath = this.cloudSync.toLocalPath(s3Path);
396419
try (InputStream cloudInput = this.cloudStorage.download(s3Path)) {
397420
this.localStorage.upload(cloudInput, localPath);
398421
}
422+
423+
// Log individual file download timing for optout files (avoid logging full path for security)
424+
if ("optout".equals(this.name)) {
425+
final long fileDownloadEnd = System.currentTimeMillis();
426+
final long fileDownloadTime = fileDownloadEnd - fileDownloadStart;
427+
// Only log filename portion to avoid potential presigned URL exposure
428+
String fileName = s3Path.substring(s3Path.lastIndexOf('/') + 1);
429+
LOGGER.info("Optout file {} downloaded in {} ms", fileName, fileDownloadTime);
430+
}
431+
399432
promise.complete();
400433
} catch (Exception ex) {
401434
// Be careful as the s3Path may contain the pre-signed S3 token, so do not log the whole path

src/main/java/com/uid2/shared/vertx/RotatingStoreVerticle.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ public void start(Promise<Void> startPromise) throws Exception {
7878
}
7979

8080
private void startRefresh(Promise<Void> promise) {
81-
LOGGER.info("Starting " + this.storeName + " loading");
82-
LOGGER.info("Starting {} store initial S3 loading", this.storeName);
81+
// Only log detailed startup messages for salt stores (which are slow)
82+
if ("salt".equals(this.storeName)) {
83+
LOGGER.info("Starting {} store initial S3 loading", this.storeName);
84+
} else {
85+
// Fast stores: just log minimal startup message
86+
LOGGER.info("Starting {} loading", this.storeName);
87+
}
8388
final long startupRefreshStart = System.nanoTime();
8489

8590
vertx.executeBlocking(p -> {
@@ -96,9 +101,15 @@ private void startRefresh(Promise<Void> promise) {
96101
if (ar.succeeded()) {
97102
this.healthComponent.setHealthStatus(true);
98103
promise.complete();
99-
LOGGER.info("Successful " + this.storeName + " loading. Starting Background Refresh");
100-
LOGGER.info("Successful {} store initial S3 loading in {} ms. Starting Background Refresh",
101-
this.storeName, startupRefreshTimeMs);
104+
105+
// Only log detailed timing for salt stores (which are slow), keep other stores minimal
106+
if ("salt".equals(this.storeName)) {
107+
LOGGER.info("Successful {} store initial S3 loading in {} ms. Starting Background Refresh",
108+
this.storeName, startupRefreshTimeMs);
109+
} else {
110+
// Fast stores: just log completion without timing details to reduce noise
111+
LOGGER.info("Successful {} loading. Starting Background Refresh", this.storeName);
112+
}
102113

103114
// Record startup-specific S3 store loading metric
104115
Gauge.builder("uid2_operator_startup_store_refresh_duration_ms", () -> (double) startupRefreshTimeMs)

0 commit comments

Comments
 (0)