Upgrade @elastic/elasticsearch to 9.3.1#253660
Conversation
29af322 to
5eb5276
Compare
…o upgrade-elasticsearch
|
Pinging @elastic/kibana-core (Team:Core) |
dhurley14
left a comment
There was a problem hiding this comment.
code review only LGTM @security-detection-engine
| if (term.field != null) { | ||
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| (filter.bool!.filter as ESFilter[]).push({ |
pmuellr
left a comment
There was a problem hiding this comment.
LGTM, thanks for removing the hallucinations! :-)
| // This can be used to apply any post-processing directly to the ingest pipeline processors. | ||
| export const applyPostProcessing = (processors: IngestProcessorContainer[]) => { | ||
| return processors.map((processor) => { | ||
| if (processor == null) return processor; |
There was a problem hiding this comment.
@Kerry350 It looks like the IngestProcessorContainer type has changed in @elastic/elasticsearch. Does this change (and the others in this PR) make sense to you or would it be better to use NonNullable<IngestProcessorContainer> type instead of IngestProcessorContainer as is so that we don't need to guard against null across the codebase?
There was a problem hiding this comment.
Using NonNullable<IngestProcessorContainer> makes sense to me rather than repeated guards 👌
There was a problem hiding this comment.
I noticed that adding NonNullable<IngestProcessorContainer> to this file would cause many changes downstream: the pipe in index.ts would lead to changing the output type of conversions.ts, which would complain for many of the process*Processor methods inside the flatMap loop.
Instead, this solution simplifies the changes: b52b911
WDYT?
There was a problem hiding this comment.
That looks okay, I'll approve 👌
smith
left a comment
There was a problem hiding this comment.
obs-presentation changes LGTM (re-review, code review only).
Previous comments addressed — alerts_overview.tsx and alerts_tab_badge.tsx changes correctly reverted.
Remaining obs changes are clean: change_point casts removed (now properly typed in 9.3.1), standard optional chaining and NonNullable patterns applied consistently across infra, SLO, UX, observability_agent_builder, and observability_ai_assistant_app.
ashokaditya
left a comment
There was a problem hiding this comment.
Changes to x-pack/solutions/security/plugins/security_solution/common/endpoint/utils/endpoint_metadata_filter.test.ts LGTM.
kdelemme
left a comment
There was a problem hiding this comment.
actionable-obs code change lgtm
|
@elasticmachine merge upstream |
miltonhultgren
left a comment
There was a problem hiding this comment.
SigEvents change (removing // @ts-expect-error) LGTM
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Async chunks
Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
cc @afharo |
…ps-config-rebase * commit 'f135f030951237c5e9b0251931441aee3121b31d': (163 commits) [CPS] Support data view requests and do not sanitize project_routing in data plugin/resolve indices (elastic#253654) [One Workflow] Execute workflow from historical (elastic#253396) [streams][background tasks] gracefully handle non existing stream (elastic#254683) [Lens API] Waffle/Mosaic get green as a default color (elastic#254304) [Security Solution] Remove prebuilt rules customization callout on Rule Management page (elastic#254386) [Workflows] support passing attachments to run_agent step (elastic#251291) [One Discover][Logs UX] Update OpenTelemetry Semantic Conventions (elastic#254367) [kbn-es] Add --docker flag to yarn es snapshot (elastic#254306) [Workplace AI] Remove Data Source Config (elastic#254521) [Entity Store v2] Add CRUD API (elastic#252052) [CI] Increase type checking machine (elastic#254676) [main] Sync bundled packages with Package Storage (elastic#254232) Skip flaky test elastic#254625 (elastic#254662) Upgrade `@elastic/elasticsearch` to 9.3.1 (elastic#253660) [One Workflow] Migrate http step to new connector (elastic#249004) [Entity Store] Store EUID Scripts (elastic#254515) [APM] Fix Otel missing fields undefined errors (elastic#254271) [Console] Add support for documentation links on Serverless (elastic#254489) Create edit ILM flow (elastic#253393) [Agent Builder] Mid term: minimal recommended model set elastic#12875 (elastic#254560) ...
## Summary
This PR upgrades `@elastic/elasticsearch` to **9.3.1**.
It triggered many Typescript issues due to the new utility type
`ExactlyOne<T>` used in the Elasticsearch library.
<details><summary>Expand for more details of the changes</summary>
<p>
---
## Root Cause
The new client version introduces an `ExactlyOne<T>` utility type for
key Elasticsearch types: `QueryDslQueryContainer`,
`IngestProcessorContainer`, `BulkOperationContainer`, and
`AggregationsAggregationContainer`. This type creates a union where
exactly one property is present and all others are `?: never`. When the
underlying interface had all-optional properties, the resulting union
also includes `undefined` as a member. This caused three categories of
breakage:
1. **`keyof` resolves to `never`** — Since `undefined` is part of the
union, `keyof QueryDslQueryContainer` becomes `never`, breaking any
`Pick<QueryDslQueryContainer, ...>` or `keyof QueryDslQueryContainer`
usage.
2. **Properties are "possibly undefined"** — Any variable typed as one
of these containers is now possibly `undefined`, so accessing `.bool`,
`.filter`, etc. triggers `TS18048`.
3. **Indexed access fails** — `QueryDslQueryContainer['match_phrase']`
fails because the key can't be resolved on a union that includes
`undefined`.
---
## Fix Patterns Applied (124 files, +618 / -403 lines)
### Pattern 1: `NonNullable<T>` for indexed access and `keyof`
Wherever code used `keyof QueryDslQueryContainer` or
`Pick<QueryDslQueryContainer, "bool" | "ids">`, it was changed to
operate on `NonNullable<QueryDslQueryContainer>` first to strip
`undefined` from the union:
```typescript
// Before
type AlertsQueryType = Pick<QueryDslQueryContainer, "bool" | "ids">;
// After
type AlertsQueryType = Partial<Pick<NonNullable<QueryDslQueryContainer>, "bool" | "ids">>;
```
This pattern was applied in **alerting types**, **rule registry**,
**alerts-table**, **kbn-grouping**, **task manager**,
**kbn-streamlang**, and **kbn-streams-schema**.
### Pattern 2: Optional chaining for "possibly undefined" access
In source files where a variable typed as `QueryDslQueryContainer` (or
similar) was accessed, optional chaining was added:
```typescript
// Before
kueryQuery.bool
// After
kueryQuery?.bool
```
Applied in **kbn-es-query**, **saved-objects migration**, **aiops**,
**ML**, **observability**, **security solution**, and many others.
### Pattern 3: `NonNullable<T>` in type casts
When constructing objects and casting them `as ESFilter` (which maps to
`QueryDslQueryContainer`), the cast was changed to `as
NonNullable<ESFilter>` to prevent TypeScript from treating the
freshly-constructed value as possibly `undefined`:
```typescript
// Before
const filter = { bool: { ... } } as ESFilter;
// After
const filter = { bool: { ... } } as NonNullable<ESFilter>;
```
Applied in **threshold bucket filters**, **alert conflict resolver**,
**session index**, etc.
### Pattern 4: `NonNullable<T>['prop']` for property type extraction
Direct indexed access on the container types was replaced with
`NonNullable` wrapping:
```typescript
// Before
estypes.QueryDslQueryContainer['match_phrase']
// After
NonNullable<estypes.QueryDslQueryContainer>['match_phrase']
```
Applied in **phrase_filter.ts**, **range_filter.ts**, and filter
building utilities.
### Pattern 5: Non-null assertions in test files
In test files where values from `toElasticsearchQuery()` or bulk
operations were known to be defined, non-null assertions (`!`) were
added rather than full null-checking:
```typescript
// Before
expect(result.bool.should).toEqual(...)
// After
expect(result!.bool!.should).toEqual(...)
```
Applied across **kbn-es-query tests**, **migration helpers tests**, **ML
inference pipeline tests**, **math processor tests**, etc.
### Pattern 6: Structural type replacements
Where `Extract<BulkOperationContainer, { delete: unknown }>` resolved to
`never`, the parameter type was replaced with a direct structural type:
```typescript
// Before
Array<Extract<BulkOperationContainer, { delete: unknown }>>
// After
Array<{ delete: BulkDeleteOperation }>
```
Applied in **security session_index.ts**.
---
</p>
</details>
## Summary of the changes by Area
| Area | Files Changed | Key Changes |
|------|--------------|-------------|
| **kbn-es-query** (core query/filter lib) | ~12 | `NonNullable` for
type access, optional chaining, test assertions |
| **Saved Objects migration** | 3 | Optional chaining on
`excludeOnUpgradeQuery.bool` |
| **Alerting / Rule Registry** | ~8 | `Partial<Pick<NonNullable<...>>>`
pattern for query types |
| **ML / Aiops** | ~25 | Default query types, optional chaining, cast
adjustments |
| **Security Solution** | ~10 | Threshold filters, network DSL, alert
bulk actions |
| **Observability (Infra, SLO, UX, APM)** | ~15 | Query construction,
alert summaries, web vitals queries |
| **Streams / kbn-streamlang** | ~6 | `keyof
NonNullable<IngestProcessorContainer>`, null checks |
| **Enterprise Search** | ~8 | ML inference pipeline processor types |
| **Task Manager** | 1 | `Pick<NonNullable<...>>` for pinned/bool query
types |
| **Other (Cases, Transform, Vega, etc.)** | ~20+ | Various combinations
of the above patterns |
### Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marta Bondyra <4283304+mbondyra@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
## Summary
This PR upgrades `@elastic/elasticsearch` to **9.3.1**.
It triggered many Typescript issues due to the new utility type
`ExactlyOne<T>` used in the Elasticsearch library.
<details><summary>Expand for more details of the changes</summary>
<p>
---
## Root Cause
The new client version introduces an `ExactlyOne<T>` utility type for
key Elasticsearch types: `QueryDslQueryContainer`,
`IngestProcessorContainer`, `BulkOperationContainer`, and
`AggregationsAggregationContainer`. This type creates a union where
exactly one property is present and all others are `?: never`. When the
underlying interface had all-optional properties, the resulting union
also includes `undefined` as a member. This caused three categories of
breakage:
1. **`keyof` resolves to `never`** — Since `undefined` is part of the
union, `keyof QueryDslQueryContainer` becomes `never`, breaking any
`Pick<QueryDslQueryContainer, ...>` or `keyof QueryDslQueryContainer`
usage.
2. **Properties are "possibly undefined"** — Any variable typed as one
of these containers is now possibly `undefined`, so accessing `.bool`,
`.filter`, etc. triggers `TS18048`.
3. **Indexed access fails** — `QueryDslQueryContainer['match_phrase']`
fails because the key can't be resolved on a union that includes
`undefined`.
---
## Fix Patterns Applied (124 files, +618 / -403 lines)
### Pattern 1: `NonNullable<T>` for indexed access and `keyof`
Wherever code used `keyof QueryDslQueryContainer` or
`Pick<QueryDslQueryContainer, "bool" | "ids">`, it was changed to
operate on `NonNullable<QueryDslQueryContainer>` first to strip
`undefined` from the union:
```typescript
// Before
type AlertsQueryType = Pick<QueryDslQueryContainer, "bool" | "ids">;
// After
type AlertsQueryType = Partial<Pick<NonNullable<QueryDslQueryContainer>, "bool" | "ids">>;
```
This pattern was applied in **alerting types**, **rule registry**,
**alerts-table**, **kbn-grouping**, **task manager**,
**kbn-streamlang**, and **kbn-streams-schema**.
### Pattern 2: Optional chaining for "possibly undefined" access
In source files where a variable typed as `QueryDslQueryContainer` (or
similar) was accessed, optional chaining was added:
```typescript
// Before
kueryQuery.bool
// After
kueryQuery?.bool
```
Applied in **kbn-es-query**, **saved-objects migration**, **aiops**,
**ML**, **observability**, **security solution**, and many others.
### Pattern 3: `NonNullable<T>` in type casts
When constructing objects and casting them `as ESFilter` (which maps to
`QueryDslQueryContainer`), the cast was changed to `as
NonNullable<ESFilter>` to prevent TypeScript from treating the
freshly-constructed value as possibly `undefined`:
```typescript
// Before
const filter = { bool: { ... } } as ESFilter;
// After
const filter = { bool: { ... } } as NonNullable<ESFilter>;
```
Applied in **threshold bucket filters**, **alert conflict resolver**,
**session index**, etc.
### Pattern 4: `NonNullable<T>['prop']` for property type extraction
Direct indexed access on the container types was replaced with
`NonNullable` wrapping:
```typescript
// Before
estypes.QueryDslQueryContainer['match_phrase']
// After
NonNullable<estypes.QueryDslQueryContainer>['match_phrase']
```
Applied in **phrase_filter.ts**, **range_filter.ts**, and filter
building utilities.
### Pattern 5: Non-null assertions in test files
In test files where values from `toElasticsearchQuery()` or bulk
operations were known to be defined, non-null assertions (`!`) were
added rather than full null-checking:
```typescript
// Before
expect(result.bool.should).toEqual(...)
// After
expect(result!.bool!.should).toEqual(...)
```
Applied across **kbn-es-query tests**, **migration helpers tests**, **ML
inference pipeline tests**, **math processor tests**, etc.
### Pattern 6: Structural type replacements
Where `Extract<BulkOperationContainer, { delete: unknown }>` resolved to
`never`, the parameter type was replaced with a direct structural type:
```typescript
// Before
Array<Extract<BulkOperationContainer, { delete: unknown }>>
// After
Array<{ delete: BulkDeleteOperation }>
```
Applied in **security session_index.ts**.
---
</p>
</details>
## Summary of the changes by Area
| Area | Files Changed | Key Changes |
|------|--------------|-------------|
| **kbn-es-query** (core query/filter lib) | ~12 | `NonNullable` for
type access, optional chaining, test assertions |
| **Saved Objects migration** | 3 | Optional chaining on
`excludeOnUpgradeQuery.bool` |
| **Alerting / Rule Registry** | ~8 | `Partial<Pick<NonNullable<...>>>`
pattern for query types |
| **ML / Aiops** | ~25 | Default query types, optional chaining, cast
adjustments |
| **Security Solution** | ~10 | Threshold filters, network DSL, alert
bulk actions |
| **Observability (Infra, SLO, UX, APM)** | ~15 | Query construction,
alert summaries, web vitals queries |
| **Streams / kbn-streamlang** | ~6 | `keyof
NonNullable<IngestProcessorContainer>`, null checks |
| **Enterprise Search** | ~8 | ML inference pipeline processor types |
| **Task Manager** | 1 | `Pick<NonNullable<...>>` for pinned/bool query
types |
| **Other (Cases, Transform, Vega, etc.)** | ~20+ | Various combinations
of the above patterns |
### Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marta Bondyra <4283304+mbondyra@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Summary
This PR upgrades
@elastic/elasticsearchto 9.3.1.It triggered many Typescript issues due to the new utility type
ExactlyOne<T>used in the Elasticsearch library.Expand for more details of the changes
Root Cause
The new client version introduces an
ExactlyOne<T>utility type for key Elasticsearch types:QueryDslQueryContainer,IngestProcessorContainer,BulkOperationContainer, andAggregationsAggregationContainer. This type creates a union where exactly one property is present and all others are?: never. When the underlying interface had all-optional properties, the resulting union also includesundefinedas a member. This caused three categories of breakage:keyofresolves tonever— Sinceundefinedis part of the union,keyof QueryDslQueryContainerbecomesnever, breaking anyPick<QueryDslQueryContainer, ...>orkeyof QueryDslQueryContainerusage.undefined, so accessing.bool,.filter, etc. triggersTS18048.QueryDslQueryContainer['match_phrase']fails because the key can't be resolved on a union that includesundefined.Fix Patterns Applied (124 files, +618 / -403 lines)
Pattern 1:
NonNullable<T>for indexed access andkeyofWherever code used
keyof QueryDslQueryContainerorPick<QueryDslQueryContainer, "bool" | "ids">, it was changed to operate onNonNullable<QueryDslQueryContainer>first to stripundefinedfrom the union:This pattern was applied in alerting types, rule registry, alerts-table, kbn-grouping, task manager, kbn-streamlang, and kbn-streams-schema.
Pattern 2: Optional chaining for "possibly undefined" access
In source files where a variable typed as
QueryDslQueryContainer(or similar) was accessed, optional chaining was added:Applied in kbn-es-query, saved-objects migration, aiops, ML, observability, security solution, and many others.
Pattern 3:
NonNullable<T>in type castsWhen constructing objects and casting them
as ESFilter(which maps toQueryDslQueryContainer), the cast was changed toas NonNullable<ESFilter>to prevent TypeScript from treating the freshly-constructed value as possiblyundefined:Applied in threshold bucket filters, alert conflict resolver, session index, etc.
Pattern 4:
NonNullable<T>['prop']for property type extractionDirect indexed access on the container types was replaced with
NonNullablewrapping:Applied in phrase_filter.ts, range_filter.ts, and filter building utilities.
Pattern 5: Non-null assertions in test files
In test files where values from
toElasticsearchQuery()or bulk operations were known to be defined, non-null assertions (!) were added rather than full null-checking:Applied across kbn-es-query tests, migration helpers tests, ML inference pipeline tests, math processor tests, etc.
Pattern 6: Structural type replacements
Where
Extract<BulkOperationContainer, { delete: unknown }>resolved tonever, the parameter type was replaced with a direct structural type:Applied in security session_index.ts.
Summary of the changes by Area
NonNullablefor type access, optional chaining, test assertionsexcludeOnUpgradeQuery.boolPartial<Pick<NonNullable<...>>>pattern for query typeskeyof NonNullable<IngestProcessorContainer>, null checksPick<NonNullable<...>>for pinned/bool query typesChecklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesbackport:*labels.