Skip to content

Commit

Permalink
Fix corner case in Histogram metrics processing
Browse files Browse the repository at this point in the history
Signed-off-by: Krishna Kondaka <[email protected]>
  • Loading branch information
Krishna Kondaka committed Jan 22, 2024
1 parent b9e0ef0 commit bb47a4d
Showing 1 changed file with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1244,22 +1244,29 @@ public static List<Bucket> createBuckets(List<Long> bucketCountsList, List<Doubl
throw new IllegalArgumentException("OpenTelemetry protocol mandates that the number of elements in bucket_counts array must be by one greater than\n" +
" // the number of elements in explicit_bounds array.");
} else {
for (int i = 0; i < bucketCountsList.size(); i++) {
if (i == 0) {
double min = -Float.MAX_VALUE; // "-Infinity"
double max = explicitBoundsList.get(i);
Long bucketCount = bucketCountsList.get(i);
buckets.add(new DefaultBucket(min, max, bucketCount));
} else if (i == bucketCountsList.size() - 1) {
double min = explicitBoundsList.get(i - 1);
double max = Float.MAX_VALUE; // "Infinity"
Long bucketCount = bucketCountsList.get(i);
buckets.add(new DefaultBucket(min, max, bucketCount));
} else {
double min = explicitBoundsList.get(i - 1);
double max = explicitBoundsList.get(i);
Long bucketCount = bucketCountsList.get(i);
buckets.add(new DefaultBucket(min, max, bucketCount));
if (bucketCountsList.size() == 1) {
double min = -Float.MAX_VALUE; // "-Infinity"
double max = Float.MAX_VALUE; // "Infinity"
Long bucketCount = bucketCountsList.get(0);
buckets.add(new DefaultBucket(min, max, bucketCount));
} else {
for (int i = 0; i < bucketCountsList.size(); i++) {
if (i == 0) {
double min = -Float.MAX_VALUE; // "-Infinity"
double max = explicitBoundsList.get(i);
Long bucketCount = bucketCountsList.get(i);
buckets.add(new DefaultBucket(min, max, bucketCount));
} else if (i == bucketCountsList.size() - 1) {
double min = explicitBoundsList.get(i - 1);
double max = Float.MAX_VALUE; // "Infinity"
Long bucketCount = bucketCountsList.get(i);
buckets.add(new DefaultBucket(min, max, bucketCount));
} else {
double min = explicitBoundsList.get(i - 1);
double max = explicitBoundsList.get(i);
Long bucketCount = bucketCountsList.get(i);
buckets.add(new DefaultBucket(min, max, bucketCount));
}
}
}
}
Expand Down

0 comments on commit bb47a4d

Please sign in to comment.