diff options
-rw-r--r-- | controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/application/v4/model/DeploymentData.java | 50 | ||||
-rw-r--r-- | hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java | 2 |
2 files changed, 47 insertions, 5 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); + } + } + + } + } diff --git a/hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java b/hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java index c56dd219879..21c189e2549 100644 --- a/hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java @@ -23,7 +23,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; /** - * Used to create builders for multi part http body entities, which stream their data. + * Used to create builders for multipart HTTP body entities, which stream their data. * * @author jonmv */ |