From 045ce20a5b2b88185d62af4578020e89cbee736c Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Fri, 22 Nov 2024 09:59:59 +0900 Subject: [PATCH] Polish gh-4955 (#5694) --- .../distribution/FixedBoundaryHistogram.java | 12 ++++++------ .../distribution/StepBucketHistogram.java | 2 +- .../FixedBoundaryHistogramTest.java | 18 +++++++++++------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/FixedBoundaryHistogram.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/FixedBoundaryHistogram.java index d740c3a21f..bbbc5a06a9 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/FixedBoundaryHistogram.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/FixedBoundaryHistogram.java @@ -29,8 +29,8 @@ class FixedBoundaryHistogram { /** * Creates a FixedBoundaryHistogram which tracks the count of values for each bucket - * bound). - * @param buckets - sorted bucket boundaries + * bound. + * @param buckets sorted bucket boundaries * @param isCumulativeBucketCounts - whether the count values should be cumulative * count of lower buckets and current bucket. */ @@ -46,10 +46,10 @@ class FixedBoundaryHistogram { /** * Returns the number of values that was recorded between previous bucket and the - * queried bucket (upper bound inclusive) + * queried bucket (upper bound inclusive). * @param bucket - the bucket to find values for * @return 0 if bucket is not a valid bucket otherwise number of values recorded - * between (index(bucket) - 1, bucket] + * between (previous bucket, bucket] */ private long countAtBucket(double bucket) { int index = Arrays.binarySearch(buckets, bucket); @@ -75,7 +75,7 @@ void record(long value) { * valueToRecord is greater than the highest bucket. */ // VisibleForTesting - int leastLessThanOrEqualTo(long valueToRecord) { + int leastLessThanOrEqualTo(double valueToRecord) { int low = 0; int high = buckets.length - 1; @@ -121,7 +121,7 @@ public CountAtBucket next() { * Returns the list of {@link CountAtBucket} for each of the buckets tracked by this * histogram. */ - CountAtBucket[] getCountsAtBucket() { + CountAtBucket[] getCountAtBuckets() { CountAtBucket[] countAtBuckets = new CountAtBucket[this.buckets.length]; long cumulativeCount = 0; diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/StepBucketHistogram.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/StepBucketHistogram.java index 5ce563def1..e81725339e 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/StepBucketHistogram.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/StepBucketHistogram.java @@ -64,7 +64,7 @@ protected Supplier valueSupplier() { return () -> { CountAtBucket[] countAtBuckets; synchronized (fixedBoundaryHistogram) { - countAtBuckets = fixedBoundaryHistogram.getCountsAtBucket(); + countAtBuckets = fixedBoundaryHistogram.getCountAtBuckets(); fixedBoundaryHistogram.reset(); } return countAtBuckets; diff --git a/micrometer-core/src/test/java/io/micrometer/core/instrument/distribution/FixedBoundaryHistogramTest.java b/micrometer-core/src/test/java/io/micrometer/core/instrument/distribution/FixedBoundaryHistogramTest.java index 80126ab7f4..ffc2530cd6 100644 --- a/micrometer-core/src/test/java/io/micrometer/core/instrument/distribution/FixedBoundaryHistogramTest.java +++ b/micrometer-core/src/test/java/io/micrometer/core/instrument/distribution/FixedBoundaryHistogramTest.java @@ -58,21 +58,25 @@ void testReset() { fixedBoundaryHistogram.record(1); fixedBoundaryHistogram.record(10); fixedBoundaryHistogram.record(100); - assertThat(fixedBoundaryHistogram.getCountsAtBucket()).allMatch(countAtBucket -> countAtBucket.count() == 1); + assertThat(fixedBoundaryHistogram.getCountAtBuckets()).isNotEmpty() + .allMatch(countAtBucket -> countAtBucket.count() == 1); fixedBoundaryHistogram.reset(); - assertThat(fixedBoundaryHistogram.getCountsAtBucket()).allMatch(countAtBucket -> countAtBucket.count() == 0); + assertThat(fixedBoundaryHistogram.getCountAtBuckets()).isNotEmpty() + .allMatch(countAtBucket -> countAtBucket.count() == 0); } @Test - void testCountsAtBucket() { + void testCountAtBuckets() { fixedBoundaryHistogram.record(1); fixedBoundaryHistogram.record(10); fixedBoundaryHistogram.record(100); - assertThat(fixedBoundaryHistogram.getCountsAtBucket()).allMatch(countAtBucket -> countAtBucket.count() == 1); + assertThat(fixedBoundaryHistogram.getCountAtBuckets()).isNotEmpty() + .allMatch(countAtBucket -> countAtBucket.count() == 1); fixedBoundaryHistogram.reset(); - assertThat(fixedBoundaryHistogram.getCountsAtBucket()).allMatch(countAtBucket -> countAtBucket.count() == 0); + assertThat(fixedBoundaryHistogram.getCountAtBuckets()).isNotEmpty() + .allMatch(countAtBucket -> countAtBucket.count() == 0); fixedBoundaryHistogram.record(0); - assertThat(fixedBoundaryHistogram.getCountsAtBucket()).containsExactly(new CountAtBucket(1.0, 1), + assertThat(fixedBoundaryHistogram.getCountAtBuckets()).containsExactly(new CountAtBucket(1.0, 1), new CountAtBucket(10.0, 0), new CountAtBucket(100.0, 0)); } @@ -82,7 +86,7 @@ void testCumulativeCounts() { fixedBoundaryHistogram.record(1); fixedBoundaryHistogram.record(10); fixedBoundaryHistogram.record(100); - assertThat(fixedBoundaryHistogram.getCountsAtBucket()).containsExactly(new CountAtBucket(1.0, 1), + assertThat(fixedBoundaryHistogram.getCountAtBuckets()).containsExactly(new CountAtBucket(1.0, 1), new CountAtBucket(10.0, 2), new CountAtBucket(100.0, 3)); }