Skip to content

Commit 3ab31d3

Browse files
authored
[ES 9.0] Remove body workaround (@elastic/fleet) (#217218)
## Summary Follow up to #213375: The latest version of the ES client fixed the issue elastic/elasticsearch-js#2584. We should be able to remove all usages of `// @ts-expect-error [email protected] 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
1 parent e7dbe43 commit 3ab31d3

File tree

6 files changed

+101
-129
lines changed

6 files changed

+101
-129
lines changed

x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/install.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,10 @@ const installPreBuiltComponentTemplates = async (
216216

217217
const esClientParams = {
218218
name: templateName,
219-
body: content,
219+
...content,
220220
};
221221

222222
return retryTransientEsErrors(
223-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584
224223
() => esClient.cluster.putComponentTemplate(esClientParams, { ignore: [404] }),
225224
{ logger }
226225
);
@@ -695,10 +694,9 @@ async function installTemplate({
695694
// TODO: Check return values for errors
696695
const esClientParams = {
697696
name: template.templateName,
698-
body: template.indexTemplate,
697+
...template.indexTemplate,
699698
};
700699
await retryTransientEsErrors(
701-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584
702700
() => esClient.indices.putIndexTemplate(esClientParams, { ignore: [404] }),
703701
{ logger }
704702
);

x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/template.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,12 +2037,10 @@ describe('EPM template', () => {
20372037
expect(putMappingsCalls).toHaveLength(1);
20382038
expect(putMappingsCalls[0][0]).toEqual({
20392039
index: 'test-constant.keyword-default',
2040-
body: {
2041-
properties: {
2042-
some_keyword_field: {
2043-
type: 'constant_keyword',
2044-
value: 'some_value',
2045-
},
2040+
properties: {
2041+
some_keyword_field: {
2042+
type: 'constant_keyword',
2043+
value: 'some_value',
20462044
},
20472045
},
20482046
write_index_only: true,
@@ -2087,7 +2085,6 @@ describe('EPM template', () => {
20872085
expect(putMappingsCalls).toHaveLength(1);
20882086
expect(putMappingsCalls[0][0]).toEqual({
20892087
index: 'test-constant.keyword-default',
2090-
body: {},
20912088
write_index_only: true,
20922089
});
20932090
});

x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/template.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,7 @@ const updateExistingDataStream = async ({
11071107
() =>
11081108
esClient.indices.putMapping({
11091109
index: dataStreamName,
1110-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584
1111-
body: mappings,
1110+
...mappings,
11121111
write_index_only: true,
11131112
}),
11141113
{ logger }

x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/transform/transforms.test.ts

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -383,21 +383,19 @@ _meta:
383383
expect(esClient.indices.putIndexTemplate.mock.calls).toEqual([
384384
[
385385
{
386-
body: {
387-
_meta: meta,
388-
composed_of: [
389-
'logs-endpoint.metadata_current-template@package',
390-
'endpoint@custom',
391-
'logs-endpoint.metadata_current-template@custom',
392-
],
393-
index_patterns: ['.metrics-endpoint.metadata_united_default'],
394-
priority: 250,
395-
template: { mappings: undefined, settings: undefined },
396-
ignore_missing_component_templates: [
397-
'endpoint@custom',
398-
'logs-endpoint.metadata_current-template@custom',
399-
],
400-
},
386+
_meta: meta,
387+
composed_of: [
388+
'logs-endpoint.metadata_current-template@package',
389+
'endpoint@custom',
390+
'logs-endpoint.metadata_current-template@custom',
391+
],
392+
index_patterns: ['.metrics-endpoint.metadata_united_default'],
393+
priority: 250,
394+
template: { mappings: undefined, settings: undefined },
395+
ignore_missing_component_templates: [
396+
'endpoint@custom',
397+
'logs-endpoint.metadata_current-template@custom',
398+
],
401399
name: 'logs-endpoint.metadata_current-template',
402400
},
403401
{ ignore: [404] },
@@ -673,21 +671,19 @@ _meta:
673671
expect(esClient.indices.putIndexTemplate.mock.calls).toEqual([
674672
[
675673
{
676-
body: {
677-
_meta: meta,
678-
composed_of: [
679-
'logs-endpoint.metadata_current-template@package',
680-
'endpoint@custom',
681-
'logs-endpoint.metadata_current-template@custom',
682-
],
683-
index_patterns: ['.metrics-endpoint.metadata_united_default'],
684-
priority: 250,
685-
template: { mappings: undefined, settings: undefined },
686-
ignore_missing_component_templates: [
687-
'endpoint@custom',
688-
'logs-endpoint.metadata_current-template@custom',
689-
],
690-
},
674+
_meta: meta,
675+
composed_of: [
676+
'logs-endpoint.metadata_current-template@package',
677+
'endpoint@custom',
678+
'logs-endpoint.metadata_current-template@custom',
679+
],
680+
index_patterns: ['.metrics-endpoint.metadata_united_default'],
681+
priority: 250,
682+
template: { mappings: undefined, settings: undefined },
683+
ignore_missing_component_templates: [
684+
'endpoint@custom',
685+
'logs-endpoint.metadata_current-template@custom',
686+
],
691687
name: 'logs-endpoint.metadata_current-template',
692688
},
693689
{ ignore: [404] },
@@ -940,21 +936,19 @@ _meta:
940936
expect(esClient.indices.putIndexTemplate.mock.calls).toEqual([
941937
[
942938
{
943-
body: {
944-
_meta: meta,
945-
composed_of: [
946-
'logs-endpoint.metadata_current-template@package',
947-
'endpoint@custom',
948-
'logs-endpoint.metadata_current-template@custom',
949-
],
950-
index_patterns: ['.metrics-endpoint.metadata_united_default'],
951-
priority: 250,
952-
template: { mappings: undefined, settings: undefined },
953-
ignore_missing_component_templates: [
954-
'endpoint@custom',
955-
'logs-endpoint.metadata_current-template@custom',
956-
],
957-
},
939+
_meta: meta,
940+
composed_of: [
941+
'logs-endpoint.metadata_current-template@package',
942+
'endpoint@custom',
943+
'logs-endpoint.metadata_current-template@custom',
944+
],
945+
index_patterns: ['.metrics-endpoint.metadata_united_default'],
946+
priority: 250,
947+
template: { mappings: undefined, settings: undefined },
948+
ignore_missing_component_templates: [
949+
'endpoint@custom',
950+
'logs-endpoint.metadata_current-template@custom',
951+
],
958952
name: 'logs-endpoint.metadata_current-template',
959953
},
960954
{ ignore: [404] },

x-pack/platform/plugins/shared/fleet/server/services/package_policies/experimental_datastream_features.test.ts

Lines changed: 48 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,10 @@ describe('experimental_datastream_features', () => {
269269
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
270270
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
271271
expect.objectContaining({
272-
body: expect.objectContaining({
273-
template: expect.objectContaining({
274-
settings: expect.objectContaining({
275-
index: expect.objectContaining({
276-
mapping: expect.objectContaining({ source: { mode: 'synthetic' } }),
277-
}),
272+
template: expect.objectContaining({
273+
settings: expect.objectContaining({
274+
index: expect.objectContaining({
275+
mapping: expect.objectContaining({ source: { mode: 'synthetic' } }),
278276
}),
279277
}),
280278
}),
@@ -296,15 +294,13 @@ describe('experimental_datastream_features', () => {
296294
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
297295
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
298296
expect.objectContaining({
299-
body: expect.objectContaining({
300-
template: expect.objectContaining({
301-
mappings: expect.objectContaining({
302-
properties: expect.objectContaining({
303-
sequence: {
304-
type: 'long',
305-
index: false,
306-
},
307-
}),
297+
template: expect.objectContaining({
298+
mappings: expect.objectContaining({
299+
properties: expect.objectContaining({
300+
sequence: {
301+
type: 'long',
302+
index: false,
303+
},
308304
}),
309305
}),
310306
}),
@@ -326,15 +322,13 @@ describe('experimental_datastream_features', () => {
326322
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
327323
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
328324
expect.objectContaining({
329-
body: expect.objectContaining({
330-
template: expect.objectContaining({
331-
mappings: expect.objectContaining({
332-
properties: expect.objectContaining({
333-
name: {
334-
type: 'keyword',
335-
index: false,
336-
},
337-
}),
325+
template: expect.objectContaining({
326+
mappings: expect.objectContaining({
327+
properties: expect.objectContaining({
328+
name: {
329+
type: 'keyword',
330+
index: false,
331+
},
338332
}),
339333
}),
340334
}),
@@ -356,14 +350,12 @@ describe('experimental_datastream_features', () => {
356350
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
357351
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
358352
expect.objectContaining({
359-
body: expect.objectContaining({
360-
template: expect.objectContaining({
361-
mappings: expect.objectContaining({
362-
properties: expect.objectContaining({
363-
'@timestamp': {
364-
type: 'date',
365-
},
366-
}),
353+
template: expect.objectContaining({
354+
mappings: expect.objectContaining({
355+
properties: expect.objectContaining({
356+
'@timestamp': {
357+
type: 'date',
358+
},
367359
}),
368360
}),
369361
}),
@@ -385,11 +377,9 @@ describe('experimental_datastream_features', () => {
385377
expect(esClient.indices.getIndexTemplate).toHaveBeenCalled();
386378
expect(esClient.indices.putIndexTemplate).toHaveBeenCalledWith(
387379
expect.objectContaining({
388-
body: expect.objectContaining({
389-
template: expect.objectContaining({
390-
settings: expect.objectContaining({
391-
index: { mode: 'time_series' },
392-
}),
380+
template: expect.objectContaining({
381+
settings: expect.objectContaining({
382+
index: { mode: 'time_series' },
393383
}),
394384
}),
395385
_meta: { has_experimental_data_stream_indexing_features: true },
@@ -485,12 +475,10 @@ describe('experimental_datastream_features', () => {
485475
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
486476
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
487477
expect.objectContaining({
488-
body: expect.objectContaining({
489-
template: expect.objectContaining({
490-
settings: expect.objectContaining({
491-
index: expect.objectContaining({
492-
mapping: expect.objectContaining({ source: { mode: 'synthetic' } }),
493-
}),
478+
template: expect.objectContaining({
479+
settings: expect.objectContaining({
480+
index: expect.objectContaining({
481+
mapping: expect.objectContaining({ source: { mode: 'synthetic' } }),
494482
}),
495483
}),
496484
}),
@@ -512,15 +500,13 @@ describe('experimental_datastream_features', () => {
512500
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
513501
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
514502
expect.objectContaining({
515-
body: expect.objectContaining({
516-
template: expect.objectContaining({
517-
mappings: expect.objectContaining({
518-
properties: expect.objectContaining({
519-
sequence: {
520-
type: 'long',
521-
index: false,
522-
},
523-
}),
503+
template: expect.objectContaining({
504+
mappings: expect.objectContaining({
505+
properties: expect.objectContaining({
506+
sequence: {
507+
type: 'long',
508+
index: false,
509+
},
524510
}),
525511
}),
526512
}),
@@ -542,15 +528,13 @@ describe('experimental_datastream_features', () => {
542528
expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled();
543529
expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith(
544530
expect.objectContaining({
545-
body: expect.objectContaining({
546-
template: expect.objectContaining({
547-
mappings: expect.objectContaining({
548-
properties: expect.objectContaining({
549-
name: {
550-
type: 'keyword',
551-
index: false,
552-
},
553-
}),
531+
template: expect.objectContaining({
532+
mappings: expect.objectContaining({
533+
properties: expect.objectContaining({
534+
name: {
535+
type: 'keyword',
536+
index: false,
537+
},
554538
}),
555539
}),
556540
}),
@@ -588,11 +572,9 @@ describe('experimental_datastream_features', () => {
588572
expect(esClient.indices.getIndexTemplate).toHaveBeenCalled();
589573
expect(esClient.indices.putIndexTemplate).toHaveBeenCalledWith(
590574
expect.objectContaining({
591-
body: expect.objectContaining({
592-
template: expect.objectContaining({
593-
settings: expect.objectContaining({
594-
index: { mode: 'time_series' },
595-
}),
575+
template: expect.objectContaining({
576+
settings: expect.objectContaining({
577+
index: { mode: 'time_series' },
596578
}),
597579
}),
598580
_meta: { has_experimental_data_stream_indexing_features: true },

x-pack/platform/plugins/shared/fleet/server/services/package_policies/experimental_datastream_features.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ export async function handleExperimentalDatastreamFeatureOptIn({
192192

193193
await esClient.cluster.putComponentTemplate({
194194
name: componentTemplateName,
195-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584
196-
body,
195+
...body,
197196
_meta: {
198197
has_experimental_data_stream_indexing_features: hasExperimentalDataStreamIndexingFeatures,
199198
},
@@ -211,7 +210,7 @@ export async function handleExperimentalDatastreamFeatureOptIn({
211210
settings: {
212211
...(indexTemplate.template?.settings ?? {}),
213212
index: {
214-
mode: featureMapEntry.features.tsdb ? 'time_series' : null,
213+
mode: featureMapEntry.features.tsdb ? 'time_series' : undefined,
215214
},
216215
},
217216
},
@@ -221,11 +220,14 @@ export async function handleExperimentalDatastreamFeatureOptIn({
221220

222221
await esClient.indices.putIndexTemplate({
223222
name: featureMapEntry.data_stream,
224-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584
225-
body: indexTemplateBody,
223+
...indexTemplateBody,
226224
_meta: {
227225
has_experimental_data_stream_indexing_features: featureMapEntry.features.tsdb,
228226
},
227+
// GET brings string | string[] | undefined but this PUT expects string[]
228+
ignore_missing_component_templates: indexTemplateBody.ignore_missing_component_templates
229+
? [indexTemplateBody.ignore_missing_component_templates].flat()
230+
: undefined,
229231
});
230232
}
231233

0 commit comments

Comments
 (0)