agent: add BenchmarkCreateSeries

Based on the one in tsdb/head_test.go.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2023-12-30 14:07:09 +00:00
parent e64d7d8928
commit bad3f23f23

View file

@ -84,7 +84,7 @@ func TestDB_InvalidSeries(t *testing.T) {
})
}
func createTestAgentDB(t *testing.T, reg prometheus.Registerer, opts *Options) *DB {
func createTestAgentDB(t testing.TB, reg prometheus.Registerer, opts *Options) *DB {
t.Helper()
dbDir := t.TempDir()
@ -878,3 +878,21 @@ func TestDBAllowOOOSamples(t *testing.T) {
require.Equal(t, float64(80), m.Metric[1].Counter.GetValue(), "agent wal mismatch of total appended histograms")
require.NoError(t, db.Close())
}
func BenchmarkCreateSeries(b *testing.B) {
s := createTestAgentDB(b, nil, DefaultOptions())
defer s.Close()
app := s.Appender(context.Background()).(*appender)
lbls := make([]labels.Labels, b.N)
for i, l := range labelsForTest("benchmark", b.N) {
lbls[i] = labels.New(l...)
}
b.ResetTimer()
for _, l := range lbls {
app.getOrCreate(l)
}
}