Skip to content

Inject origin-only project_routing into transport.request CPS call sites#256430

Closed
rudolf wants to merge 1 commit intomainfrom
ralph/cps-transport-request
Closed

Inject origin-only project_routing into transport.request CPS call sites#256430
rudolf wants to merge 1 commit intomainfrom
ralph/cps-transport-request

Conversation

@rudolf
Copy link
Copy Markdown
Contributor

@rudolf rudolf commented Mar 6, 2026

Summary

Adds explicit project_routing: '_alias:_origin' to all transport.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_routing directly into the request body (or querystring for query-level APIs like search_mvt). The CPS request handler strips project_routing unconditionally when CPS is disabled, so this is safe in all environments. The default is set first in the object spread so any caller-provided project_routing takes precedence.

Call sites updated (6):

  • esql_search_strategy.tsPOST /_query (body)
  • esql_async_search_strategy.tsPOST /_query/async submit (body)
  • elasticsearch_retriever.tsPOST /{index}/_search (body)
  • esql_request.tsPOST /_query/async submit (body)
  • mvt_routes.tsPOST /{index}/_mvt/... (querystring)
  • observability_ai_assistant elasticsearch.ts — conditional for POST _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

@rudolf rudolf requested review from a team as code owners March 6, 2026 11:41
@rudolf rudolf requested a review from rylnd March 6, 2026 11:41
@botelastic botelastic Bot added ci:project-deploy-observability Create an Observability project Team:obs-ai Observability AI team labels Mar 6, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/obs-ai-team (Team:obs-ai)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@rudolf rudolf added backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes labels Mar 6, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Mar 6, 2026

💔 Build Failed

  • Buildkite Build
  • Commit: 9ab288a
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-256430-9ab288a9cce4

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #10 / BackfillClient constructor should register backfill task type
  • [job] [logs] Jest Tests #10 / BackfillClient constructor should register backfill task type
  • [job] [logs] Jest Tests #10 / conversational chain asking with chat history should re-write the question
  • [job] [logs] Jest Tests #10 / conversational chain asking with chat history should re-write the question
  • [job] [logs] Jest Tests #10 / conversational chain should be able to create a conversational chain
  • [job] [logs] Jest Tests #10 / conversational chain should be able to create a conversational chain
  • [job] [logs] Jest Tests #10 / conversational chain should be able to create a conversational chain with inner hit field
  • [job] [logs] Jest Tests #10 / conversational chain should be able to create a conversational chain with inner hit field
  • [job] [logs] Jest Tests #10 / conversational chain should be able to create a conversational chain with multiple context fields
  • [job] [logs] Jest Tests #10 / conversational chain should be able to create a conversational chain with multiple context fields
  • [job] [logs] Jest Tests #10 / conversational chain should be able to create a conversational chain with nested field
  • [job] [logs] Jest Tests #10 / conversational chain should be able to create a conversational chain with nested field
  • [job] [logs] Jest Tests #10 / conversational chain should cope with quotes in the query
  • [job] [logs] Jest Tests #10 / conversational chain should cope with quotes in the query
  • [job] [logs] Jest Tests #10 / conversational chain should error the conversation when over model limit
  • [job] [logs] Jest Tests #10 / conversational chain should error the conversation when over model limit
  • [job] [logs] Jest Tests #10 / conversational chain should omit the system messages in chat
  • [job] [logs] Jest Tests #10 / conversational chain should omit the system messages in chat
  • [job] [logs] Jest Tests #10 / conversational chain should work with an LLM based model
  • [job] [logs] Jest Tests #10 / conversational chain should work with an LLM based model
  • [job] [logs] Jest Tests #8 / ES|QL async search strategy search no sessionId sets transport options on POST requests
  • [job] [logs] Jest Tests #8 / ES|QL async search strategy search no sessionId sets transport options on POST requests
  • [job] [logs] Jest Tests #1 / performEsqlRequest polls until the query is completed
  • [job] [logs] Jest Tests #1 / performEsqlRequest polls until the query is completed
  • [job] [logs] Jest Tests #1 / performEsqlRequest returns results immediately when the async query completed
  • [job] [logs] Jest Tests #1 / performEsqlRequest returns results immediately when the async query completed

Metrics [docs]

✅ unchanged

History

@rudolf rudolf marked this pull request as draft March 6, 2026 13:32
@elasticmachine
Copy link
Copy Markdown
Contributor

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!
  • Click to trigger kibana-entity-store-performance-from-pr for this PR!
  • Click to trigger kibana-storybooks-from-pr for this PR!

@rudolf
Copy link
Copy Markdown
Contributor Author

rudolf commented Mar 6, 2026

Closing in favour of #256456

@rudolf rudolf closed this Mar 6, 2026
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>
@sophiec20 sophiec20 deleted the ralph/cps-transport-request branch March 11, 2026 18:22
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting ci:project-deploy-observability Create an Observability project release_note:skip Skip the PR/issue when compiling release notes Team:obs-ai Observability AI team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants