mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
record_test.go: avoid captures, simply return test refs
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
parent
1508149184
commit
a7ccc8e091
|
@ -469,26 +469,17 @@ func TestRecord_MetadataDecodeUnknownExtraFields(t *testing.T) {
|
||||||
require.Equal(t, expectedMetadata, decMetadata)
|
require.Equal(t, expectedMetadata, decMetadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type refsCreateFn func(labelCount, histograms, buckets int) ([]RefSeries, []RefSample, []RefHistogramSample)
|
||||||
|
|
||||||
type recordsMaker struct {
|
type recordsMaker struct {
|
||||||
name string
|
name string
|
||||||
init func(int, int, int)
|
make refsCreateFn
|
||||||
}
|
}
|
||||||
|
|
||||||
// BenchmarkWAL_HistogramLog measures efficiency of encoding classic
|
// BenchmarkWAL_HistogramLog measures efficiency of encoding classic
|
||||||
// histograms and native historgrams with custom buckets (NHCB).
|
// histograms and native historgrams with custom buckets (NHCB).
|
||||||
func BenchmarkWAL_HistogramEncoding(b *testing.B) {
|
func BenchmarkWAL_HistogramEncoding(b *testing.B) {
|
||||||
// Cache for the refs.
|
initClassicRefs := func(labelCount, histograms, buckets int) (series []RefSeries, floatSamples []RefSample, histSamples []RefHistogramSample) {
|
||||||
var series []RefSeries
|
|
||||||
var samples []RefSample
|
|
||||||
var nhcbs []RefHistogramSample
|
|
||||||
|
|
||||||
resetCache := func() {
|
|
||||||
series = nil
|
|
||||||
samples = nil
|
|
||||||
nhcbs = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
initClassicRefs := func(labelCount, histograms, buckets int) {
|
|
||||||
ref := chunks.HeadSeriesRef(0)
|
ref := chunks.HeadSeriesRef(0)
|
||||||
lbls := map[string]string{}
|
lbls := map[string]string{}
|
||||||
for i := range labelCount {
|
for i := range labelCount {
|
||||||
|
@ -500,7 +491,7 @@ func BenchmarkWAL_HistogramEncoding(b *testing.B) {
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
Labels: labels.FromMap(lbls),
|
Labels: labels.FromMap(lbls),
|
||||||
})
|
})
|
||||||
samples = append(samples, RefSample{
|
floatSamples = append(floatSamples, RefSample{
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
T: 100,
|
T: 100,
|
||||||
V: float64(i),
|
V: float64(i),
|
||||||
|
@ -512,7 +503,7 @@ func BenchmarkWAL_HistogramEncoding(b *testing.B) {
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
Labels: labels.FromMap(lbls),
|
Labels: labels.FromMap(lbls),
|
||||||
})
|
})
|
||||||
samples = append(samples, RefSample{
|
floatSamples = append(floatSamples, RefSample{
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
T: 100,
|
T: 100,
|
||||||
V: float64(i),
|
V: float64(i),
|
||||||
|
@ -529,7 +520,7 @@ func BenchmarkWAL_HistogramEncoding(b *testing.B) {
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
Labels: labels.FromMap(lbls),
|
Labels: labels.FromMap(lbls),
|
||||||
})
|
})
|
||||||
samples = append(samples, RefSample{
|
floatSamples = append(floatSamples, RefSample{
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
T: 100,
|
T: 100,
|
||||||
V: float64(i + j),
|
V: float64(i + j),
|
||||||
|
@ -538,9 +529,10 @@ func BenchmarkWAL_HistogramEncoding(b *testing.B) {
|
||||||
}
|
}
|
||||||
delete(lbls, model.BucketLabel)
|
delete(lbls, model.BucketLabel)
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
initNHCBRefs := func(labelCount, histograms, buckets int) {
|
initNHCBRefs := func(labelCount, histograms, buckets int) (series []RefSeries, floatSamples []RefSample, histSamples []RefHistogramSample) {
|
||||||
ref := chunks.HeadSeriesRef(0)
|
ref := chunks.HeadSeriesRef(0)
|
||||||
lbls := map[string]string{}
|
lbls := map[string]string{}
|
||||||
for i := range labelCount {
|
for i := range labelCount {
|
||||||
|
@ -563,31 +555,31 @@ func BenchmarkWAL_HistogramEncoding(b *testing.B) {
|
||||||
for j := range buckets {
|
for j := range buckets {
|
||||||
h.PositiveBuckets[j] = int64(i + j)
|
h.PositiveBuckets[j] = int64(i + j)
|
||||||
}
|
}
|
||||||
nhcbs = append(nhcbs, RefHistogramSample{
|
histSamples = append(histSamples, RefHistogramSample{
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
T: 100,
|
T: 100,
|
||||||
H: h,
|
H: h,
|
||||||
})
|
})
|
||||||
ref++
|
ref++
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, maker := range []recordsMaker{
|
for _, maker := range []recordsMaker{
|
||||||
{
|
{
|
||||||
name: "classic",
|
name: "classic",
|
||||||
init: initClassicRefs,
|
make: initClassicRefs,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nhcb",
|
name: "nhcb",
|
||||||
init: initNHCBRefs,
|
make: initNHCBRefs,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
for _, labelCount := range []int{0, 10, 50} {
|
for _, labelCount := range []int{0, 10, 50} {
|
||||||
for _, histograms := range []int{10, 100, 1000} {
|
for _, histograms := range []int{10, 100, 1000} {
|
||||||
for _, buckets := range []int{0, 1, 10, 100} {
|
for _, buckets := range []int{0, 1, 10, 100} {
|
||||||
b.Run(fmt.Sprintf("type=%s/labels=%d/histograms=%d/buckets=%d", maker.name, labelCount, histograms, buckets), func(b *testing.B) {
|
b.Run(fmt.Sprintf("type=%s/labels=%d/histograms=%d/buckets=%d", maker.name, labelCount, histograms, buckets), func(b *testing.B) {
|
||||||
resetCache()
|
series, samples, nhcbs := maker.make(labelCount, histograms, buckets)
|
||||||
maker.init(labelCount, histograms, buckets)
|
|
||||||
enc := Encoder{}
|
enc := Encoder{}
|
||||||
for range b.N {
|
for range b.N {
|
||||||
var buf []byte
|
var buf []byte
|
||||||
|
|
Loading…
Reference in a new issue