Commit 6dfef31
[CPS] Fix ESQL index validation for linked projects (#259141)
## Summary
Fixes a bug in ESQL validation in Discover where indices that exist on a
CPS-linked project are incorrectly flagged as unknown.
Closes elastic/kibana-team#3107
## Root cause
The ESQL sources route (`/internal/esql/autocomplete/sources/{scope}`)
always resolved indices against the local project, ignoring the project
picker selection. Validation therefore failed for any index that only
exists on a linked project.
## Fix
```
Browser Server
────────────────────────────── ──────────────────────────────────────────
ESQL editor /internal/esql/autocomplete/sources/{scope}
├─ useObservable(getProjectRouting$()) └─ ?projectRouting=<value>
│ re-renders + re-validates on change └─ EsqlService.getAllIndices(scope, projectRouting)
├─ SET project_routing (from query) └─ resolveIndex({ project_routing })
│ takes precedence over picker └─ CPS transport: inject if enabled,
└─ effectiveRouting = SET ?? picker strip if not
sent as ?projectRouting query param
```
The editor computes an `effectiveProjectRouting` value (`SET
project_routing` statement takes precedence over the project picker
selection) and sends it as an explicit `?projectRouting` query param to
the sources route. The route forwards it directly to `resolveIndex()`.
The existing CPS transport layer handles stripping it in non-CPS
environments, so stateful and non-CPS Serverless deployments are
unaffected.
## Changes
### ESQL sources route — explicit `projectRouting` query param
([`get_all_sources.ts`](src/platform/plugins/shared/esql/server/routes/get_all_sources.ts))
Adds an optional `?projectRouting` query param and passes it to
`EsqlService.getAllIndices()`.
### `EsqlService.getAllIndices()` — direct injection
([`esql_service.ts`](src/platform/plugins/shared/esql/server/services/esql_service.ts))
Accepts an optional `projectRouting` and spreads `{ project_routing }`
directly into both `resolveIndex` calls. The CPS transport layer handles
the rest:
- **CPS-enabled**: an explicit value takes precedence over the handler's
default injection.
- **CPS-disabled**: the transport strips `project_routing`
unconditionally.
### ESQL editor — reactive picker + explicit param
([`esql_editor.tsx`](src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx),
[`sources.ts`](src/platform/packages/shared/kbn-esql-utils/src/utils/callbacks/sources.ts))
- `useObservable(cps?.cpsManager?.getProjectRouting$() ?? EMPTY)` reads
the picker value reactively; each change causes a re-render that busts
the `memoizedSources` cache (triggering a fresh source fetch with the
new routing).
- `SET project_routing` extracted from the query overrides the picker:
`effectiveProjectRouting = setProjectRouting ?? pickerProjectRouting`.
- `effectiveProjectRouting` is sent as `?projectRouting` to the sources
route.
- A ref-guarded `useEffect([pickerProjectRouting])` calls
`queryValidation` when the picker changes (skipping the initial mount to
avoid a double-validation).
The ESQL plugin's `ESQLLangEditor` wrapper passes `cps` (an optional
plugin dep) through `KibanaContextProvider` so consumers need no
changes.
## Also included: Core cleanup
The PR also reverts some earlier exploratory additions that are no
longer needed:
- `'http-header'` option removed from `AsScopedOptions` (only `'space'`
remains)
- `getClient(opts)` removed from `ElasticsearchRequestHandlerContext`
## Testing
- [ ] With CPS enabled, select a linked project in the project picker;
write `FROM <index-on-that-project>` in Discover's ESQL editor —
validation should pass (no "Unknown index" error).
- [ ] Changing the project picker selection triggers a fresh validation.
- [ ] Writing `SET project_routing=<other-project>; FROM
<index-on-other-project>` uses the SET value, not the picker's value,
for index resolution.
- [ ] Without CPS (stateful / non-CPS Serverless), behaviour is
unchanged.
Made with [Cursor](https://cursor.com)
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>1 parent 3402744 commit 6dfef31
15 files changed
Lines changed: 126 additions & 42 deletions
File tree
- src
- core/packages/elasticsearch
- client-server-internal/src
- server/src
- client
- platform
- packages
- private/kbn-esql-editor
- src
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
| 60 | + | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
Lines changed: 24 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
17 | 27 | | |
18 | 28 | | |
19 | 29 | | |
20 | 30 | | |
21 | 31 | | |
22 | 32 | | |
23 | 33 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
42 | 38 | | |
43 | 39 | | |
44 | 40 | | |
| |||
62 | 58 | | |
63 | 59 | | |
64 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
68 | | - | |
| 73 | + | |
69 | 74 | | |
70 | 75 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
Lines changed: 34 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
176 | 178 | | |
177 | 179 | | |
178 | 180 | | |
| 181 | + | |
179 | 182 | | |
180 | 183 | | |
181 | 184 | | |
| |||
195 | 198 | | |
196 | 199 | | |
197 | 200 | | |
| 201 | + | |
198 | 202 | | |
199 | 203 | | |
200 | 204 | | |
| |||
603 | 607 | | |
604 | 608 | | |
605 | 609 | | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
606 | 614 | | |
| 615 | + | |
| 616 | + | |
607 | 617 | | |
608 | 618 | | |
609 | 619 | | |
610 | | - | |
| 620 | + | |
611 | 621 | | |
612 | 622 | | |
613 | 623 | | |
614 | 624 | | |
615 | | - | |
| 625 | + | |
616 | 626 | | |
617 | 627 | | |
618 | 628 | | |
| |||
903 | 913 | | |
904 | 914 | | |
905 | 915 | | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
906 | 938 | | |
907 | 939 | | |
908 | 940 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| 117 | + | |
116 | 118 | | |
117 | 119 | | |
118 | 120 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
Lines changed: 15 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
37 | | - | |
| 40 | + | |
| 41 | + | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
41 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
| |||
96 | 103 | | |
97 | 104 | | |
98 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
99 | 109 | | |
100 | 110 | | |
101 | 111 | | |
102 | 112 | | |
103 | 113 | | |
104 | | - | |
| 114 | + | |
| 115 | + | |
105 | 116 | | |
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
109 | 120 | | |
110 | | - | |
| 121 | + | |
111 | 122 | | |
112 | 123 | | |
113 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
0 commit comments