@@ -428,12 +428,12 @@ type HistogramOpts struct {
428
428
// a major version bump.
429
429
NativeHistogramBucketFactor float64
430
430
// All observations with an absolute value of less or equal
431
- // NativeHistogramZeroThreshold are accumulated into a “zero”
432
- // bucket. For best results, this should be close to a bucket
433
- // boundary. This is usually the case if picking a power of two. If
431
+ // NativeHistogramZeroThreshold are accumulated into a “zero” bucket.
432
+ // For best results, this should be close to a bucket boundary. This is
433
+ // usually the case if picking a power of two. If
434
434
// NativeHistogramZeroThreshold is left at zero,
435
- // DefNativeHistogramZeroThreshold is used as the threshold. To configure
436
- // a zero bucket with an actual threshold of zero (i.e. only
435
+ // DefNativeHistogramZeroThreshold is used as the threshold. To
436
+ // configure a zero bucket with an actual threshold of zero (i.e. only
437
437
// observations of precisely zero will go into the zero bucket), set
438
438
// NativeHistogramZeroThreshold to the NativeHistogramZeroThresholdZero
439
439
// constant (or any negative float value).
@@ -446,23 +446,28 @@ type HistogramOpts struct {
446
446
// Histogram are sufficiently wide-spread. In particular, this could be
447
447
// used as a DoS attack vector. Where the observed values depend on
448
448
// external inputs, it is highly recommended to set a
449
- // NativeHistogramMaxBucketNumber.) Once the set
449
+ // NativeHistogramMaxBucketNumber.) Once the set
450
450
// NativeHistogramMaxBucketNumber is exceeded, the following strategy is
451
- // enacted: First, if the last reset (or the creation) of the histogram
452
- // is at least NativeHistogramMinResetDuration ago, then the whole
453
- // histogram is reset to its initial state (including regular
454
- // buckets). If less time has passed, or if
455
- // NativeHistogramMinResetDuration is zero, no reset is
456
- // performed. Instead, the zero threshold is increased sufficiently to
457
- // reduce the number of buckets to or below
458
- // NativeHistogramMaxBucketNumber, but not to more than
459
- // NativeHistogramMaxZeroThreshold. Thus, if
460
- // NativeHistogramMaxZeroThreshold is already at or below the current
461
- // zero threshold, nothing happens at this step. After that, if the
462
- // number of buckets still exceeds NativeHistogramMaxBucketNumber, the
463
- // resolution of the histogram is reduced by doubling the width of the
464
- // sparse buckets (up to a growth factor between one bucket to the next
465
- // of 2^(2^4) = 65536, see above).
451
+ // enacted:
452
+ // - First, if the last reset (or the creation) of the histogram is at
453
+ // least NativeHistogramMinResetDuration ago, then the whole
454
+ // histogram is reset to its initial state (including regular
455
+ // buckets).
456
+ // - If less time has passed, or if NativeHistogramMinResetDuration is
457
+ // zero, no reset is performed. Instead, the zero threshold is
458
+ // increased sufficiently to reduce the number of buckets to or below
459
+ // NativeHistogramMaxBucketNumber, but not to more than
460
+ // NativeHistogramMaxZeroThreshold. Thus, if
461
+ // NativeHistogramMaxZeroThreshold is already at or below the current
462
+ // zero threshold, nothing happens at this step.
463
+ // - After that, if the number of buckets still exceeds
464
+ // NativeHistogramMaxBucketNumber, the resolution of the histogram is
465
+ // reduced by doubling the width of the sparse buckets (up to a
466
+ // growth factor between one bucket to the next of 2^(2^4) = 65536,
467
+ // see above).
468
+ // - Any increased zero threshold or reduced resolution is reset back
469
+ // to their original values once NativeHistogramMinResetDuration has
470
+ // passed (since the last reset or the creation of the histogram).
466
471
NativeHistogramMaxBucketNumber uint32
467
472
NativeHistogramMinResetDuration time.Duration
468
473
NativeHistogramMaxZeroThreshold float64
@@ -854,13 +859,16 @@ func (h *histogram) limitBuckets(counts *histogramCounts, value float64, bucket
854
859
h .doubleBucketWidth (hotCounts , coldCounts )
855
860
}
856
861
857
- // maybeReset resests the whole histogram if at least h.nativeHistogramMinResetDuration
862
+ // maybeReset resets the whole histogram if at least h.nativeHistogramMinResetDuration
858
863
// has been passed. It returns true if the histogram has been reset. The caller
859
864
// must have locked h.mtx.
860
- func (h * histogram ) maybeReset (hot , cold * histogramCounts , coldIdx uint64 , value float64 , bucket int ) bool {
865
+ func (h * histogram ) maybeReset (
866
+ hot , cold * histogramCounts , coldIdx uint64 , value float64 , bucket int ,
867
+ ) bool {
861
868
// We are using the possibly mocked h.now() rather than
862
869
// time.Since(h.lastResetTime) to enable testing.
863
- if h .nativeHistogramMinResetDuration == 0 || h .now ().Sub (h .lastResetTime ) < h .nativeHistogramMinResetDuration {
870
+ if h .nativeHistogramMinResetDuration == 0 ||
871
+ h .now ().Sub (h .lastResetTime ) < h .nativeHistogramMinResetDuration {
864
872
return false
865
873
}
866
874
// Completely reset coldCounts.
0 commit comments