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

[Fleet] Don't throw concurrent installation error when encountering conflicts #173190

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class PackageInvalidArchiveError extends FleetError {}
export class PackageRemovalError extends FleetError {}
export class PackageESError extends FleetError {}
export class ConcurrentInstallOperationError extends FleetError {}
export class PackageSavedObjectConflictError extends FleetError {}
kpollich marked this conversation as resolved.
Show resolved Hide resolved

export class KibanaSOReferenceError extends FleetError {}
export class PackageAlreadyInstalledError extends FleetError {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { savedObjectsClientMock, elasticsearchServiceMock } from '@kbn/core/serv
import { loggerMock } from '@kbn/logging-mocks';
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common/constants';

import { ConcurrentInstallOperationError } from '../../../errors';
import { ConcurrentInstallOperationError, PackageSavedObjectConflictError } from '../../../errors';

import type { Installation } from '../../../../common';

Expand Down Expand Up @@ -254,7 +254,6 @@ describe('_installPackage', () => {
});

describe('when package is stuck in `installing`', () => {
afterEach(() => {});
const mockInstalledPackageSo: SavedObject<Installation> = {
id: 'mocked-package',
attributes: {
Expand Down Expand Up @@ -387,4 +386,56 @@ describe('_installPackage', () => {
});
});
});

it('surfaces saved object conflicts error', () => {
appContextService.start(
createAppContextStartContractMock({
internal: {
disableILMPolicies: false,
disableProxies: false,
fleetServerStandalone: false,
onlyAllowAgentUpgradeToKnownVersions: false,
retrySetupOnBoot: false,
registry: {
kibanaVersionCheckEnabled: true,
capabilities: [],
excludePackages: [],
},
},
})
);

mockedInstallKibanaAssetsAndReferences.mockRejectedValueOnce(
new PackageSavedObjectConflictError('test')
);

expect(
_installPackage({
savedObjectsClient: soClient,
// @ts-ignore
savedObjectsImporter: jest.fn(),
esClient,
logger: loggerMock.create(),
packageInstallContext: {
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' },
} as any,
assetsMap: new Map(),
paths: [],
},
installType: 'install',
installSource: 'registry',
spaceId: DEFAULT_SPACE_ID,
})
).rejects.toThrowError(PackageSavedObjectConflictError);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { installTransforms } from '../elasticsearch/transform/install';
import { installMlModel } from '../elasticsearch/ml_model';
import { installIlmForDataStream } from '../elasticsearch/datastream_ilm/install';
import { saveArchiveEntriesFromAssetsMap } from '../archive/storage';
import { ConcurrentInstallOperationError } from '../../../errors';
import { ConcurrentInstallOperationError, PackageSavedObjectConflictError } from '../../../errors';
import { appContextService, packagePolicyService } from '../..';

import { auditLoggingService } from '../../audit_logging';
Expand Down Expand Up @@ -387,10 +387,12 @@ export async function _installPackage({
return [...installedKibanaAssetsRefs, ...esReferences];
} catch (err) {
if (SavedObjectsErrorHelpers.isConflictError(err)) {
throw new ConcurrentInstallOperationError(
`Concurrent installation or upgrade of ${pkgName || 'unknown'}-${
throw new PackageSavedObjectConflictError(
`Saved Object conflict encountered while installing ${pkgName || 'unknown'}-${
pkgVersion || 'unknown'
} detected, aborting. Original error: ${err.message}`
}. There may be a conflicting Saved Object saved to another Space. Original error: ${
err.message
}`
);
} else {
throw err;
Expand Down