🌐 AI搜索 & 代理 主页
Skip to content

Commit 59e0610

Browse files
committed
* 5.0.1
- Bugfix: PowersOfTenDividedBuckets did not work with >= 10 buckets due to overlap. Now skips overlapping region of generated series.
1 parent 8d79f11 commit 59e0610

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

History

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* 5.0.1
2+
- Bugfix: PowersOfTenDividedBuckets did not work with >= 10 buckets due to overlap. Now skips overlapping region of generated series.
13
* 5.0.0
24
- Added HTTP client metric that measures the response duration (time until response content reading is finished).
35
- Added "client" label containing the name of HTTP client to HTTP client metrics.

Prometheus.NetStandard/Histogram.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,17 @@ public static double[] PowersOfTenDividedBuckets(int startPower, int endPower, i
236236
// The math we do can make it incur some tiny avoidable error due to floating point gremlins.
237237
// We use decimal for the path to preserve as much accuracy as we can, before finally converting to double.
238238
// It will not fix 100% of the cases where we end up with 0.0000000000000000000000000000001 offset but it helps a lot.
239+
var candidate = (double)bucket;
239240

240-
buckets.Add((double)bucket);
241+
// Depending on the number of divisions, it may be that divisions from different powers overlap.
242+
// For example, a division into 20 would include:
243+
// 19th value in the 0th power: 9.5 (10/20*19=9.5)
244+
// 1st value in the 1st power: 5 (100/20*1 = 5)
245+
// To avoid this being a problem, we simply constrain all values to be increasing.
246+
if (buckets.Any() && buckets.Last() >= candidate)
247+
continue; // Skip this one, it is not greater.
248+
249+
buckets.Add(candidate);
241250
}
242251
}
243252

Resources/SolutionAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Runtime.CompilerServices;
33

44
// This is the real version number, used in NuGet packages and for display purposes.
5-
[assembly: AssemblyFileVersion("5.0.0")]
5+
[assembly: AssemblyFileVersion("5.0.1")]
66

77
// Only use major version here, with others kept at zero, for correct assembly binding logic.
88
[assembly: AssemblyVersion("5.0.0")]

Tests.NetFramework/HistogramTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ public void PowersOfTenDividedBuckets_CreatesExpectedBuckets()
5757
Assert.AreEqual(expected[i], actual[i]);
5858
}
5959

60+
[TestMethod]
61+
public void PowersOfTenDividedBuckets_WithOverlappingEdges_CreatesExpectedBuckets()
62+
{
63+
var expected = new[]
64+
{
65+
// 10 should be in both power=1 and power=2 series
66+
// But we expect it only to be emitted once.
67+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
68+
20, 30, 40, 50, 60, 70, 80, 90, 100
69+
};
70+
71+
var actual = Histogram.PowersOfTenDividedBuckets(0, 2, 10);
72+
73+
Assert.AreEqual(expected.Length, actual.Length);
74+
75+
for (var i = 0; i < expected.Length; i++)
76+
Assert.AreEqual(expected[i], actual[i]);
77+
}
78+
6079
[TestMethod]
6180
public void LinearBuckets_CreatesExpectedBuckets()
6281
{

0 commit comments

Comments
 (0)