aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/concurrent
diff options
context:
space:
mode:
authorArnstein Ressem <aressem@gmail.com>2021-06-04 21:57:32 +0200
committerGitHub <noreply@github.com>2021-06-04 21:57:32 +0200
commitcd1b747b4f65fa3a6ed6aace23235db7591638c5 (patch)
tree810ae8989030055b3cea65c684f69c0cfbd404b5 /vespajlib/src/main/java/com/yahoo/concurrent
parentb14315a6f51bc8e5bce22e0d9d11d0e730aaf96d (diff)
Revert "Emit a success factor from maintainers"
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/concurrent')
-rw-r--r--vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobMetrics.java24
-rw-r--r--vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java24
2 files changed, 18 insertions, 30 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobMetrics.java b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobMetrics.java
index 73a5dc77743..fcc5b8e57a2 100644
--- a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobMetrics.java
+++ b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobMetrics.java
@@ -2,18 +2,25 @@
package com.yahoo.concurrent.maintenance;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.BiConsumer;
/**
* Tracks and forwards maintenance job metrics.
*
* @author mpolden
*/
-public abstract class JobMetrics {
+public class JobMetrics {
+
+ private final BiConsumer<String, Long> metricConsumer;
private final ConcurrentHashMap<String, Long> incompleteRuns = new ConcurrentHashMap<>();
- /** Record starting of a run of a job */
- public void starting(String job) {
+ public JobMetrics(BiConsumer<String, Long> metricConsumer) {
+ this.metricConsumer = metricConsumer;
+ }
+
+ /** Record a run for given job */
+ public void recordRunOf(String job) {
incompleteRuns.merge(job, 1L, Long::sum);
}
@@ -22,17 +29,12 @@ public abstract class JobMetrics {
incompleteRuns.put(job, 0L);
}
- /**
- * Records completion of a run of a job.
- * This is guaranteed to always be called once whenever starting has been called.
- */
- public void completed(String job, double successFactor) {
+ /** Forward metrics for given job to metric consumer */
+ public void forward(String job) {
Long incompleteRuns = this.incompleteRuns.get(job);
if (incompleteRuns != null) {
- recordCompletion(job, incompleteRuns, successFactor);
+ metricConsumer.accept(job, incompleteRuns);
}
}
- protected abstract void recordCompletion(String job, Long incompleteRuns, double successFactor);
-
}
diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java
index 2a9e6dda6b6..734c46a2819 100644
--- a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java
+++ b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java
@@ -83,19 +83,8 @@ public abstract class Maintainer implements Runnable {
@Override
public final String toString() { return name(); }
- /**
- * Called once each time this maintenance job should run.
- *
- * @return the degree to which the run was successful - a number between 0 (no success), to 1 (complete success).
- * Note that this indicates whether something is wrong, so e.g if the call did nothing because it should do
- * nothing, 1.0 should be returned.
- */
- protected abstract double maintain();
-
- /** Convenience methods to convert attempts and failures into a success factor */
- protected final double asSuccessFactor(int attempts, int failures) {
- return attempts == 0 ? 1.0 : 1 - (double)failures / attempts;
- }
+ /** Called once each time this maintenance job should run. Returns whether the maintenance run was successful */
+ protected abstract boolean maintain();
/** Returns the interval at which this job is set to run */
protected Duration interval() { return interval; }
@@ -104,12 +93,9 @@ public abstract class Maintainer implements Runnable {
public final void lockAndMaintain(boolean force) {
if (!force && !jobControl.isActive(name())) return;
log.log(Level.FINE, () -> "Running " + this.getClass().getSimpleName());
- jobMetrics.starting(name());
- double successFactor = 0;
+ jobMetrics.recordRunOf(name());
try (var lock = jobControl.lockJob(name())) {
- successFactor = maintain();
- if (successFactor > 0.0)
- jobMetrics.recordCompletionOf(name());
+ if (maintain()) jobMetrics.recordCompletionOf(name());
} catch (UncheckedTimeoutException e) {
if (ignoreCollision) {
jobMetrics.recordCompletionOf(name());
@@ -119,7 +105,7 @@ public abstract class Maintainer implements Runnable {
} catch (Throwable e) {
log.log(Level.WARNING, this + " failed. Will retry in " + interval, e);
} finally {
- jobMetrics.completed(name(), successFactor);
+ jobMetrics.forward(name());
}
log.log(Level.FINE, () -> "Finished " + this.getClass().getSimpleName());
}