mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Profiling] Fix incorrect status of single-click installation (#159168)
## Summary This PR addresses two bugs discovered after https://github.com/elastic/kibana/pull/157949: * when setting up security roles, the incorrect status was set * when merging the statuses of all steps, the merged status could lose some statuses
This commit is contained in:
parent
e52e889503
commit
5e907edc39
3 changed files with 158 additions and 2 deletions
155
x-pack/plugins/profiling/common/setup.test.ts
Normal file
155
x-pack/plugins/profiling/common/setup.test.ts
Normal file
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
areResourcesSetup,
|
||||
createDefaultSetupState,
|
||||
mergePartialSetupStates,
|
||||
PartialSetupState,
|
||||
} from './setup';
|
||||
|
||||
function createCloudState(available: boolean): PartialSetupState {
|
||||
return {
|
||||
cloud: {
|
||||
available,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createDataState(available: boolean): PartialSetupState {
|
||||
return {
|
||||
data: {
|
||||
available,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createPackageState(installed: boolean): PartialSetupState {
|
||||
return {
|
||||
packages: {
|
||||
installed,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createPermissionState(configured: boolean): PartialSetupState {
|
||||
return {
|
||||
permissions: {
|
||||
configured,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createApmPolicyState(installed: boolean): PartialSetupState {
|
||||
return {
|
||||
policies: {
|
||||
apm: {
|
||||
installed,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createCollectorPolicyState(installed: boolean): PartialSetupState {
|
||||
return {
|
||||
policies: {
|
||||
collector: {
|
||||
installed,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createSymbolizerPolicyState(installed: boolean): PartialSetupState {
|
||||
return {
|
||||
policies: {
|
||||
symbolizer: {
|
||||
installed,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createResourceState({
|
||||
enabled,
|
||||
created,
|
||||
}: {
|
||||
enabled: boolean;
|
||||
created: boolean;
|
||||
}): PartialSetupState {
|
||||
return {
|
||||
resource_management: {
|
||||
enabled,
|
||||
},
|
||||
resources: {
|
||||
created,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createSettingsState(configured: boolean): PartialSetupState {
|
||||
return {
|
||||
settings: {
|
||||
configured,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe('Merging partial state operations', () => {
|
||||
const defaultSetupState = createDefaultSetupState();
|
||||
|
||||
test('partial states with missing key', () => {
|
||||
const mergedState = mergePartialSetupStates(defaultSetupState, [
|
||||
createCloudState(true),
|
||||
createDataState(true),
|
||||
]);
|
||||
|
||||
expect(mergedState.cloud.available).toEqual(true);
|
||||
expect(mergedState.cloud.required).toEqual(true);
|
||||
expect(mergedState.data.available).toEqual(true);
|
||||
});
|
||||
|
||||
test('deeply nested partial states with overlap', () => {
|
||||
const mergedState = mergePartialSetupStates(defaultSetupState, [
|
||||
createApmPolicyState(true),
|
||||
createCollectorPolicyState(true),
|
||||
createSymbolizerPolicyState(true),
|
||||
]);
|
||||
|
||||
expect(mergedState.policies.apm.installed).toEqual(true);
|
||||
expect(mergedState.policies.collector.installed).toEqual(true);
|
||||
expect(mergedState.policies.symbolizer.installed).toEqual(true);
|
||||
});
|
||||
|
||||
test('check resource status with failed partial states', () => {
|
||||
const mergedState = mergePartialSetupStates(defaultSetupState, [
|
||||
createPackageState(false),
|
||||
createApmPolicyState(true),
|
||||
createCollectorPolicyState(true),
|
||||
createSymbolizerPolicyState(true),
|
||||
createPermissionState(false),
|
||||
createResourceState({ enabled: true, created: true }),
|
||||
createSettingsState(true),
|
||||
]);
|
||||
|
||||
expect(areResourcesSetup(mergedState)).toEqual(false);
|
||||
});
|
||||
|
||||
test('check resource status with all successful partial states', () => {
|
||||
const mergedState = mergePartialSetupStates(defaultSetupState, [
|
||||
createPackageState(true),
|
||||
createApmPolicyState(true),
|
||||
createCollectorPolicyState(true),
|
||||
createSymbolizerPolicyState(true),
|
||||
createPermissionState(true),
|
||||
createResourceState({ enabled: true, created: true }),
|
||||
createSettingsState(true),
|
||||
]);
|
||||
|
||||
expect(areResourcesSetup(mergedState)).toEqual(true);
|
||||
});
|
||||
});
|
|
@ -5,6 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { merge } from 'lodash';
|
||||
import { RecursivePartial } from '@kbn/apm-plugin/typings/common';
|
||||
|
||||
export interface SetupState {
|
||||
|
@ -97,7 +98,7 @@ export function areResourcesSetup(state: SetupState): boolean {
|
|||
}
|
||||
|
||||
function mergeRecursivePartial<T>(base: T, partial: RecursivePartial<T>): T {
|
||||
return { ...base, ...partial };
|
||||
return merge(base, partial);
|
||||
}
|
||||
|
||||
export function mergePartialSetupStates(
|
||||
|
|
|
@ -16,7 +16,7 @@ export async function validateSecurityRole({
|
|||
const esClient = client.getEsClient();
|
||||
const roles = await esClient.security.getRole();
|
||||
return {
|
||||
settings: {
|
||||
permissions: {
|
||||
configured: PROFILING_READER_ROLE_NAME in roles,
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue