Skip to content

Commit

Permalink
Only provide obsoleteIndexTemplatePattern to the default index migrat…
Browse files Browse the repository at this point in the history
…or to avoid race conditions (elastic#42016) (elastic#42033)

* Only provide obsoleteIndexTemplatePattern to the default index migrator to avoid race conditions

* Add test

* Apply PR feedback
  • Loading branch information
mikecote authored Jul 26, 2019
1 parent 5a46b8c commit 81f77df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ describe('KibanaMigrator', () => {
const migrationResults = await new KibanaMigrator({ kbnServer }).awaitMigration();
expect(migrationResults.length).toEqual(2);
});

it('only handles and deletes index templates once', async () => {
const { kbnServer } = mockKbnServer();
const clusterStub = jest.fn<any, any>(() => ({ status: 404 }));
const waitUntilReady = jest.fn(async () => undefined);

kbnServer.server.plugins.elasticsearch = {
waitUntilReady,
getCluster() {
return {
callWithInternalUser: clusterStub,
};
},
};

await new KibanaMigrator({ kbnServer }).awaitMigration();

// callCluster with "cat.templates" is called by "deleteIndexTemplates" function
// and should only be done once
const callClusterCommands = clusterStub.mock.calls
.map(([callClusterPath]) => callClusterPath)
.filter(callClusterPath => callClusterPath === 'cat.templates');
expect(callClusterCommands.length).toBe(1);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export class KibanaMigrator {
await server.plugins.elasticsearch.waitUntilReady();

const config = server.config();
const kibanaIndexName = config.get('kibana.index');
const indexMap = createIndexMap(
config.get('kibana.index'),
kibanaIndexName,
this.kbnServer.uiExports.savedObjectSchemas,
this.mappingProperties
);
Expand All @@ -110,7 +111,9 @@ export class KibanaMigrator {
pollInterval: config.get('migrations.pollInterval'),
scrollDuration: config.get('migrations.scrollDuration'),
serializer: this.serializer,
obsoleteIndexTemplatePattern: 'kibana_index_template*',
// Only necessary for the migrator of the kibana index.
obsoleteIndexTemplatePattern:
index === kibanaIndexName ? 'kibana_index_template*' : undefined,
convertToAliasScript: indexMap[index].script,
});
});
Expand Down

0 comments on commit 81f77df

Please sign in to comment.