Skip to content

Commit

Permalink
[tatget-allocator] add discoverer benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Świątek committed Apr 13, 2023
1 parent b324939 commit 5dc5e72
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cmd/otel-allocator/target/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/prometheus/prometheus/discovery"
"github.com/prometheus/prometheus/model/relabel"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/open-telemetry/opentelemetry-operator/cmd/otel-allocator/config"
Expand Down Expand Up @@ -333,6 +334,49 @@ func TestDiscovery_ScrapeConfigHashing(t *testing.T) {
}
}

func BenchmarkApplyScrapeConfig(b *testing.B) {
numConfigs := 1000
scrapeConfig := promconfig.ScrapeConfig{
JobName: "serviceMonitor/testapp/testapp/0",
HonorTimestamps: true,
ScrapeInterval: model.Duration(30 * time.Second),
ScrapeTimeout: model.Duration(30 * time.Second),
MetricsPath: "/metrics",
Scheme: "http",
HTTPClientConfig: commonconfig.HTTPClientConfig{
FollowRedirects: true,
},
RelabelConfigs: []*relabel.Config{
{
SourceLabels: model.LabelNames{model.LabelName("job")},
Separator: ";",
Regex: relabel.MustNewRegexp("(.*)"),
TargetLabel: "__tmp_prometheus_job_name",
Replacement: "$$1",
Action: relabel.Replace,
},
},
}
cfg := &promconfig.Config{
ScrapeConfigs: make([]*promconfig.ScrapeConfig, numConfigs),
}

for i := 0; i < numConfigs; i++ {
cfg.ScrapeConfigs[i] = &scrapeConfig
}

scu := &mockScrapeConfigUpdater{}
ctx := context.Background()
d := discovery.NewManager(ctx, gokitlog.NewNopLogger())
manager := NewDiscoverer(ctrl.Log.WithName("test"), d, nil, scu)

b.ResetTimer()
for i := 0; i < b.N; i++ {
err := manager.ApplyConfig(allocatorWatcher.EventSourcePrometheusCR, cfg)
require.NoError(b, err)
}
}

var _ scrapeConfigsUpdater = &mockScrapeConfigUpdater{}

// mockScrapeConfigUpdater is a mock implementation of the scrapeConfigsUpdater.
Expand Down

0 comments on commit 5dc5e72

Please sign in to comment.