[ES 9.0] Remove body workaround (@elastic/fleet) (#217218)

## Summary

Follow up to https://github.com/elastic/kibana/pull/213375: The latest
version of the ES client fixed the issue
https://github.com/elastic/elasticsearch-js/issues/2584.

We should be able to remove all usages of `// @ts-expect-error
elasticsearch@9.0.0
https://github.com/elastic/elasticsearch-js/issues/2584`.


### Checklist

- [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
This commit is contained in:
Alejandro Fernández Haro 2025-04-08 11:34:26 +02:00 committed by GitHub
parent e7dbe43e28
commit 3ab31d3fc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 101 additions and 129 deletions

View file

@ -216,11 +216,10 @@ const installPreBuiltComponentTemplates = async (
const esClientParams = {
name: templateName,
body: content,
...content,
};
return retryTransientEsErrors(
// @ts-expect-error elasticsearch@9.0.0 https://github.com/elastic/elasticsearch-js/issues/2584
() => esClient.cluster.putComponentTemplate(esClientParams, { ignore: [404] }),
{ logger }
);
@ -695,10 +694,9 @@ async function installTemplate({
// TODO: Check return values for errors
const esClientParams = {
name: template.templateName,
body: template.indexTemplate,
...template.indexTemplate,
};
await retryTransientEsErrors(
// @ts-expect-error elasticsearch@9.0.0 https://github.com/elastic/elasticsearch-js/issues/2584
() => esClient.indices.putIndexTemplate(esClientParams, { ignore: [404] }),
{ logger }
);

View file

@ -2037,12 +2037,10 @@ describe('EPM template', () => {
expect(putMappingsCalls).toHaveLength(1);
expect(putMappingsCalls[0][0]).toEqual({
index: 'test-constant.keyword-default',
body: {
properties: {
some_keyword_field: {
type: 'constant_keyword',
value: 'some_value',
},
properties: {
some_keyword_field: {
type: 'constant_keyword',
value: 'some_value',
},
},
write_index_only: true,
@ -2087,7 +2085,6 @@ describe('EPM template', () => {
expect(putMappingsCalls).toHaveLength(1);
expect(putMappingsCalls[0][0]).toEqual({
index: 'test-constant.keyword-default',
body: {},
write_index_only: true,
});
});

View file

@ -1107,8 +1107,7 @@ const updateExistingDataStream = async ({
() =>
esClient.indices.putMapping({
index: dataStreamName,
// @ts-expect-error elasticsearch@9.0.0 https://github.com/elastic/elasticsearch-js/issues/2584
body: mappings,
...mappings,
write_index_only: true,
}),
{ logger }

View file

@ -383,21 +383,19 @@ _meta:
expect(esClient.indices.putIndexTemplate.mock.calls).toEqual([
[
{
body: {
_meta: meta,
composed_of: [
'logs-endpoint.metadata_current-template@package',
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
index_patterns: ['.metrics-endpoint.metadata_united_default'],
priority: 250,
template: { mappings: undefined, settings: undefined },
ignore_missing_component_templates: [
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
},
_meta: meta,
composed_of: [
'logs-endpoint.metadata_current-template@package',
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
index_patterns: ['.metrics-endpoint.metadata_united_default'],
priority: 250,
template: { mappings: undefined, settings: undefined },
ignore_missing_component_templates: [
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
name: 'logs-endpoint.metadata_current-template',
},
{ ignore: [404] },
@ -673,21 +671,19 @@ _meta:
expect(esClient.indices.putIndexTemplate.mock.calls).toEqual([
[
{
body: {
_meta: meta,
composed_of: [
'logs-endpoint.metadata_current-template@package',
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
index_patterns: ['.metrics-endpoint.metadata_united_default'],
priority: 250,
template: { mappings: undefined, settings: undefined },
ignore_missing_component_templates: [
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
},
_meta: meta,
composed_of: [
'logs-endpoint.metadata_current-template@package',
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
index_patterns: ['.metrics-endpoint.metadata_united_default'],
priority: 250,
template: { mappings: undefined, settings: undefined },
ignore_missing_component_templates: [
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
name: 'logs-endpoint.metadata_current-template',
},
{ ignore: [404] },
@ -940,21 +936,19 @@ _meta:
expect(esClient.indices.putIndexTemplate.mock.calls).toEqual([
[
{
body: {
_meta: meta,
composed_of: [
'logs-endpoint.metadata_current-template@package',
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
index_patterns: ['.metrics-endpoint.metadata_united_default'],
priority: 250,
template: { mappings: undefined, settings: undefined },
ignore_missing_component_templates: [
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
},
_meta: meta,
composed_of: [
'logs-endpoint.metadata_current-template@package',
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
index_patterns: ['.metrics-endpoint.metadata_united_default'],
priority: 250,
template: { mappings: undefined, settings: undefined },
ignore_missing_component_templates: [
'endpoint@custom',
'logs-endpoint.metadata_current-template@custom',
],
name: 'logs-endpoint.metadata_current-template',
},
{ ignore: [404] },

View file

@ -269,12 +269,10 @@ describe('experimental_datastream_features', () => {
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
template: expect.objectContaining({
settings: expect.objectContaining({
index: expect.objectContaining({
mapping: expect.objectContaining({ source: { mode: 'synthetic' } }),
}),
template: expect.objectContaining({
settings: expect.objectContaining({
index: expect.objectContaining({
mapping: expect.objectContaining({ source: { mode: 'synthetic' } }),
}),
}),
}),
@ -296,15 +294,13 @@ describe('experimental_datastream_features', () => {
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
template: expect.objectContaining({
mappings: expect.objectContaining({
properties: expect.objectContaining({
sequence: {
type: 'long',
index: false,
},
}),
template: expect.objectContaining({
mappings: expect.objectContaining({
properties: expect.objectContaining({
sequence: {
type: 'long',
index: false,
},
}),
}),
}),
@ -326,15 +322,13 @@ describe('experimental_datastream_features', () => {
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
template: expect.objectContaining({
mappings: expect.objectContaining({
properties: expect.objectContaining({
name: {
type: 'keyword',
index: false,
},
}),
template: expect.objectContaining({
mappings: expect.objectContaining({
properties: expect.objectContaining({
name: {
type: 'keyword',
index: false,
},
}),
}),
}),
@ -356,14 +350,12 @@ describe('experimental_datastream_features', () => {
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
template: expect.objectContaining({
mappings: expect.objectContaining({
properties: expect.objectContaining({
'@timestamp': {
type: 'date',
},
}),
template: expect.objectContaining({
mappings: expect.objectContaining({
properties: expect.objectContaining({
'@timestamp': {
type: 'date',
},
}),
}),
}),
@ -385,11 +377,9 @@ describe('experimental_datastream_features', () => {
expect(esClient.indices.getIndexTemplate).toHaveBeenCalled();
expect(esClient.indices.putIndexTemplate).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
template: expect.objectContaining({
settings: expect.objectContaining({
index: { mode: 'time_series' },
}),
template: expect.objectContaining({
settings: expect.objectContaining({
index: { mode: 'time_series' },
}),
}),
_meta: { has_experimental_data_stream_indexing_features: true },
@ -485,12 +475,10 @@ describe('experimental_datastream_features', () => {
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
template: expect.objectContaining({
settings: expect.objectContaining({
index: expect.objectContaining({
mapping: expect.objectContaining({ source: { mode: 'synthetic' } }),
}),
template: expect.objectContaining({
settings: expect.objectContaining({
index: expect.objectContaining({
mapping: expect.objectContaining({ source: { mode: 'synthetic' } }),
}),
}),
}),
@ -512,15 +500,13 @@ describe('experimental_datastream_features', () => {
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
template: expect.objectContaining({
mappings: expect.objectContaining({
properties: expect.objectContaining({
sequence: {
type: 'long',
index: false,
},
}),
template: expect.objectContaining({
mappings: expect.objectContaining({
properties: expect.objectContaining({
sequence: {
type: 'long',
index: false,
},
}),
}),
}),
@ -542,15 +528,13 @@ describe('experimental_datastream_features', () => {
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
template: expect.objectContaining({
mappings: expect.objectContaining({
properties: expect.objectContaining({
name: {
type: 'keyword',
index: false,
},
}),
template: expect.objectContaining({
mappings: expect.objectContaining({
properties: expect.objectContaining({
name: {
type: 'keyword',
index: false,
},
}),
}),
}),
@ -588,11 +572,9 @@ describe('experimental_datastream_features', () => {
expect(esClient.indices.getIndexTemplate).toHaveBeenCalled();
expect(esClient.indices.putIndexTemplate).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
template: expect.objectContaining({
settings: expect.objectContaining({
index: { mode: 'time_series' },
}),
template: expect.objectContaining({
settings: expect.objectContaining({
index: { mode: 'time_series' },
}),
}),
_meta: { has_experimental_data_stream_indexing_features: true },

View file

@ -192,8 +192,7 @@ export async function handleExperimentalDatastreamFeatureOptIn({
await esClient.cluster.putComponentTemplate({
name: componentTemplateName,
// @ts-expect-error elasticsearch@9.0.0 https://github.com/elastic/elasticsearch-js/issues/2584
body,
...body,
_meta: {
has_experimental_data_stream_indexing_features: hasExperimentalDataStreamIndexingFeatures,
},
@ -211,7 +210,7 @@ export async function handleExperimentalDatastreamFeatureOptIn({
settings: {
...(indexTemplate.template?.settings ?? {}),
index: {
mode: featureMapEntry.features.tsdb ? 'time_series' : null,
mode: featureMapEntry.features.tsdb ? 'time_series' : undefined,
},
},
},
@ -221,11 +220,14 @@ export async function handleExperimentalDatastreamFeatureOptIn({
await esClient.indices.putIndexTemplate({
name: featureMapEntry.data_stream,
// @ts-expect-error elasticsearch@9.0.0 https://github.com/elastic/elasticsearch-js/issues/2584
body: indexTemplateBody,
...indexTemplateBody,
_meta: {
has_experimental_data_stream_indexing_features: featureMapEntry.features.tsdb,
},
// GET brings string | string[] | undefined but this PUT expects string[]
ignore_missing_component_templates: indexTemplateBody.ignore_missing_component_templates
? [indexTemplateBody.ignore_missing_component_templates].flat()
: undefined,
});
}