mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
add benchmark for buildTimeSeries which does the filtering
Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
parent
9ef2bcd9db
commit
6c731e3603
|
@ -17,6 +17,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -611,6 +612,30 @@ func createTimeseries(numSamples, numSeries int, extraLabels ...labels.Label) ([
|
||||||
return samples, series
|
return samples, series
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createProtoTimeseriesWithOld(numSamples, baseTs int64, extraLabels ...labels.Label) []prompb.TimeSeries {
|
||||||
|
samples := make([]prompb.TimeSeries, numSamples)
|
||||||
|
// use a fixed rand source so tests are consistent
|
||||||
|
r := rand.New(rand.NewSource(99))
|
||||||
|
for j := int64(0); j < numSamples; j++ {
|
||||||
|
name := fmt.Sprintf("test_metric_%d", j)
|
||||||
|
|
||||||
|
samples[j] = prompb.TimeSeries{
|
||||||
|
Labels: []prompb.Label{{Name: "__name__", Value: name}},
|
||||||
|
Samples: []prompb.Sample{
|
||||||
|
{
|
||||||
|
Timestamp: baseTs + int64(j),
|
||||||
|
Value: float64(j),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// 10% of the time use a ts that is too old
|
||||||
|
if r.Intn(10) == 0 {
|
||||||
|
samples[j].Samples[0].Timestamp = baseTs - 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return samples
|
||||||
|
}
|
||||||
|
|
||||||
func createExemplars(numExemplars, numSeries int) ([]record.RefExemplar, []record.RefSeries) {
|
func createExemplars(numExemplars, numSeries int) ([]record.RefExemplar, []record.RefSeries) {
|
||||||
exemplars := make([]record.RefExemplar, 0, numExemplars)
|
exemplars := make([]record.RefExemplar, 0, numExemplars)
|
||||||
series := make([]record.RefSeries, 0, numSeries)
|
series := make([]record.RefSeries, 0, numSeries)
|
||||||
|
@ -1668,3 +1693,14 @@ func TestBuildTimeSeries(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkBuildTimeSeries(b *testing.B) {
|
||||||
|
// Send one sample per series, which is the typical remote_write case
|
||||||
|
const numSamples = 10000
|
||||||
|
filter := func(ts prompb.TimeSeries) bool { return filterTsLimit(99, ts) }
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
samples := createProtoTimeseriesWithOld(numSamples, 100, extraLabels...)
|
||||||
|
_, _, result, _, _, _ := buildTimeSeries(samples, filter)
|
||||||
|
require.NotNil(b, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue