Skip to content

Commit af5cba7

Browse files
authored
Merge pull request #534 from IABTechLab/wzh-UID2-6049-add-startup-timer-s3-new
add s3 related metrics
2 parents 3d203ac + 545a067 commit af5cba7

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ private SaltSnapshot loadSnapshot(JsonObject spec, String firstLevelSalt, SaltFi
129129

130130
final String path = spec.getString("location");
131131
Integer size = spec.getInteger("size");
132+
133+
final long downloadStart = System.currentTimeMillis();
132134
SaltEntry[] entries = readInputStream(this.contentStreamProvider.download(path), saltFileParser, size);
135+
final long downloadEnd = System.currentTimeMillis();
136+
LOGGER.info("Salt file downloaded in {} ms", downloadEnd - downloadStart);
133137

134138
LOGGER.info("Loaded {} salts", size);
135139
return new SaltSnapshot(effective, expires, entries, firstLevelSalt);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.uid2.shared.health.HealthManager;
88
import io.micrometer.core.instrument.Counter;
99
import io.micrometer.core.instrument.Gauge;
10+
import io.micrometer.core.instrument.Timer;
1011
import io.micrometer.core.instrument.Metrics;
1112
import io.vertx.core.*;
1213
import io.vertx.core.eventbus.Message;
@@ -44,6 +45,8 @@ public class CloudSyncVerticle extends AbstractVerticle {
4445
private final Counter counterDownloadFailures;
4546
private final Counter counterUploadFailures;
4647
private final Gauge gaugeConsecutiveRefreshFailures;
48+
private final Timer downloadSuccessTimer;
49+
private final Timer downloadFailureTimer;
4750

4851
private final String name;
4952
private final ICloudStorage cloudStorage;
@@ -148,6 +151,10 @@ 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.downloadSuccessTimer = Metrics.timer("uid2_cloud_download_duration", "store_name", name, "status", "success");
156+
157+
this.downloadFailureTimer = Metrics.timer("uid2_cloud_download_duration", "store_name", name, "status", "failure");
151158
}
152159

153160
@Override
@@ -379,13 +386,24 @@ private Future<Void> cloudDownloadFile(String s3Path) {
379386
}
380387

381388
private void cloudDownloadBlocking(Promise<Void> promise, String s3Path) {
389+
final long cloudDownloadStart = System.nanoTime();
382390
try {
383391
String localPath = this.cloudSync.toLocalPath(s3Path);
384392
try (InputStream cloudInput = this.cloudStorage.download(s3Path)) {
393+
final long cloudDownloadEnd = System.nanoTime();
394+
final long cloudDownloadTimeMs = (cloudDownloadEnd - cloudDownloadStart) / 1_000_000;
395+
385396
this.localStorage.upload(cloudInput, localPath);
397+
398+
downloadSuccessTimer.record(java.time.Duration.ofMillis(cloudDownloadTimeMs));
399+
LOGGER.info("S3 download completed: {} in {} ms", cloudStorage.mask(s3Path), cloudDownloadTimeMs);
386400
}
387401
promise.complete();
388402
} catch (Exception ex) {
403+
final long cloudDownloadEnd = System.nanoTime();
404+
final long cloudDownloadTimeMs = (cloudDownloadEnd - cloudDownloadStart) / 1_000_000;
405+
406+
downloadFailureTimer.record(java.time.Duration.ofMillis(cloudDownloadTimeMs));
389407
// Be careful as the s3Path may contain the pre-signed S3 token, so do not log the whole path
390408
LOGGER.error("download error: " + ex.getClass().getSimpleName());
391409
promise.fail(new Throwable(ex));

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.micrometer.core.instrument.Counter;
77
import io.micrometer.core.instrument.Gauge;
88
import io.micrometer.core.instrument.Metrics;
9+
import io.micrometer.core.instrument.Timer;
910
import io.vertx.core.AbstractVerticle;
1011
import io.vertx.core.Promise;
1112
import io.vertx.core.json.JsonObject;
@@ -19,6 +20,7 @@ public class RotatingStoreVerticle extends AbstractVerticle {
1920
private static final Logger LOGGER = LoggerFactory.getLogger(RotatingStoreVerticle.class);
2021
private final String storeName;
2122
private final HealthComponent healthComponent;
23+
private final Timer storeRefreshTimer;
2224
private final Counter counterStoreRefreshTimeMs;
2325
private final Counter counterStoreRefreshed;
2426
private final Gauge gaugeStoreVersion;
@@ -69,6 +71,7 @@ public RotatingStoreVerticle(String storeName, long refreshIntervalMs, IMetadata
6971
.register(Metrics.globalRegistry);
7072
this.versionedStore = versionedStore;
7173
this.refreshIntervalMs = refreshIntervalMs;
74+
this.storeRefreshTimer = Metrics.timer("uid2_store_refresh_duration", "store_name", storeName);
7275
}
7376

7477
@Override
@@ -79,6 +82,7 @@ public void start(Promise<Void> startPromise) throws Exception {
7982

8083
private void startRefresh(Promise<Void> promise) {
8184
LOGGER.info("Starting " + this.storeName + " loading");
85+
final long startupRefreshStart = System.nanoTime();
8286
vertx.executeBlocking(p -> {
8387
try {
8488
this.refresh();
@@ -87,9 +91,13 @@ private void startRefresh(Promise<Void> promise) {
8791
p.fail(e);
8892
}
8993
}, ar -> {
94+
final long startupRefreshEnd = System.nanoTime();
95+
final long startupRefreshTimeMs = (startupRefreshEnd - startupRefreshStart) / 1000000;
96+
9097
if (ar.succeeded()) {
9198
this.healthComponent.setHealthStatus(true);
9299
promise.complete();
100+
storeRefreshTimer.record(java.time.Duration.ofMillis(startupRefreshTimeMs));
93101
LOGGER.info("Successful " + this.storeName + " loading. Starting Background Refresh");
94102
this.startBackgroundRefresh();
95103
} else {
@@ -140,4 +148,4 @@ public synchronized void refresh() throws Exception {
140148
LOGGER.info("Successfully loaded " + this.storeName + " version " + version);
141149
}
142150
}
143-
}
151+
}

0 commit comments

Comments
 (0)