Skip to content

Commit

Permalink
Index Management ES JS client migration followup (elastic#107463)
Browse files Browse the repository at this point in the history
* Improve Index Management ts-expect-error annotations.
* Add steps for testing legacy index template mappings types to Index Management README.
* Rename component template API route handler files to follow pattern used elsewhere.
  • Loading branch information
cjcenizal authored and vadimkibana committed Aug 8, 2021
1 parent 295d70b commit ccad260
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/index_lifecycle_management/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const indexLifecycleDataEnricher = async (
return indicesList.map((index: IndexWithoutIlm) => {
return {
...index,
// @ts-expect-error @elastic/elasticsearch Element implicitly has an 'any' type
// @ts-expect-error @elastic/elasticsearch https://github.com/elastic/elasticsearch-specification/issues/531
ilm: { ...(ilmIndicesData[index.name] || {}) },
};
});
Expand Down
19 changes: 18 additions & 1 deletion x-pack/plugins/index_management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,21 @@ PUT _template/.cloud-example
}
```

The UI will now prevent you from editing or deleting this template.
The UI will now prevent you from editing or deleting this template.

In 7.x, the UI supports types defined as part of the mappings for legacy index templates. To test this out, use the "Load JSON" feature and verify the custom type is preserved:

```
{
"my_custom_type": {
"_source": {
"enabled": false
},
"properties": {
"name1": {
"type": "keyword"
}
}
}
}
```
4 changes: 2 additions & 2 deletions x-pack/plugins/index_management/server/lib/fetch_indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ async function fetchIndicesCall(
size: hit['store.size'],
isFrozen: hit.sth === 'true', // sth value coming back as a string from ES
aliases: aliases.length ? aliases : 'none',
// @ts-expect-error @elastic/elasticsearch Property 'index' does not exist on type 'IndicesIndexSettings | IndicesIndexStatePrefixedSettings'.
// @ts-expect-error @elastic/elasticsearch https://github.com/elastic/elasticsearch-specification/issues/532
hidden: index.settings.index.hidden === 'true',
// @ts-expect-error @elastic/elasticsearch Property 'data_stream' does not exist on type 'IndicesIndexState'.
// @ts-expect-error @elastic/elasticsearch https://github.com/elastic/elasticsearch-specification/issues/532
data_stream: index.data_stream!,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import { RouteDependencies } from '../../../types';

import { registerGetAllRoute } from './get';
import { registerCreateRoute } from './create';
import { registerUpdateRoute } from './update';
import { registerDeleteRoute } from './delete';
import { registerPrivilegesRoute } from './privileges';
import { registerGetAllRoute } from './register_get_route';
import { registerCreateRoute } from './register_create_route';
import { registerUpdateRoute } from './register_update_route';
import { registerDeleteRoute } from './register_delete_route';
import { registerPrivilegesRoute } from './register_privileges_route';

export function registerComponentTemplateRoutes(dependencies: RouteDependencies) {
registerGetAllRoute(dependencies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const registerCreateRoute = ({
try {
const { body: responseBody } = await client.asCurrentUser.cluster.putComponentTemplate({
name,
// @ts-expect-error @elastic/elasticsearch Type 'ComponentTemplateSerialized' is not assignable
// @ts-expect-error ComponentTemplateSerialized conflicts with @elastic/elasticsearch ClusterPutComponentTemplateRequest
body: serializedComponentTemplate,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'sr

import { IndexDataEnricher } from '../../../services/index_data_enricher';

import { registerPrivilegesRoute } from './privileges';
import { registerPrivilegesRoute } from './register_privileges_route';

jest.mock('../../../services/index_data_enricher');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { estypes } from '@elastic/elasticsearch';

import { RouteDependencies } from '../../../types';
import { addBasePath } from '../index';
Expand Down Expand Up @@ -39,8 +40,7 @@ export const registerUpdateRoute = ({
const { body: responseBody } = await client.asCurrentUser.cluster.putComponentTemplate({
name,
body: {
// @ts-expect-error @elastic/elasticsearch Not assignable to type 'IndicesIndexState'
template,
template: template as estypes.IndicesIndexState,
version,
_meta,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ export function registerGetAllRoute({ router, lib: { handleEsError }, config }:
}

const enhancedDataStreams = enhanceDataStreams({
// @ts-expect-error @elastic/elasticsearch DataStreamFromEs incompatible with IndicesGetDataStreamIndicesGetDataStreamItem
// @ts-expect-error DataStreamFromEs conflicts with @elastic/elasticsearch IndicesGetDataStreamIndicesGetDataStreamItem
dataStreams,
// @ts-expect-error @elastic/elasticsearch StatsFromEs incompatible with IndicesDataStreamsStatsDataStreamsStatsItem
// @ts-expect-error StatsFromEs conflicts with @elastic/elasticsearch IndicesDataStreamsStatsDataStreamsStatsItem
dataStreamsStats,
// @ts-expect-error @elastic/elasticsearch PrivilegesFromEs incompatible with ApplicationsPrivileges
// @ts-expect-error PrivilegesFromEs conflicts with @elastic/elasticsearch ApplicationsPrivileges
dataStreamsPrivileges,
});

Expand Down Expand Up @@ -176,11 +176,11 @@ export function registerGetOneRoute({ router, lib: { handleEsError }, config }:
}

const enhancedDataStreams = enhanceDataStreams({
// @ts-expect-error @elastic/elasticsearch DataStreamFromEs incompatible with IndicesGetDataStreamIndicesGetDataStreamItem
// @ts-expect-error DataStreamFromEs conflicts with @elastic/elasticsearch IndicesGetDataStreamIndicesGetDataStreamItem
dataStreams,
// @ts-expect-error @elastic/elasticsearch StatsFromEs incompatible with IndicesDataStreamsStatsDataStreamsStatsItem
// @ts-expect-error StatsFromEs conflicts with @elastic/elasticsearch IndicesDataStreamsStatsDataStreamsStatsItem
dataStreamsStats,
// @ts-expect-error @elastic/elasticsearch PrivilegesFromEs incompatible with ApplicationsPrivileges
// @ts-expect-error PrivilegesFromEs conflicts with @elastic/elasticsearch ApplicationsPrivileges
dataStreamsPrivileges,
});
const body = deserializeDataStream(enhancedDataStreams[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const saveTemplate = async ({

return await client.asCurrentUser.indices.putTemplate({
name: template.name,
// @ts-expect-error @elastic/elasticsearch not assignable to parameter of type 'IndicesPutTemplateRequest'
// @ts-expect-error @elastic/elasticsearch https://github.com/elastic/elasticsearch-specification/issues/533
order,
body: {
index_patterns,
Expand All @@ -65,7 +65,7 @@ export const saveTemplate = async ({

return await client.asCurrentUser.indices.putIndexTemplate({
name: template.name,
// @ts-expect-error @elastic/elasticsearch Type 'LegacyTemplateSerialized | TemplateSerialized' is not assignable
// @ts-expect-error LegacyTemplateSerialized | TemplateSerialized conflicts with @elastic/elasticsearch IndicesPutIndexTemplateRequest
body: serializedTemplate,
});
};

0 comments on commit ccad260

Please sign in to comment.