Skip to content

Commit 31c0b97

Browse files
authored
Merge of #21214
2 parents 090dad4 + 7c4e035 commit 31c0b97

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

systemtest/estest/search.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,15 @@ func ExpectMinDocs(t testing.TB, es *espoll.Client, min int, index string, query
7777
return result
7878
}
7979

80-
func ExpectSourcemapError(t testing.TB, es *espoll.Client, index string, retry func(), query interface{}, updated bool) espoll.SearchResult {
80+
// ExpectSourcemapError retries sending events via retry until the sourcemap
81+
// fetcher is available (i.e. no "fetcher unavailable" errors appear in the
82+
// indexed documents), then returns the search result.
83+
//
84+
// minDocs is the minimum number of documents expected in the index after a
85+
// successful retry. Callers must pass the exact count they expect so that the
86+
// underlying poll does not return early when Elasticsearch has only indexed a
87+
// partial batch (see: TotalHitsCondition race).
88+
func ExpectSourcemapError(t testing.TB, es *espoll.Client, index string, minDocs int, retry func(), query interface{}, updated bool) espoll.SearchResult {
8189
t.Helper()
8290

8391
deadline := time.After(5 * time.Second)
@@ -99,7 +107,7 @@ func ExpectSourcemapError(t testing.TB, es *espoll.Client, index string, retry f
99107

100108
retry()
101109

102-
result := ExpectDocs(t, es, index, query)
110+
result := ExpectMinDocs(t, es, minDocs, index, query)
103111

104112
if isFetcherAvailable(t, result) {
105113
assertSourcemapUpdated(t, result, updated)

systemtest/rum_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ func TestRUMRoutingIntegration(t *testing.T) {
220220
require.NoError(t, err)
221221
defer resp.Body.Close()
222222
}
223-
result := estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "traces-apm.rum*", retry, nil, false)
223+
// 9 = 1 transaction + 8 spans produced by testdata/intake-v3/rum_events.ndjson.
224+
// Passing the exact count prevents ExpectSourcemapError from returning early
225+
// when Elasticsearch has only indexed a partial batch (TotalHitsCondition race).
226+
const wantDocs = 9
227+
result := estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "traces-apm.rum*", wantDocs, retry, nil, false)
224228
approvaltest.ApproveFields(
225229
t, t.Name(), result.Hits.Hits, "@timestamp", "timestamp.us",
226230
"source.port", "source.ip", "client.ip",

systemtest/sourcemap_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestRUMErrorSourcemapping(t *testing.T) {
4343
retry := func() {
4444
systemtest.SendRUMEventsPayload(t, serverURL, "../testdata/intake-v2/errors_rum.ndjson")
4545
}
46-
result := estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "logs-apm.error-*", retry, nil, true)
46+
result := estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "logs-apm.error-*", 1, retry, nil, true)
4747
approvaltest.ApproveFields(
4848
t, t.Name(), result.Hits.Hits,
4949
// RUM timestamps are set by the server based on the time the payload is received.
@@ -92,7 +92,7 @@ func TestRUMSpanSourcemapping(t *testing.T) {
9292
retry := func() {
9393
systemtest.SendRUMEventsPayload(t, srv.URL, "../testdata/intake-v2/transactions_spans_rum_2.ndjson")
9494
}
95-
result := estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "traces-apm*", retry, espoll.TermQuery{
95+
result := estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "traces-apm*", 1, retry, espoll.TermQuery{
9696
Field: "processor.event",
9797
Value: "span",
9898
}, true)
@@ -125,7 +125,7 @@ func TestNoMatchingSourcemap(t *testing.T) {
125125
retry := func() {
126126
systemtest.SendRUMEventsPayload(t, srv.URL, "../testdata/intake-v2/transactions_spans_rum_2.ndjson")
127127
}
128-
result := estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "traces-apm*", retry, espoll.TermQuery{
128+
result := estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "traces-apm*", 1, retry, espoll.TermQuery{
129129
Field: "processor.event",
130130
Value: "span",
131131
}, false)
@@ -158,11 +158,11 @@ func TestSourcemapCaching(t *testing.T) {
158158
retry := func() {
159159
systemtest.SendRUMEventsPayload(t, srv.URL, "../testdata/intake-v2/errors_rum.ndjson")
160160
}
161-
estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "logs-apm.error-*", retry, nil, true)
161+
estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "logs-apm.error-*", 1, retry, nil, true)
162162

163163
// Delete the source map and error, and try again.
164164
systemtest.CleanupElasticsearch(t)
165-
estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "logs-apm.error-*", retry, nil, true)
165+
estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "logs-apm.error-*", 1, retry, nil, true)
166166
}
167167

168168
func TestSourcemapFetcher(t *testing.T) {
@@ -217,7 +217,7 @@ func TestSourcemapFetcher(t *testing.T) {
217217
retry := func() {
218218
systemtest.SendRUMEventsPayload(t, srv.URL, "../testdata/intake-v2/errors_rum.ndjson")
219219
}
220-
estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "logs-apm.error-*", retry, nil, true)
220+
estest.ExpectSourcemapError(t, systemtest.Elasticsearch, "logs-apm.error-*", 1, retry, nil, true)
221221
})
222222
}
223223
}

0 commit comments

Comments
 (0)