Skip to content
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
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {} },
Expand Down
20 changes: 19 additions & 1 deletion x-pack/plugins/fleet/server/services/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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',
]);
});
});
10 changes: 8 additions & 2 deletions x-pack/plugins/fleet/server/services/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down