Skip to content

Commit

Permalink
[Rule Registry] ignore some errors while updating index mappings (ela…
Browse files Browse the repository at this point in the history
…stic#140778)

resolves elastic#139969

Changes the ResourceInstaller to ignore cases when the elasticsearch
simulateIndexTemplate() API returns an error or empty mappings, logging an
error instead. This will hopefully allow initialization to continue to set
up the alerts-as-data indices and backing resources for future indexing.

Also adds _meta: { managed: true } to the ILM policy, which should show a
warning in Kibana UX when attempting to make changes to the policy. Which
was the cause of why simulateIndexTemplate() could return empty mappings.

(cherry picked from commit 01daf31)

# Conflicts:
#	x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.test.ts
#	x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.ts
  • Loading branch information
pmuellr committed Sep 20, 2022
1 parent 2f13a1b commit 5682944
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

export const defaultLifecyclePolicy = {
policy: {
_meta: {
managed: true,
},
phases: {
hot: {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,26 @@ export class ResourceInstaller {
private async updateAliasWriteIndexMapping({ index, alias }: ConcreteIndexInfo) {
const { logger, getClusterClient } = this.options;
const clusterClient = await getClusterClient();
const simulatedIndexMapping = await clusterClient.indices.simulateIndexTemplate({
name: index,
});

let simulatedIndexMapping: estypes.IndicesSimulateIndexTemplateResponse;
try {
simulatedIndexMapping = await clusterClient.indices.simulateIndexTemplate({
name: index,
});
} catch (err) {
logger.error(
`Ignored PUT mappings for alias ${alias}; error generating simulated mappings: ${err.message}`
);
return;
}

const simulatedMapping = get(simulatedIndexMapping, ['body', 'template', 'mappings']);

if (simulatedMapping == null) {
logger.error(`Ignored PUT mappings for alias ${alias}; simulated mappings were empty`);
return;
}

try {
await clusterClient.indices.putMapping({
index,
Expand Down

0 comments on commit 5682944

Please sign in to comment.