From 10296150be63bf9010a94d97461e06be63206d2c Mon Sep 17 00:00:00 2001 From: Lenin Jaganathan Date: Wed, 18 Dec 2024 00:40:42 -0800 Subject: [PATCH] Defer to rescaling if values don't fit in the bucket - Rescaling is not frequent behaviour (for cumulative scale should normalize after initial few recording, for delta it could increase/decrease but would be mostly stable) hence we would re-try the record behaviour if the index won't fit in the value. --- .../registry/otlp/internal/CircularCountHolder.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/internal/CircularCountHolder.java b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/internal/CircularCountHolder.java index 0911a98c9a..c79e66d255 100644 --- a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/internal/CircularCountHolder.java +++ b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/internal/CircularCountHolder.java @@ -81,8 +81,12 @@ else if (index < startIndex) { startIndex = index; } - counts.addAndGet(getRelativeIndex(index), incrementBy); - return true; + final int relativeIndex = getRelativeIndex(index); + if (relativeIndex >= 0 && relativeIndex < length) { + counts.addAndGet(relativeIndex, incrementBy); + return true; + } + return false; } private int getRelativeIndex(int index) {