|
7 | 7 | import com.uid2.shared.health.HealthManager; |
8 | 8 | import io.micrometer.core.instrument.Counter; |
9 | 9 | import io.micrometer.core.instrument.Gauge; |
| 10 | +import io.micrometer.core.instrument.Timer; |
10 | 11 | import io.micrometer.core.instrument.Metrics; |
11 | 12 | import io.vertx.core.*; |
12 | 13 | import io.vertx.core.eventbus.Message; |
@@ -44,6 +45,8 @@ public class CloudSyncVerticle extends AbstractVerticle { |
44 | 45 | private final Counter counterDownloadFailures; |
45 | 46 | private final Counter counterUploadFailures; |
46 | 47 | private final Gauge gaugeConsecutiveRefreshFailures; |
| 48 | + private final Timer downloadSuccessTimer; |
| 49 | + private final Timer downloadFailureTimer; |
47 | 50 |
|
48 | 51 | private final String name; |
49 | 52 | private final ICloudStorage cloudStorage; |
@@ -148,6 +151,10 @@ public CloudSyncVerticle(String name, ICloudStorage cloudStorage, ICloudStorage |
148 | 151 | .tag("store", name) |
149 | 152 | .description("gauge for number of consecutive " + name + " store refresh failures") |
150 | 153 | .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"); |
151 | 158 | } |
152 | 159 |
|
153 | 160 | @Override |
@@ -379,13 +386,24 @@ private Future<Void> cloudDownloadFile(String s3Path) { |
379 | 386 | } |
380 | 387 |
|
381 | 388 | private void cloudDownloadBlocking(Promise<Void> promise, String s3Path) { |
| 389 | + final long cloudDownloadStart = System.nanoTime(); |
382 | 390 | try { |
383 | 391 | String localPath = this.cloudSync.toLocalPath(s3Path); |
384 | 392 | try (InputStream cloudInput = this.cloudStorage.download(s3Path)) { |
| 393 | + final long cloudDownloadEnd = System.nanoTime(); |
| 394 | + final long cloudDownloadTimeMs = (cloudDownloadEnd - cloudDownloadStart) / 1_000_000; |
| 395 | + |
385 | 396 | 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); |
386 | 400 | } |
387 | 401 | promise.complete(); |
388 | 402 | } 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)); |
389 | 407 | // Be careful as the s3Path may contain the pre-signed S3 token, so do not log the whole path |
390 | 408 | LOGGER.error("download error: " + ex.getClass().getSimpleName()); |
391 | 409 | promise.fail(new Throwable(ex)); |
|
0 commit comments