From efef9034c5897f26895b400ec20205340bcab474 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Mon, 14 Nov 2022 14:53:16 +0100 Subject: [PATCH 1/2] Rename histogram tests (from sparse to native) Signed-off-by: beorn7 --- prometheus/histogram_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prometheus/histogram_test.go b/prometheus/histogram_test.go index e745aa1..0e1317e 100644 --- a/prometheus/histogram_test.go +++ b/prometheus/histogram_test.go @@ -470,7 +470,7 @@ func TestHistogramExemplar(t *testing.T) { } } -func TestSparseHistogram(t *testing.T) { +func TestNativeHistogram(t *testing.T) { scenarios := []struct { name string observations []float64 // With simulated interval of 1m. @@ -686,7 +686,7 @@ func TestSparseHistogram(t *testing.T) { } } -func TestSparseHistogramConcurrency(t *testing.T) { +func TestNativeHistogramConcurrency(t *testing.T) { if testing.Short() { t.Skip("Skipping test in short mode.") } @@ -703,7 +703,7 @@ func TestSparseHistogramConcurrency(t *testing.T) { end.Add(concLevel) his := NewHistogram(HistogramOpts{ - Name: "test_sparse_histogram", + Name: "test_native_histogram", Help: "This help is sparse.", NativeHistogramBucketFactor: 1.05, NativeHistogramZeroThreshold: 0.0000001, From 043372ee04e711934c014f7a55fad257d008b300 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Mon, 14 Nov 2022 15:03:17 +0100 Subject: [PATCH 2/2] Initialize atomic variables in histogramCounts with atomic.Store... Signed-off-by: beorn7 --- prometheus/histogram.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/prometheus/histogram.go b/prometheus/histogram.go index 4c873a0..8798184 100644 --- a/prometheus/histogram.go +++ b/prometheus/histogram.go @@ -544,16 +544,12 @@ func newHistogram(desc *Desc, opts HistogramOpts, labelValues ...string) Histogr } // Finally we know the final length of h.upperBounds and can make buckets // for both counts as well as exemplars: - h.counts[0] = &histogramCounts{ - buckets: make([]uint64, len(h.upperBounds)), - nativeHistogramZeroThresholdBits: math.Float64bits(h.nativeHistogramZeroThreshold), - nativeHistogramSchema: h.nativeHistogramSchema, - } - h.counts[1] = &histogramCounts{ - buckets: make([]uint64, len(h.upperBounds)), - nativeHistogramZeroThresholdBits: math.Float64bits(h.nativeHistogramZeroThreshold), - nativeHistogramSchema: h.nativeHistogramSchema, - } + h.counts[0] = &histogramCounts{buckets: make([]uint64, len(h.upperBounds))} + atomic.StoreUint64(&h.counts[0].nativeHistogramZeroThresholdBits, math.Float64bits(h.nativeHistogramZeroThreshold)) + atomic.StoreInt32(&h.counts[0].nativeHistogramSchema, h.nativeHistogramSchema) + h.counts[1] = &histogramCounts{buckets: make([]uint64, len(h.upperBounds))} + atomic.StoreUint64(&h.counts[1].nativeHistogramZeroThresholdBits, math.Float64bits(h.nativeHistogramZeroThreshold)) + atomic.StoreInt32(&h.counts[1].nativeHistogramSchema, h.nativeHistogramSchema) h.exemplars = make([]atomic.Value, len(h.upperBounds)+1) h.init(h) // Init self-collection.