forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_sampler_bench_test.go
More file actions
126 lines (110 loc) · 5.66 KB
/
Copy pathcheck_sampler_bench_test.go
File metadata and controls
126 lines (110 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package aggregator
import (
"testing"
"go.uber.org/fx"
"github.com/DataDog/datadog-agent/comp/core"
"github.com/DataDog/datadog-agent/comp/core/hostname"
"github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl"
log "github.com/DataDog/datadog-agent/comp/core/log/def"
secretsmock "github.com/DataDog/datadog-agent/comp/core/secrets/mock"
taggerfxmock "github.com/DataDog/datadog-agent/comp/core/tagger/fx-mock"
"github.com/DataDog/datadog-agent/comp/core/telemetry/def"
filterlistimpl "github.com/DataDog/datadog-agent/comp/filterlist/impl"
eventplatform "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/def"
eventplatformimpl "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/impl"
haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock"
logscompressionmock "github.com/DataDog/datadog-agent/comp/serializer/logscompression/fx-mock"
forwarder "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/def"
forwarderimpl "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/impl"
forwardernoop "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/noop-impl"
"github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver"
compression "github.com/DataDog/datadog-agent/comp/serializer/metricscompression/def"
"github.com/DataDog/datadog-agent/pkg/aggregator/ckey"
"github.com/DataDog/datadog-agent/pkg/aggregator/internal/tags"
"github.com/DataDog/datadog-agent/pkg/config/utils"
checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id"
configmock "github.com/DataDog/datadog-agent/pkg/config/mock"
"github.com/DataDog/datadog-agent/pkg/metrics"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
"github.com/DataDog/datadog-agent/pkg/util/option"
)
type benchmarkDeps struct {
fx.In
Log log.Component
Hostname hostname.Component
Compressor compression.Component
Telemetry telemetry.Component
}
func benchmarkAddBucket(bucketValue int64, b *testing.B) {
// Because these benchs can run for a long time, the aggregator is trying to
// flush and because the serializer is not initialized it panics with a nil.
// For some reasons using InitAggregator[WithInterval] doesn't fix the problem,
// but this do.
mockConfig := configmock.New(b)
deps := fxutil.Test[benchmarkDeps](b, core.MockBundle(), hostnameimpl.MockModule())
taggerComponent := taggerfxmock.SetupFakeTagger(b)
resolver, _ := resolver.NewSingleDomainResolvers(map[string][]utils.APIKeys{"hello": {utils.NewAPIKeys("", "world")}})
forwarderOpts := forwarderimpl.NewOptionsWithResolvers(mockConfig, deps.Log, resolver)
options := DefaultAgentDemultiplexerOptions()
options.DontStartForwarders = true
secrets := secretsmock.New(b)
forwarderOpts.Secrets = secrets
sharedForwarder := forwarderimpl.NewDefaultForwarder(mockConfig, deps.Log, forwarderOpts)
orchestratorForwarder := option.New[forwarder.Forwarder](forwardernoop.NewComponent())
eventPlatformForwarder := option.NewPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(deps.Hostname, logscompressionmock.NewMockCompressor()))
haAgent := haagentmock.NewMockHaAgent()
filterList := filterlistimpl.NewFilterList(deps.Log, mockConfig, deps.Telemetry)
demux := InitAndStartAgentDemultiplexer(deps.Log, sharedForwarder, &orchestratorForwarder, options, eventPlatformForwarder, haAgent, deps.Compressor, taggerComponent, filterList, "hostname")
defer demux.Stop()
checkSampler := newCheckSampler(1, true, true, 1000, true, tags.NewStore(true, "bench"), checkid.ID("hello:world:1234"), taggerComponent)
matcher := filterlistimpl.NewNoopTagMatcher()
bucket := &metrics.HistogramBucket{
Name: "my.histogram",
Value: bucketValue,
LowerBound: 10.0,
UpperBound: 20.0,
Tags: []string{"foo", "bar"},
Timestamp: 12345.0,
}
for n := 0; n < b.N; n++ {
checkSampler.addBucket(bucket, matcher)
// reset bucket cache
checkSampler.lastBucketValue = make(map[ckey.ContextKey]int64)
}
}
func benchmarkAddBucketWideBounds(bucketValue int64, b *testing.B) {
taggerComponent := taggerfxmock.SetupFakeTagger(b)
checkSampler := newCheckSampler(1, true, true, 1000, true, tags.NewStore(true, "bench"), checkid.ID("hello:world:1234"), taggerComponent)
matcher := filterlistimpl.NewNoopTagMatcher()
bounds := []float64{0, .0005, .001, .003, .005, .007, .01, .015, .02, .025, .03, .04, .05, .06, .07, .08, .09, .1, .5, 1, 5, 10}
bucket := &metrics.HistogramBucket{
Name: "my.histogram",
Value: bucketValue,
Tags: []string{"foo", "bar"},
Timestamp: 12345.0,
}
for n := 0; n < b.N; n++ {
for i := range bounds {
if i == 0 {
continue
}
bucket.LowerBound = bounds[i-1]
bucket.UpperBound = bounds[i]
checkSampler.addBucket(bucket, matcher)
}
// reset bucket cache
checkSampler.lastBucketValue = make(map[ckey.ContextKey]int64)
}
}
func BenchmarkAddBucket1(b *testing.B) { benchmarkAddBucket(1, b) }
func BenchmarkAddBucket10(b *testing.B) { benchmarkAddBucket(10, b) }
func BenchmarkAddBucket100(b *testing.B) { benchmarkAddBucket(100, b) }
func BenchmarkAddBucket1000(b *testing.B) { benchmarkAddBucket(1000, b) }
func BenchmarkAddBucket10000(b *testing.B) { benchmarkAddBucket(10000, b) }
func BenchmarkAddBucket1000000(b *testing.B) { benchmarkAddBucket(1000000, b) }
func BenchmarkAddBucket10000000(b *testing.B) { benchmarkAddBucket(10000000, b) }
func BenchmarkAddBucketWide1e10(b *testing.B) { benchmarkAddBucketWideBounds(1e10, b) }