diff --git a/x-pack/plugins/fleet/server/mocks/index.ts b/x-pack/plugins/fleet/server/mocks/index.ts index d6620fe4c3fb9..5fab5add30fc8 100644 --- a/x-pack/plugins/fleet/server/mocks/index.ts +++ b/x-pack/plugins/fleet/server/mocks/index.ts @@ -62,7 +62,7 @@ export const createAppContextStartContractMock = ( securitySetup: securityMock.createSetup(), securityStart: securityMock.createStart(), logger: loggingSystemMock.create().get(), - experimentalFeatures: {} as ExperimentalFeatures, + experimentalFeatures: { diagnosticFileUploadEnabled: true } as ExperimentalFeatures, isProductionMode: true, configInitialValue: { agents: { enabled: true, elasticsearch: {} }, diff --git a/x-pack/plugins/fleet/server/services/setup.test.ts b/x-pack/plugins/fleet/server/services/setup.test.ts index 996701c920387..7d98db879910b 100644 --- a/x-pack/plugins/fleet/server/services/setup.test.ts +++ b/x-pack/plugins/fleet/server/services/setup.test.ts @@ -15,7 +15,9 @@ import { ensurePreconfiguredPackagesAndPolicies } from '.'; import { appContextService } from './app_context'; import { getInstallations } from './epm/packages'; import { upgradeManagedPackagePolicies } from './managed_package_policies'; -import { setupFleet } from './setup'; +import { setupFleet, ensureFleetFileUploadIndices } from './setup'; + +import { ensureFileUploadWriteIndices } from './epm/elasticsearch/template/install'; jest.mock('./preconfiguration'); jest.mock('./preconfiguration/outputs'); @@ -26,6 +28,12 @@ jest.mock('./download_source'); jest.mock('./epm/packages'); jest.mock('./managed_package_policies'); jest.mock('./setup/upgrade_package_install_version'); +jest.mock('./epm/elasticsearch/template/install', () => { + return { + ...jest.requireActual('./epm/elasticsearch/template/install'), + ensureFileUploadWriteIndices: jest.fn(), + }; +}); const mockedMethodThrowsError = (mockFn: jest.Mock) => mockFn.mockImplementation(() => { @@ -62,6 +70,8 @@ describe('setupFleet', () => { soClient.find.mockResolvedValue({ saved_objects: [] } as any); soClient.bulkGet.mockResolvedValue({ saved_objects: [] } as any); + + (ensureFileUploadWriteIndices as jest.Mock).mockResolvedValue({}); }); afterEach(async () => { @@ -128,4 +138,12 @@ describe('setupFleet', () => { ], }); }); + + it('should create agent file upload write indices', async () => { + await ensureFleetFileUploadIndices(soClient, esClient); + + expect((ensureFileUploadWriteIndices as jest.Mock).mock.calls[0][0].integrationNames).toEqual([ + 'elastic_agent', + ]); + }); }); diff --git a/x-pack/plugins/fleet/server/services/setup.ts b/x-pack/plugins/fleet/server/services/setup.ts index 7a35d6813cafa..da8bcfc3d093f 100644 --- a/x-pack/plugins/fleet/server/services/setup.ts +++ b/x-pack/plugins/fleet/server/services/setup.ts @@ -12,7 +12,11 @@ import pMap from 'p-map'; import type { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/server'; import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common/constants'; -import { AUTO_UPDATE_PACKAGES, FILE_STORAGE_INTEGRATION_NAMES } from '../../common/constants'; +import { + AUTO_UPDATE_PACKAGES, + FILE_STORAGE_INTEGRATION_NAMES, + FLEET_ELASTIC_AGENT_PACKAGE, +} from '../../common/constants'; import type { PreconfigurationError } from '../../common/constants'; import type { DefaultPackagesInstallationError, @@ -199,8 +203,10 @@ export async function ensureFleetFileUploadIndices( pkgNames: [...FILE_STORAGE_INTEGRATION_NAMES], }); - if (!installedFileUploadIntegrations.length) return []; const integrationNames = installedFileUploadIntegrations.map(({ name }) => name); + if (!integrationNames.includes(FLEET_ELASTIC_AGENT_PACKAGE)) { + integrationNames.push(FLEET_ELASTIC_AGENT_PACKAGE); + } logger.debug(`Ensuring file upload write indices for ${integrationNames}`); return ensureFileUploadWriteIndices({ esClient,