fix(test): resolve flaky TestSourcemapFetcher by avoiding fields parsing issue#21556
Conversation
|
This pull request does not have a backport label. Could you fix it @Copilot? 🙏
|
…ing issue Fixes #21486 Two bugs in systemtest/estest/search.go: 1. Fix swapped args in strings.Split(",", index) → strings.Split(index, ",") in ExpectMinDocs. The refresh was targeting the literal string "," instead of the actual index name, making the pre-search refresh a no-op. 2. Rewrite ExpectSourcemapError to use a custom search implementation (searchSourcemapDocs) that requests only _source instead of fields. The espoll.SearchHit.UnmarshalJSON calls json.Unmarshal(nil, &h.Fields) when the fields key is absent from ES response hits (which can happen when a data stream is freshly created after deletion), returning "unexpected end of JSON input". Since isFetcherAvailable and assertSourcemapUpdated only use RawSource, requesting fields is unnecessary for this code path.
When Yes, the upstream fix would be a simple nil/length guard in if len(h.RawFields) > 0 {
if err := json.Unmarshal(h.RawFields, &h.Fields); err != nil {
return fmt.Errorf("error unmarshaling fields: %w", err)
}
}That change belongs in |
|
Nice catch on the root cause — the One thing worth flagging on
Reproduced by shaping hits the way each path builds them and calling The upstream — flagged via Coretexa (adversarial PR verification) |
TestSourcemapFetcherandTestSourcemapCachingfailed intermittently with"error unmarshaling fields: unexpected end of JSON input". The root cause is inespoll.SearchHit.UnmarshalJSON: it callsjson.Unmarshal(nil, &h.Fields)when thefieldskey is absent from an ES hit, and Go'sjson.Unmarshal(nil, ...)returns that error. This occurs when a data stream is freshly created after deletion — ES may omitfieldsfrom hits under certain timing conditions.Motivation/summary
Two bugs fixed in
systemtest/estest/search.go:Swapped
strings.Splitargs inExpectMinDocs:strings.Split(",", index)→strings.Split(index, ","). The pre-search index refresh was targeting the literal string","instead of the actual index name, making the refresh a no-op.ExpectSourcemapErrorrewrite: replacedExpectMinDocs(which usesespoll.NewSearchRequestwith"fields": ["*"], triggeringSearchHit.UnmarshalJSON) with a newsearchSourcemapDocshelper that:_source— notfields— avoiding the nil unmarshal path entirelyespoll.SearchHit.UnmarshalJSONespoll.SearchResultwithRawSourcepopulated (sufficient forisFetcherAvailableandassertSourcemapUpdated, which only inspectRawSource)Checklist
Update CHANGELOG.asciidocDocumentation has been updatedRelated issues
Fixes #21486