Skip to content

Commit

Permalink
[Fleet] Fix upgrade with a large number of stream backing indices (el…
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Nov 26, 2024
1 parent bcbf54e commit 97318c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1900,9 +1900,19 @@ describe('EPM template', () => {

it('should fill constant keywords from previous mappings', async () => {
const esClient = elasticsearchServiceMock.createElasticsearchClient();

esClient.indices.getDataStream.mockResponse({
data_streams: [{ name: 'test-constant.keyword-default' }],
data_streams: [
{
name: 'test-constant.keyword-default',
indices: [
{ index_name: '.ds-test-constant.keyword-default-0001' },
{ index_name: '.ds-test-constant.keyword-default-0002' },
],
},
],
} as any);

esClient.indices.get.mockResponse({
'test-constant.keyword-default': {
mappings: {
Expand Down Expand Up @@ -1942,6 +1952,9 @@ describe('EPM template', () => {
} as any,
},
]);
expect(esClient.indices.get).toBeCalledWith({
index: '.ds-test-constant.keyword-default-0002',
});
const putMappingsCalls = esClient.indices.putMapping.mock.calls;
expect(putMappingsCalls).toHaveLength(1);
expect(putMappingsCalls[0][0]).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface CurrentDataStream {
dataStreamName: string;
replicated: boolean;
indexTemplate: IndexTemplate;
currentWriteIndex: string;
}

const DEFAULT_IGNORE_ABOVE = 1024;
Expand Down Expand Up @@ -954,6 +955,7 @@ const getDataStreams = async (
dataStreamName: dataStream.name,
replicated: dataStream.replicated,
indexTemplate,
currentWriteIndex: dataStream.indices?.at(-1)?.index_name,
}));
};

Expand Down Expand Up @@ -989,6 +991,7 @@ const updateAllDataStreams = async (
return updateExistingDataStream({
esClient,
logger,
currentWriteIndex: templateEntry.currentWriteIndex,
dataStreamName: templateEntry.dataStreamName,
options,
});
Expand All @@ -1002,11 +1005,13 @@ const updateAllDataStreams = async (

const updateExistingDataStream = async ({
dataStreamName,
currentWriteIndex,
esClient,
logger,
options,
}: {
dataStreamName: string;
currentWriteIndex: string;
esClient: ElasticsearchClient;
logger: Logger;
options?: {
Expand All @@ -1015,7 +1020,7 @@ const updateExistingDataStream = async ({
};
}) => {
const existingDs = await esClient.indices.get({
index: dataStreamName,
index: currentWriteIndex,
});

const existingDsConfig = Object.values(existingDs);
Expand Down

0 comments on commit 97318c9

Please sign in to comment.