Inject origin-only project_routing into transport.request CPS call sites#256430
Closed
Inject origin-only project_routing into transport.request CPS call sites#256430
Conversation
Contributor
|
Pinging @elastic/obs-ai-team (Team:obs-ai) |
Contributor
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
Contributor
💔 Build Failed
Failed CI StepsTest Failures
Metrics [docs]
History |
Contributor
|
🤖 Jobs for this PR can be triggered through checkboxes. 🚧
ℹ️ To trigger the CI, please tick the checkbox below 👇
|
9 tasks
Contributor
Author
|
Closing in favour of #256456 |
rudolf
added a commit
that referenced
this pull request
Mar 11, 2026
## Summary Partially addresses elastic/kibana-team#2886 Further iteration on #256430 — converts `transport.request()` calls to typed elasticsearch-js client methods where feasible, improving type safety and ensuring CPS `project_routing` is automatically handled by the client library. **Converted (4 call sites):** - `elasticsearch_retriever.ts` → `esClient.search()` — Search Playground RAG retriever - `esql_request.ts` → `esql.asyncQuery()` / `asyncQueryGet()` / `asyncQueryDelete()` — Security detection engine ES|QL executor - `esql_search_strategy.ts` → `esql.query()` — Synchronous ES|QL search (Discover/Lens) - `esql_async_search_strategy.ts` → `esql.asyncQuery()` / `asyncQueryGet()` / `asyncQueryStop()` / `asyncQueryDelete()` — Async ES|QL search. Also fixed incorrect `SqlGetAsyncResponse` type → `EsqlAsyncQueryResponse` **Remaining as transport.request (2 call sites):** - `mvt_routes.ts` — Maps MVT tiles. Requires restructuring `getTile()` helper and tile request builders to pass `index`/`field`/`zoom`/`x`/`y` as separate params instead of a pre-built path string - `observability_ai_assistant elasticsearch.ts` — Dynamic caller by design, method/path determined at runtime by AI **Why typed methods are better for CPS:** Typed client methods already include `meta.acceptedParams` in their implementation, so the CPS handler automatically injects `project_routing` — no explicit injection or annotation needed. The two remaining `transport.request` callers use explicit `project_routing: '_alias:_origin'` injection (stripped automatically when CPS is disabled). ## Test plan - [x] `conversational_chain.test.ts` — 12/12 pass (updated mocks from `transport.request` to `search()`) - [x] `esql_request.test.ts` — all pass (updated mocks to typed esql methods) - [x] `esql.test.ts` — 5/5 pass (updated mocks) - [x] `esql_async_search_strategy.test.ts` — 15/15 pass (updated mocks + assertions) - [x] `async_utils.test.ts` — 16/16 pass - [x] `es_search_strategy.test.ts` + `ese_search_strategy.test.ts` — 35/35 pass (regression check) - [x] `cps_request_handler.test.ts` — 38/38 pass (CPS handler sanity check) - [x] `mvt_routes.test.ts` — pass - [x] Typecheck passes for all affected plugins 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Lukas Olson <lukas@elastic.co> Co-authored-by: Marco Vettorello <marco.vettorello@elastic.co>
sorenlouv
pushed a commit
that referenced
this pull request
Mar 17, 2026
## Summary Partially addresses elastic/kibana-team#2886 Further iteration on #256430 — converts `transport.request()` calls to typed elasticsearch-js client methods where feasible, improving type safety and ensuring CPS `project_routing` is automatically handled by the client library. **Converted (4 call sites):** - `elasticsearch_retriever.ts` → `esClient.search()` — Search Playground RAG retriever - `esql_request.ts` → `esql.asyncQuery()` / `asyncQueryGet()` / `asyncQueryDelete()` — Security detection engine ES|QL executor - `esql_search_strategy.ts` → `esql.query()` — Synchronous ES|QL search (Discover/Lens) - `esql_async_search_strategy.ts` → `esql.asyncQuery()` / `asyncQueryGet()` / `asyncQueryStop()` / `asyncQueryDelete()` — Async ES|QL search. Also fixed incorrect `SqlGetAsyncResponse` type → `EsqlAsyncQueryResponse` **Remaining as transport.request (2 call sites):** - `mvt_routes.ts` — Maps MVT tiles. Requires restructuring `getTile()` helper and tile request builders to pass `index`/`field`/`zoom`/`x`/`y` as separate params instead of a pre-built path string - `observability_ai_assistant elasticsearch.ts` — Dynamic caller by design, method/path determined at runtime by AI **Why typed methods are better for CPS:** Typed client methods already include `meta.acceptedParams` in their implementation, so the CPS handler automatically injects `project_routing` — no explicit injection or annotation needed. The two remaining `transport.request` callers use explicit `project_routing: '_alias:_origin'` injection (stripped automatically when CPS is disabled). ## Test plan - [x] `conversational_chain.test.ts` — 12/12 pass (updated mocks from `transport.request` to `search()`) - [x] `esql_request.test.ts` — all pass (updated mocks to typed esql methods) - [x] `esql.test.ts` — 5/5 pass (updated mocks) - [x] `esql_async_search_strategy.test.ts` — 15/15 pass (updated mocks + assertions) - [x] `async_utils.test.ts` — 16/16 pass - [x] `es_search_strategy.test.ts` + `ese_search_strategy.test.ts` — 35/35 pass (regression check) - [x] `cps_request_handler.test.ts` — 38/38 pass (CPS handler sanity check) - [x] `mvt_routes.test.ts` — pass - [x] Typecheck passes for all affected plugins 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Lukas Olson <lukas@elastic.co> Co-authored-by: Marco Vettorello <marco.vettorello@elastic.co>
jeramysoucy
pushed a commit
to jeramysoucy/kibana
that referenced
this pull request
Mar 26, 2026
## Summary Partially addresses elastic/kibana-team#2886 Further iteration on elastic#256430 — converts `transport.request()` calls to typed elasticsearch-js client methods where feasible, improving type safety and ensuring CPS `project_routing` is automatically handled by the client library. **Converted (4 call sites):** - `elasticsearch_retriever.ts` → `esClient.search()` — Search Playground RAG retriever - `esql_request.ts` → `esql.asyncQuery()` / `asyncQueryGet()` / `asyncQueryDelete()` — Security detection engine ES|QL executor - `esql_search_strategy.ts` → `esql.query()` — Synchronous ES|QL search (Discover/Lens) - `esql_async_search_strategy.ts` → `esql.asyncQuery()` / `asyncQueryGet()` / `asyncQueryStop()` / `asyncQueryDelete()` — Async ES|QL search. Also fixed incorrect `SqlGetAsyncResponse` type → `EsqlAsyncQueryResponse` **Remaining as transport.request (2 call sites):** - `mvt_routes.ts` — Maps MVT tiles. Requires restructuring `getTile()` helper and tile request builders to pass `index`/`field`/`zoom`/`x`/`y` as separate params instead of a pre-built path string - `observability_ai_assistant elasticsearch.ts` — Dynamic caller by design, method/path determined at runtime by AI **Why typed methods are better for CPS:** Typed client methods already include `meta.acceptedParams` in their implementation, so the CPS handler automatically injects `project_routing` — no explicit injection or annotation needed. The two remaining `transport.request` callers use explicit `project_routing: '_alias:_origin'` injection (stripped automatically when CPS is disabled). ## Test plan - [x] `conversational_chain.test.ts` — 12/12 pass (updated mocks from `transport.request` to `search()`) - [x] `esql_request.test.ts` — all pass (updated mocks to typed esql methods) - [x] `esql.test.ts` — 5/5 pass (updated mocks) - [x] `esql_async_search_strategy.test.ts` — 15/15 pass (updated mocks + assertions) - [x] `async_utils.test.ts` — 16/16 pass - [x] `es_search_strategy.test.ts` + `ese_search_strategy.test.ts` — 35/35 pass (regression check) - [x] `cps_request_handler.test.ts` — 38/38 pass (CPS handler sanity check) - [x] `mvt_routes.test.ts` — pass - [x] Typecheck passes for all affected plugins 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Lukas Olson <lukas@elastic.co> Co-authored-by: Marco Vettorello <marco.vettorello@elastic.co>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds explicit
project_routing: '_alias:_origin'to alltransport.request()call sites that target ES APIs supporting CPS project routing. This ensures a safe default for these transport calls so that enabling CPS doesn't suddenly expand the scope in unintended ways.Approach: We inject
project_routingdirectly into the request body (or querystring for query-level APIs likesearch_mvt). The CPS request handler stripsproject_routingunconditionally when CPS is disabled, so this is safe in all environments. The default is set first in the object spread so any caller-providedproject_routingtakes precedence.Call sites updated (6):
esql_search_strategy.ts—POST /_query(body)esql_async_search_strategy.ts—POST /_query/asyncsubmit (body)elasticsearch_retriever.ts—POST /{index}/_search(body)esql_request.ts—POST /_query/asyncsubmit (body)mvt_routes.ts—POST /{index}/_mvt/...(querystring)observability_ai_assistant elasticsearch.ts— conditional forPOST _search(body)Not updated:
workflows_execution_engine— fully dynamic paths, cannot determine API support at compile time🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com