mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[Fleet] Disable ILM policy in serverless (#154460)
This commit is contained in:
parent
a0d754c595
commit
394174eedf
6 changed files with 156 additions and 18 deletions
|
@ -1 +1,2 @@
|
||||||
xpack.fleet.enableExperimental: ['fleetServerStandalone']
|
xpack.fleet.enableExperimental: ['fleetServerStandalone']
|
||||||
|
xpack.fleet.internal.ILMPoliciesDisabled: true
|
||||||
|
|
|
@ -44,6 +44,9 @@ export interface FleetConfigType {
|
||||||
disableRegistryVersionCheck?: boolean;
|
disableRegistryVersionCheck?: boolean;
|
||||||
bundledPackageLocation?: string;
|
bundledPackageLocation?: string;
|
||||||
};
|
};
|
||||||
|
internal?: {
|
||||||
|
disableILMPolicies: boolean;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calling Object.entries(PackagesGroupedByStatus) gave `status: string`
|
// Calling Object.entries(PackagesGroupedByStatus) gave `status: string`
|
||||||
|
|
|
@ -158,6 +158,14 @@ export const config: PluginConfigDescriptor = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
internal: schema.maybe(
|
||||||
|
schema.object({
|
||||||
|
disableILMPolicies: schema.boolean({
|
||||||
|
defaultValue: false,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -61,12 +61,18 @@ export function buildDefaultSettings({
|
||||||
: defaultFields
|
: defaultFields
|
||||||
).map((field) => field.name);
|
).map((field) => field.name);
|
||||||
|
|
||||||
|
const isILMPolicyDisabled = appContextService.getConfig()?.internal?.disableILMPolicies ?? false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
index: {
|
index: {
|
||||||
// ILM Policy must be added here, for now point to the default global ILM policy name
|
...(isILMPolicyDisabled
|
||||||
lifecycle: {
|
? {}
|
||||||
name: ilmPolicy ? ilmPolicy : type,
|
: {
|
||||||
},
|
// ILM Policy must be added here, for now point to the default global ILM policy name
|
||||||
|
lifecycle: {
|
||||||
|
name: ilmPolicy ? ilmPolicy : type,
|
||||||
|
},
|
||||||
|
}),
|
||||||
// What should be our default for the compression?
|
// What should be our default for the compression?
|
||||||
codec: 'best_compression',
|
codec: 'best_compression',
|
||||||
// All the default fields which should be queried have to be added here.
|
// All the default fields which should be queried have to be added here.
|
||||||
|
|
|
@ -8,11 +8,13 @@
|
||||||
import type { SavedObjectsClientContract, ElasticsearchClient } from '@kbn/core/server';
|
import type { SavedObjectsClientContract, ElasticsearchClient } from '@kbn/core/server';
|
||||||
import { savedObjectsClientMock, elasticsearchServiceMock } from '@kbn/core/server/mocks';
|
import { savedObjectsClientMock, elasticsearchServiceMock } from '@kbn/core/server/mocks';
|
||||||
import { loggerMock } from '@kbn/logging-mocks';
|
import { loggerMock } from '@kbn/logging-mocks';
|
||||||
|
|
||||||
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common/constants';
|
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common/constants';
|
||||||
|
|
||||||
import { appContextService } from '../../app_context';
|
import { appContextService } from '../../app_context';
|
||||||
import { createAppContextStartContractMock } from '../../../mocks';
|
import { createAppContextStartContractMock } from '../../../mocks';
|
||||||
|
import { saveArchiveEntries } from '../archive/storage';
|
||||||
|
import { installILMPolicy } from '../elasticsearch/ilm/install';
|
||||||
|
import { installIlmForDataStream } from '../elasticsearch/datastream_ilm/install';
|
||||||
|
|
||||||
jest.mock('../elasticsearch/template/template');
|
jest.mock('../elasticsearch/template/template');
|
||||||
jest.mock('../kibana/assets/install');
|
jest.mock('../kibana/assets/install');
|
||||||
|
@ -20,6 +22,10 @@ jest.mock('../kibana/index_pattern/install');
|
||||||
jest.mock('./install');
|
jest.mock('./install');
|
||||||
jest.mock('./get');
|
jest.mock('./get');
|
||||||
|
|
||||||
|
jest.mock('../archive/storage');
|
||||||
|
jest.mock('../elasticsearch/ilm/install');
|
||||||
|
jest.mock('../elasticsearch/datastream_ilm/install');
|
||||||
|
|
||||||
import { updateCurrentWriteIndices } from '../elasticsearch/template/template';
|
import { updateCurrentWriteIndices } from '../elasticsearch/template/template';
|
||||||
import { installKibanaAssetsAndReferences } from '../kibana/assets/install';
|
import { installKibanaAssetsAndReferences } from '../kibana/assets/install';
|
||||||
|
|
||||||
|
@ -47,8 +53,22 @@ describe('_installPackage', () => {
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
soClient = savedObjectsClientMock.create();
|
soClient = savedObjectsClientMock.create();
|
||||||
|
|
||||||
|
soClient.update.mockImplementation(async (type, id, attributes) => {
|
||||||
|
return { id, attributes } as any;
|
||||||
|
});
|
||||||
|
|
||||||
esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
|
esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
|
||||||
appContextService.start(createAppContextStartContractMock());
|
appContextService.start(createAppContextStartContractMock());
|
||||||
|
jest.mocked(installILMPolicy).mockReset();
|
||||||
|
jest.mocked(installIlmForDataStream).mockReset();
|
||||||
|
jest.mocked(installIlmForDataStream).mockResolvedValue({
|
||||||
|
esReferences: [],
|
||||||
|
installedIlms: [],
|
||||||
|
});
|
||||||
|
jest.mocked(saveArchiveEntries).mockResolvedValue({
|
||||||
|
saved_objects: [],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
appContextService.stop();
|
appContextService.stop();
|
||||||
|
@ -96,4 +116,100 @@ describe('_installPackage', () => {
|
||||||
await expect(installationPromise).rejects.toThrow('mocked');
|
await expect(installationPromise).rejects.toThrow('mocked');
|
||||||
await expect(installationPromise).rejects.toThrow('should be caught');
|
await expect(installationPromise).rejects.toThrow('should be caught');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('do not install ILM policies if disabled in config', async () => {
|
||||||
|
appContextService.start(
|
||||||
|
createAppContextStartContractMock({
|
||||||
|
internal: {
|
||||||
|
disableILMPolicies: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
// force errors from this function
|
||||||
|
mockedInstallKibanaAssetsAndReferences.mockResolvedValue([]);
|
||||||
|
// pick any function between when those are called and when await Promise.all is defined later
|
||||||
|
// and force it to take long enough for the errors to occur
|
||||||
|
// @ts-expect-error about call signature
|
||||||
|
mockedUpdateCurrentWriteIndices.mockImplementation(async () => await sleep(1000));
|
||||||
|
mockedInstallIndexTemplatesAndPipelines.mockResolvedValue({
|
||||||
|
installedTemplates: [],
|
||||||
|
esReferences: [],
|
||||||
|
});
|
||||||
|
await _installPackage({
|
||||||
|
savedObjectsClient: soClient,
|
||||||
|
// @ts-ignore
|
||||||
|
savedObjectsImporter: jest.fn(),
|
||||||
|
esClient,
|
||||||
|
logger: loggerMock.create(),
|
||||||
|
paths: [],
|
||||||
|
packageInfo: {
|
||||||
|
title: 'title',
|
||||||
|
name: 'xyz',
|
||||||
|
version: '4.5.6',
|
||||||
|
description: 'test',
|
||||||
|
type: 'integration',
|
||||||
|
categories: ['cloud', 'custom'],
|
||||||
|
format_version: 'string',
|
||||||
|
release: 'experimental',
|
||||||
|
conditions: { kibana: { version: 'x.y.z' } },
|
||||||
|
owner: { github: 'elastic/fleet' },
|
||||||
|
},
|
||||||
|
installType: 'install',
|
||||||
|
installSource: 'registry',
|
||||||
|
spaceId: DEFAULT_SPACE_ID,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(installILMPolicy).not.toBeCalled();
|
||||||
|
expect(installIlmForDataStream).not.toBeCalled();
|
||||||
|
// if we have a .catch this will fail nicely (test pass)
|
||||||
|
// otherwise the test will fail with either of the mocked errors
|
||||||
|
// await expect(installationPromise).rejects.toThrow('mocked');
|
||||||
|
// await expect(installationPromise).rejects.toThrow('should be caught');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('install ILM policies if not disabled in config', async () => {
|
||||||
|
appContextService.start(
|
||||||
|
createAppContextStartContractMock({
|
||||||
|
internal: {
|
||||||
|
disableILMPolicies: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
// force errors from this function
|
||||||
|
mockedInstallKibanaAssetsAndReferences.mockResolvedValue([]);
|
||||||
|
// pick any function between when those are called and when await Promise.all is defined later
|
||||||
|
// and force it to take long enough for the errors to occur
|
||||||
|
// @ts-expect-error about call signature
|
||||||
|
mockedUpdateCurrentWriteIndices.mockImplementation(async () => await sleep(1000));
|
||||||
|
mockedInstallIndexTemplatesAndPipelines.mockResolvedValue({
|
||||||
|
installedTemplates: [],
|
||||||
|
esReferences: [],
|
||||||
|
});
|
||||||
|
await _installPackage({
|
||||||
|
savedObjectsClient: soClient,
|
||||||
|
// @ts-ignore
|
||||||
|
savedObjectsImporter: jest.fn(),
|
||||||
|
esClient,
|
||||||
|
logger: loggerMock.create(),
|
||||||
|
paths: [],
|
||||||
|
packageInfo: {
|
||||||
|
title: 'title',
|
||||||
|
name: 'xyz',
|
||||||
|
version: '4.5.6',
|
||||||
|
description: 'test',
|
||||||
|
type: 'integration',
|
||||||
|
categories: ['cloud', 'custom'],
|
||||||
|
format_version: 'string',
|
||||||
|
release: 'experimental',
|
||||||
|
conditions: { kibana: { version: 'x.y.z' } },
|
||||||
|
owner: { github: 'elastic/fleet' },
|
||||||
|
},
|
||||||
|
installType: 'install',
|
||||||
|
installSource: 'registry',
|
||||||
|
spaceId: DEFAULT_SPACE_ID,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(installILMPolicy).toBeCalled();
|
||||||
|
expect(installIlmForDataStream).toBeCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -153,20 +153,24 @@ export async function _installPackage({
|
||||||
// currently only the base package has an ILM policy
|
// currently only the base package has an ILM policy
|
||||||
// at some point ILM policies can be installed/modified
|
// at some point ILM policies can be installed/modified
|
||||||
// per data stream and we should then save them
|
// per data stream and we should then save them
|
||||||
esReferences = await withPackageSpan('Install ILM policies', () =>
|
const isILMPoliciesDisabled =
|
||||||
installILMPolicy(packageInfo, paths, esClient, savedObjectsClient, logger, esReferences)
|
appContextService.getConfig()?.internal?.disableILMPolicies ?? false;
|
||||||
);
|
if (!isILMPoliciesDisabled) {
|
||||||
|
esReferences = await withPackageSpan('Install ILM policies', () =>
|
||||||
|
installILMPolicy(packageInfo, paths, esClient, savedObjectsClient, logger, esReferences)
|
||||||
|
);
|
||||||
|
|
||||||
({ esReferences } = await withPackageSpan('Install Data Stream ILM policies', () =>
|
({ esReferences } = await withPackageSpan('Install Data Stream ILM policies', () =>
|
||||||
installIlmForDataStream(
|
installIlmForDataStream(
|
||||||
packageInfo,
|
packageInfo,
|
||||||
paths,
|
paths,
|
||||||
esClient,
|
esClient,
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
logger,
|
logger,
|
||||||
esReferences
|
esReferences
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// installs ml models
|
// installs ml models
|
||||||
esReferences = await withPackageSpan('Install ML models', () =>
|
esReferences = await withPackageSpan('Install ML models', () =>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue