diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2017-10-18 16:35:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-18 16:35:26 +0200 |
commit | c967345262c44804d01938608c6f84a8bdee34f5 (patch) | |
tree | 88f8596e33135bc816a99e8f37b063eaed142251 | |
parent | 391c2957ce6f450cfdd5684018dde4e222d6b848 (diff) | |
parent | 59f4f33244a22794441f3dcc0df19956b9f6c586 (diff) |
Merge pull request #3796 from vespa-engine/jvenstad/catch-metrics-fetching-errors-and-reduce-locking
Cleaner code
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java index 52ffa67c565..07464463bfc 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java @@ -9,6 +9,7 @@ import com.yahoo.vespa.hosted.controller.application.DeploymentMetrics; import java.io.UncheckedIOException; import java.time.Duration; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -35,22 +36,24 @@ public class DeploymentMetricsMaintainer extends Maintainer { DeploymentMetrics appMetrics = new DeploymentMetrics(metrics.queriesPerSecond(), metrics.writesPerSecond(), metrics.documentCount(), metrics.queryLatencyMillis(), metrics.writeLatencyMillis()); - // Avoid locking for a long time, due to slow YAMAS. try (Lock lock = controller().applications().lock(application.id())) { - // Deployment (or application) may have changed (or be gone) now: - controller().applications().get(application.id()).ifPresent(freshApplication -> { - Deployment freshDeployment = freshApplication.deployments().get(deployment.zone()); - if (freshDeployment != null) - controller().applications().store(freshApplication.with(freshDeployment.withMetrics(appMetrics)), lock); - }); + + // Deployment or application may have changed (or be gone) now: + application = controller().applications().get(application.id()).orElse(null); + if (application == null) + break; + + deployment = application.deployments().get(deployment.zone()); + if (deployment == null) + continue; + + controller().applications().store(application.with(deployment.withMetrics(appMetrics)), lock); } } catch (UncheckedIOException e) { - log.warning("Timed out talking to YAMAS; retrying in " + maintenanceInterval() + ":\n" + e); + log.log(Level.WARNING, "Timed out talking to YAMAS; retrying in " + maintenanceInterval(), e); } - } - } } |