Raise Elastic::TimeoutError when Elasticsearch reports timed_out

🤖 AI-authored change.

What does this MR do and why?

Restores the Elasticsearch timed_out check on the Gitlab::Search::Client path, behind search_client_raise_on_timed_out (default off). With the flag off the behaviour is byte-identical to today.

Without it, execute_search yields the response straight to its caller, so a body carrying timed_out: true is consumed as if it were complete. ResponseMapper#total_count then reads hits.total.value unconditionally — a number assembled from only the shards that answered — and the user sees a plausible, smaller, complete-looking result set.

The other client already raises: SearchRequest#execute! in ee/config/initializers/elastic_client_setup.rb, since 2021. Scopes lost the check as they migrated, not by any decision to drop it — projects, milestones, merge_requests and notes still raise; work_items, issues, epics and every other execute_search caller do not.

References

  • Issue: #629244
  • Spec: specs/search-backend-degradation-behaviour/SPEC.md in gitlab-org/search-team/artifacts, merged at 433fcacf59f9 (acceptance criterion 6)

Screenshots or screen recordings

No user-visible change while the flag is off.

Why raise, test evidence, and what I did not verify

Why raise rather than a partial-results marker

It makes the two client paths agree rather than inventing a third behaviour, and the affected values surface as a single count where "incomplete" has no representation. SearchController and the REST search endpoints already render Elastic::TimeoutError as HTTP 408. GraphQL does not — the exception is absent from GraphqlController::ERROR_STATUS_MAP — so this ships behind a flag, and the spec gates full enablement on adding that mapping.

Red-then-green

The fix line reverted, then restored, both runs full:

RED   (yield search(es_query))                     11 examples, 9 failures
GREEN (yield search_with_timeout_check(es_query))  11 examples, 0 failures

The two examples green in both runs are the controls: flag-off, and a response with timed_out: false. Files: ee/spec/lib/gitlab/search/client_spec.rb (chokepoint, including count_only) and ee/spec/lib/gitlab/elastic/search_results_spec.rb (issues, work_items, epics, objects and formatted_count for each, plus issue_aggregations).

What I did not verify

The production 200-versus-408 split quoted in the issue above was not re-measured; this change rests on the source paths, which were re-read, not on that traffic sample. No live Elasticsearch was available on the machine used, so the scope-family examples stub the transport adapter rather than running as :elastic integration specs.


🤖 Automated change — mention me to get a response. Feedback welcome. Ask to speak to John directly anytime.

Merge request reports

Loading
Loading