runtime/metrics: use explicit histogram boundaries (API fix) #43443
Labels
FrozenDueToAge
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
okay-after-beta1
Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1
release-blocker
Milestone
This issue refers the current implementation that includes post go1.16beta1 fixes:
go version devel +95ce805d14 Thu Dec 31 02:24:55 2020 +0000 linux/amd64
Proposal: #37112
API Audit: #43407
I've found that using implicit
-inf
/+inf
boundaries with theruntime/metrics.Float64Histogram
API is a bit awkward (compared to using explicit boundaries). Implicit boundaries:-inf
) is usually nonsensical/wasted and ignored (negative allocation size, negative duration).I think it would be much better making the boundaries explicit:
math.Inf(-1)
is a valid floating point number). Eg, it is impossible to allocate -10 bytes - using [1, 9) or [0, 9) for the first bucket makes more sense.In practice, the total number of float64s could be the same since the first bucket can usually be dropped. Eg:
Assuming the following counts / buckets:
Current implicit encoding:
Proposed explicit encoding:
Even if there is a reason to keep the unused
-inf
bucket, making the boundaries explicit provides more future flexibility and makes it easier for callers.For comparison, the current API is documented as:
Note: this is actually incorrect, it should be [bucket[n-1], bucket[n]), for 0 < n < N-1.
The explicit boundary API would be:
Simplifying the documentation crudely indicates using explicit boundaries provides a cleaner API.
Cc @mknyszek
Sorry about the report late in the cycle, but I think this would be a much better API for the future and it's a simple fix now.
The text was updated successfully, but these errors were encountered: