@@ -32,6 +32,7 @@ import (
32
32
"github.com/stretchr/testify/require"
33
33
34
34
"go.elastic.co/apm/v2/apmtest"
35
+ "go.elastic.co/fastjson"
35
36
36
37
"github.com/elastic/beats/v7/libbeat/beat"
37
38
"github.com/elastic/beats/v7/libbeat/idxmgmt"
@@ -97,6 +98,8 @@ func TestPublisherStopShutdownInactive(t *testing.T) {
97
98
}
98
99
99
100
func BenchmarkPublisher (b * testing.B ) {
101
+ require .NoError (b , logp .DevelopmentSetup (logp .ToObserverOutput ()))
102
+
100
103
mux := http .NewServeMux ()
101
104
mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
102
105
w .Header ().Set ("X-Elastic-Product" , "Elasticsearch" )
@@ -109,14 +112,30 @@ func BenchmarkPublisher(b *testing.B) {
109
112
assert .NoError (b , err )
110
113
defer gzr .Close ()
111
114
115
+ var jsonw fastjson.Writer
116
+ jsonw .RawString (`{"items":[` )
117
+ first := true
118
+
112
119
scanner := bufio .NewScanner (gzr )
113
120
var n int64
114
- for scanner .Scan () { // index
115
- if scanner .Scan () { // actual event
116
- n ++
121
+
122
+ // stop if there's no more data or we bump into an empty line
123
+ // Prevent an issue with clients appending newlines to
124
+ // valid requests
125
+ for scanner .Scan () && len (scanner .Bytes ()) != 0 { // index
126
+ require .True (b , scanner .Scan ())
127
+
128
+ if first {
129
+ first = false
130
+ } else {
131
+ jsonw .RawByte (',' )
117
132
}
133
+ jsonw .RawString (`{"create":{"status":201}}` )
134
+ n ++
118
135
}
119
136
assert .NoError (b , scanner .Err ())
137
+ jsonw .RawString (`]}` )
138
+ w .Write (jsonw .Bytes ())
120
139
indexed .Add (n )
121
140
})
122
141
srv := httptest .NewServer (mux )
@@ -137,9 +156,12 @@ func BenchmarkPublisher(b *testing.B) {
137
156
namespace := config.Namespace {}
138
157
err = conf .Unpack (& namespace )
139
158
require .NoError (b , err )
159
+
140
160
pipeline , err := pipeline .New (
141
161
beat.Info {},
142
- pipeline.Monitors {},
162
+ pipeline.Monitors {
163
+ Logger : logp .NewLogger ("monitor" ),
164
+ },
143
165
namespace ,
144
166
outputGroup ,
145
167
pipeline.Settings {
0 commit comments