aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/container/logging/Coverage.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-core/src/main/java/com/yahoo/container/logging/Coverage.java')
-rw-r--r--container-core/src/main/java/com/yahoo/container/logging/Coverage.java64
1 files changed, 64 insertions, 0 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/logging/Coverage.java b/container-core/src/main/java/com/yahoo/container/logging/Coverage.java
new file mode 100644
index 00000000000..9d122b90641
--- /dev/null
+++ b/container-core/src/main/java/com/yahoo/container/logging/Coverage.java
@@ -0,0 +1,64 @@
+// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.logging;
+
+/**
+ * Carry information about how the query covered the document corpus.
+ */
+public class Coverage {
+ private final long docs;
+ private final long active;
+ private final long soonActive;
+ private final int degradedReason;
+ private final static int DEGRADED_BY_MATCH_PHASE = 1;
+ private final static int DEGRADED_BY_TIMEOUT = 2;
+ private final static int DEGRADED_BY_ADAPTIVE_TIMEOUT = 4;
+ public Coverage(long docs, long active, long soonActive, int degradedReason) {
+ this.docs = docs;
+ this.active = active;
+ this.soonActive = soonActive;
+ this.degradedReason = degradedReason;
+ }
+
+ public long getDocs() {
+ return docs;
+ }
+
+ public long getActive() {
+ return active;
+ }
+
+ public static int toDegradation(boolean degradeByMatchPhase, boolean degradedByTimeout, boolean degradedByAdaptiveTimeout) {
+ int v = 0;
+ if (degradeByMatchPhase) {
+ v |= DEGRADED_BY_MATCH_PHASE;
+ }
+ if (degradedByTimeout) {
+ v |= DEGRADED_BY_TIMEOUT;
+ }
+ if (degradedByAdaptiveTimeout) {
+ v |= DEGRADED_BY_ADAPTIVE_TIMEOUT;
+ }
+ return v;
+ }
+
+ public long getSoonActive() { return soonActive; }
+
+ public boolean isDegraded() { return (degradedReason != 0) || isDegradedByNonIdealState(); }
+ public boolean isDegradedByMatchPhase() { return (degradedReason & DEGRADED_BY_MATCH_PHASE) != 0; }
+ public boolean isDegradedByTimeout() { return (degradedReason & DEGRADED_BY_TIMEOUT) != 0; }
+ public boolean isDegradedByAdapativeTimeout() { return (degradedReason & DEGRADED_BY_ADAPTIVE_TIMEOUT) != 0; }
+ public boolean isDegradedByNonIdealState() { return (degradedReason == 0) && (getResultPercentage() != 100);}
+
+ /**
+ * An int between 0 (inclusive) and 100 (inclusive) representing how many
+ * percent coverage the result sets this Coverage instance contains information
+ * about had.
+ */
+ public int getResultPercentage() {
+ if (docs < active) {
+ return (int) Math.round(docs * 100.0d / active);
+ }
+ return 100;
+ }
+
+}