diff options
author | jonmv <venstad@gmail.com> | 2023-10-19 16:07:32 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2023-10-19 16:07:32 +0200 |
commit | 4916aab2d6da2fee98bb576e33192c753197ff62 (patch) | |
tree | 801306401d566b2ae7581077b0baf89c86f1b77a /controller-api | |
parent | 2eaba6e84b5e3f70aacd450a33ad5ff076c01ff7 (diff) |
Time suppliers, and warn when slow
Diffstat (limited to 'controller-api')
-rw-r--r-- | controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/application/v4/model/DeploymentData.java | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/application/v4/model/DeploymentData.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/application/v4/model/DeploymentData.java index b7d06aff47a..34682204163 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/application/v4/model/DeploymentData.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/application/v4/model/DeploymentData.java @@ -14,9 +14,12 @@ import com.yahoo.yolean.concurrent.Memoized; import java.io.InputStream; import java.security.cert.X509Certificate; +import java.time.Duration; import java.util.List; import java.util.Optional; import java.util.function.Supplier; +import java.util.logging.Level; +import java.util.logging.Logger; import static java.util.Objects.requireNonNull; @@ -28,6 +31,8 @@ import static java.util.Objects.requireNonNull; */ public class DeploymentData { + private static final Logger log = Logger.getLogger(DeploymentData.class.getName()); + private final ApplicationId instance; private final ZoneId zone; private final Supplier<InputStream> applicationPackage; @@ -56,14 +61,14 @@ public class DeploymentData { this.zone = requireNonNull(zone); this.applicationPackage = requireNonNull(applicationPackage); this.platform = requireNonNull(platform); - this.endpoints = new Memoized<>(requireNonNull(endpoints)); + this.endpoints = wrap(requireNonNull(endpoints), Duration.ofSeconds(30), "deployment endpoints"); this.dockerImageRepo = requireNonNull(dockerImageRepo); this.athenzDomain = athenzDomain; - this.quota = new Memoized<>(requireNonNull(quota)); + this.quota = wrap(requireNonNull(quota), Duration.ofSeconds(10), "quota"); this.tenantSecretStores = List.copyOf(requireNonNull(tenantSecretStores)); this.operatorCertificates = List.copyOf(requireNonNull(operatorCertificates)); - this.cloudAccount = new Memoized<>(requireNonNull(cloudAccount)); - this.dataPlaneTokens = new Memoized<>(dataPlaneTokens); + this.cloudAccount = wrap(requireNonNull(cloudAccount), Duration.ofSeconds(5), "cloud account"); + this.dataPlaneTokens = wrap(dataPlaneTokens, Duration.ofSeconds(5), "data plane tokens"); this.dryRun = dryRun; } @@ -119,4 +124,41 @@ public class DeploymentData { return dryRun; } + private static <T> Supplier<T> wrap(Supplier<T> delegate, Duration timeout, String description) { + return new TimingSupplier<>(new Memoized<>(delegate), timeout, description); + } + + public static class TimingSupplier<T> implements Supplier<T> { + + private final Supplier<T> delegate; + private final Duration timeout; + private final String description; + + public TimingSupplier(Supplier<T> delegate, Duration timeout, String description) { + this.delegate = delegate; + this.timeout = timeout; + this.description = description; + } + + @Override + public T get() { + long startNanos = System.nanoTime(); + Throwable thrown = null; + try { + return delegate.get(); + } + catch (Throwable t) { + thrown = t; + throw t; + } + finally { + long durationNanos = System.nanoTime() - startNanos; + Level level = durationNanos > timeout.toNanos() ? Level.WARNING : Level.FINE; + String thrownMessage = thrown == null ? "" : " with exception " + thrown; + log.log(level, () -> "Getting " + description + " took " + Duration.ofNanos(durationNanos) + thrownMessage); + } + } + + } + } |