Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Only provide obsoleteIndexTemplatePattern to the default index migrator to avoid race conditions (#42016) #42033

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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