Add benchmark for each collector

Benchmarks will allow for easier identification of slow collectors.
Additionally, they increase test coverage of the collectors, with some
collectors now reaching 80-95% coverage with this change.

Collector benchmarks have been structed so that common functionality is
present in `collector/collector_test.go` as is done with non-test
functionality in `collector/collector.go`.
Test logic that is specific to individual collectors is present in the
collector test file (E.G. `collector/process_test.go` for the Process
collector).

Signed-off-by: Ben Reedy <breed808@breed808.com>
This commit is contained in:
Ben Reedy
2021-01-25 10:53:24 +10:00
parent 7adcac8f39
commit a2c4bf6a2d
39 changed files with 368 additions and 34 deletions

View File

@@ -2,22 +2,8 @@ package collector
import (
"testing"
"github.com/prometheus/client_golang/prometheus"
)
func BenchmarkCsCollect(b *testing.B) {
c, err := NewCSCollector()
if err != nil {
b.Error(err)
}
metrics := make(chan prometheus.Metric)
go func() {
for {
<-metrics
}
}()
for i := 0; i < b.N; i++ {
c.Collect(&ScrapeContext{}, metrics)
}
func BenchmarkCsCollector(b *testing.B) {
benchmarkCollector(b, "cs", NewCSCollector)
}