From 0c55dc92a3bf889c67fac1ca855e6e33e1994904 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Mon, 9 Oct 2023 09:44:29 +0200 Subject: Update copyright --- hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java') 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 b3862b76296..c56dd219879 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 @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.hosted.api; import com.yahoo.yolean.Exceptions; -- cgit v1.2.3 From 4916aab2d6da2fee98bb576e33192c753197ff62 Mon Sep 17 00:00:00 2001 From: jonmv Date: Thu, 19 Oct 2023 16:07:32 +0200 Subject: Time suppliers, and warn when slow --- .../api/application/v4/model/DeploymentData.java | 50 ++++++++++++++++++++-- .../ai/vespa/hosted/api/MultiPartStreamer.java | 2 +- 2 files changed, 47 insertions(+), 5 deletions(-) (limited to 'hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java') 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 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 Supplier wrap(Supplier delegate, Duration timeout, String description) { + return new TimingSupplier<>(new Memoized<>(delegate), timeout, description); + } + + public static class TimingSupplier implements Supplier { + + private final Supplier delegate; + private final Duration timeout; + private final String description; + + public TimingSupplier(Supplier 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 */ -- cgit v1.2.3