Skip to content

Commit a4c50d9

Browse files
authored
fix: Setup metrics for WritableKVStateStack (#12486)
Signed-off-by: Michael Heinrichs <[email protected]>
1 parent c31aa3b commit a4c50d9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/disk/OnDiskWritableKvStateMetrics.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public OnDiskWritableKvStateMetrics(
5050
if (currentValue < 0) {
5151
throw new IllegalArgumentException("currentValue must be non-negative");
5252
}
53-
if (maxCapacity <= 0) {
54-
throw new IllegalArgumentException("maxCapacity must be positive");
53+
if (maxCapacity < 0) {
54+
throw new IllegalArgumentException("maxCapacity must be non-negative");
5555
}
5656
this.count = new AtomicLong(currentValue);
5757

@@ -60,7 +60,7 @@ public OnDiskWritableKvStateMetrics(
6060
.withFormat("%,d");
6161
metrics.getOrCreate(totalUtilizationConfig);
6262

63-
final double relativeFactor = 100.0 / maxCapacity;
63+
final double relativeFactor = 100.0 / Math.max(1.0, maxCapacity); // in some tests, maxCapacity is 0
6464
final var relativeUtilizationConfig = new Config<>(
6565
"app", name + "PercentUsed", Double.class, () -> count.get() * relativeFactor)
6666
.withDescription(String.format("instantaneous %% used of %s system limit", label))

hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/stack/WritableKVStateStack.java

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static java.util.Objects.requireNonNull;
2020

2121
import com.hedera.node.app.spi.state.WritableKVState;
22+
import com.swirlds.metrics.api.Metrics;
2223
import edu.umd.cs.findbugs.annotations.NonNull;
2324
import edu.umd.cs.findbugs.annotations.Nullable;
2425
import java.util.Iterator;
@@ -122,4 +123,9 @@ public Set<K> readKeys() {
122123
public long size() {
123124
return getCurrent().size();
124125
}
126+
127+
@Override
128+
public void setupMetrics(@NonNull Metrics metrics, @NonNull String name, @NonNull String label, long maxCapacity) {
129+
getCurrent().setupMetrics(metrics, name, label, maxCapacity);
130+
}
125131
}

0 commit comments

Comments
 (0)