mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Profiling: get rid of apm policy modifications (#162663)
## Summary Remove apm-related configurations from the Universal Profiling setup logic. Signed-off-by: inge4pres <francesco.gualazzi@elastic.co> Co-authored-by: Joseph Crail <joseph.crail@elastic.co>
This commit is contained in:
parent
716ecb8a04
commit
ecb7f3eaf7
6 changed files with 0 additions and 212 deletions
|
@ -28,14 +28,6 @@ function createDataState(available: boolean): PartialSetupState {
|
|||
};
|
||||
}
|
||||
|
||||
function createPackageState(installed: boolean): PartialSetupState {
|
||||
return {
|
||||
packages: {
|
||||
installed,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createPermissionState(configured: boolean): PartialSetupState {
|
||||
return {
|
||||
permissions: {
|
||||
|
@ -44,16 +36,6 @@ function createPermissionState(configured: boolean): PartialSetupState {
|
|||
};
|
||||
}
|
||||
|
||||
function createApmPolicyState(installed: boolean): PartialSetupState {
|
||||
return {
|
||||
policies: {
|
||||
apm: {
|
||||
installed,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createCollectorPolicyState(installed: boolean): PartialSetupState {
|
||||
return {
|
||||
policies: {
|
||||
|
@ -115,20 +97,16 @@ describe('Merging partial state operations', () => {
|
|||
|
||||
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),
|
||||
|
@ -141,8 +119,6 @@ describe('Merging partial state operations', () => {
|
|||
|
||||
test('check resource status with all successful partial states', () => {
|
||||
const mergedState = mergePartialSetupStates(defaultSetupState, [
|
||||
createPackageState(true),
|
||||
createApmPolicyState(true),
|
||||
createCollectorPolicyState(true),
|
||||
createSymbolizerPolicyState(true),
|
||||
createPermissionState(true),
|
||||
|
|
|
@ -16,16 +16,10 @@ export interface SetupState {
|
|||
data: {
|
||||
available: boolean;
|
||||
};
|
||||
packages: {
|
||||
installed: boolean;
|
||||
};
|
||||
permissions: {
|
||||
configured: boolean;
|
||||
};
|
||||
policies: {
|
||||
apm: {
|
||||
installed: boolean;
|
||||
};
|
||||
collector: {
|
||||
installed: boolean;
|
||||
};
|
||||
|
@ -55,16 +49,10 @@ export function createDefaultSetupState(): SetupState {
|
|||
data: {
|
||||
available: false,
|
||||
},
|
||||
packages: {
|
||||
installed: false,
|
||||
},
|
||||
permissions: {
|
||||
configured: false,
|
||||
},
|
||||
policies: {
|
||||
apm: {
|
||||
installed: false,
|
||||
},
|
||||
collector: {
|
||||
installed: false,
|
||||
},
|
||||
|
@ -88,9 +76,7 @@ export function areResourcesSetup(state: SetupState): boolean {
|
|||
return (
|
||||
state.resource_management.enabled &&
|
||||
state.resources.created &&
|
||||
state.packages.installed &&
|
||||
state.permissions.configured &&
|
||||
state.policies.apm.installed &&
|
||||
state.policies.collector.installed &&
|
||||
state.policies.symbolizer.installed &&
|
||||
state.settings.configured
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* 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 { installPackage, getInstallation } from '@kbn/fleet-plugin/server/services/epm/packages';
|
||||
import {
|
||||
fetchFindLatestPackageOrThrow,
|
||||
pkgToPkgKey,
|
||||
} from '@kbn/fleet-plugin/server/services/epm/registry';
|
||||
import { ProfilingSetupOptions } from './types';
|
||||
import { PartialSetupState } from '../../../common/setup';
|
||||
|
||||
export async function isApmPackageInstalled({
|
||||
soClient,
|
||||
}: ProfilingSetupOptions): Promise<PartialSetupState> {
|
||||
const installation = await getInstallation({
|
||||
pkgName: 'apm',
|
||||
savedObjectsClient: soClient,
|
||||
});
|
||||
return {
|
||||
packages: {
|
||||
installed: !!installation,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function installLatestApmPackage({
|
||||
client,
|
||||
soClient,
|
||||
spaceId,
|
||||
}: ProfilingSetupOptions) {
|
||||
const esClient = client.getEsClient();
|
||||
const { name, version } = await fetchFindLatestPackageOrThrow('apm');
|
||||
|
||||
await installPackage({
|
||||
installSource: 'registry',
|
||||
esClient,
|
||||
savedObjectsClient: soClient,
|
||||
pkgkey: pkgToPkgKey({ name, version }),
|
||||
spaceId,
|
||||
force: true,
|
||||
});
|
||||
}
|
|
@ -5,111 +5,13 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { merge } from 'lodash';
|
||||
import { ElasticsearchClient } from '@kbn/core/server';
|
||||
import { fetchFindLatestPackageOrThrow } from '@kbn/fleet-plugin/server/services/epm/registry';
|
||||
import { SavedObjectsClientContract } from '@kbn/core/server';
|
||||
import { PackagePolicyClient } from '@kbn/fleet-plugin/server';
|
||||
import { getApmPolicy } from './get_apm_policy';
|
||||
import { ProfilingSetupOptions } from './types';
|
||||
import { PartialSetupState } from '../../../common/setup';
|
||||
import { PackageInputType } from '../..';
|
||||
|
||||
async function createIngestAPIKey(esClient: ElasticsearchClient) {
|
||||
const apiKeyResponse = await esClient.security.createApiKey({
|
||||
name: 'profiling-manager',
|
||||
role_descriptors: {
|
||||
profiling_manager: {
|
||||
indices: [
|
||||
{
|
||||
names: ['profiling-*', '.profiling-*'],
|
||||
privileges: [
|
||||
'read',
|
||||
'create_doc',
|
||||
'create',
|
||||
'write',
|
||||
'index',
|
||||
'create_index',
|
||||
'view_index_metadata',
|
||||
'manage',
|
||||
],
|
||||
},
|
||||
],
|
||||
cluster: ['monitor'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return atob(apiKeyResponse.encoded);
|
||||
}
|
||||
|
||||
export async function validateApmPolicy({
|
||||
soClient,
|
||||
packagePolicyClient,
|
||||
}: ProfilingSetupOptions): Promise<PartialSetupState> {
|
||||
const apmPolicy = await getApmPolicy({ packagePolicyClient, soClient });
|
||||
return {
|
||||
policies: {
|
||||
apm: {
|
||||
installed: !!(apmPolicy && apmPolicy?.inputs[0].config?.['apm-server'].value?.profiling),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function updateApmPolicy({
|
||||
client,
|
||||
soClient,
|
||||
packagePolicyClient,
|
||||
}: ProfilingSetupOptions) {
|
||||
const esClient = client.getEsClient();
|
||||
const apmPolicy = await getApmPolicy({ packagePolicyClient, soClient });
|
||||
|
||||
if (!apmPolicy) {
|
||||
throw new Error(`Could not find APM policy`);
|
||||
}
|
||||
|
||||
const apmPolicyApiKey = await createIngestAPIKey(esClient);
|
||||
|
||||
const profilingApmConfig = {
|
||||
profiling: {
|
||||
enabled: true,
|
||||
elasticsearch: {
|
||||
api_key: apmPolicyApiKey,
|
||||
},
|
||||
metrics: {
|
||||
elasticsearch: {
|
||||
hosts: ['https://1b6c02856ea642a6ac14499b01507233.us-east-2.aws.elastic-cloud.com:443'],
|
||||
api_key: 'woq-IoMBRbbiEbPugtWW:_iBmc1PdSout7sf5FCkEpA',
|
||||
},
|
||||
},
|
||||
keyvalue_retention: {
|
||||
// 60 days
|
||||
age: '1440h',
|
||||
// 200 Gib
|
||||
size_bytes: 200 * 1024 * 1024 * 1024,
|
||||
execution_interval: '12h',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const {
|
||||
id,
|
||||
revision,
|
||||
updated_at: updateAt,
|
||||
updated_by: updateBy,
|
||||
...apmPolicyModified
|
||||
} = apmPolicy;
|
||||
|
||||
apmPolicyModified.inputs = apmPolicy.inputs.map((input) => {
|
||||
return input.type === 'apm'
|
||||
? merge({}, input, { config: { 'apm-server': { value: profilingApmConfig } } })
|
||||
: input;
|
||||
});
|
||||
|
||||
await packagePolicyClient.update(soClient, esClient, id, apmPolicyModified);
|
||||
}
|
||||
|
||||
const CLOUD_AGENT_POLICY_ID = 'policy-elastic-agent-on-cloud';
|
||||
const COLLECTOR_PACKAGE_POLICY_NAME = 'elastic-universal-profiling-collector';
|
||||
const SYMBOLIZER_PACKAGE_POLICY_NAME = 'elastic-universal-profiling-symbolizer';
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* 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 { SavedObjectsClientContract } from '@kbn/core/server';
|
||||
import { PackagePolicyClient } from '@kbn/fleet-plugin/server';
|
||||
|
||||
export const ELASTIC_CLOUD_APM_POLICY = 'elastic-cloud-apm';
|
||||
|
||||
export async function getApmPolicy({
|
||||
packagePolicyClient,
|
||||
soClient,
|
||||
}: {
|
||||
packagePolicyClient: PackagePolicyClient;
|
||||
soClient: SavedObjectsClientContract;
|
||||
}) {
|
||||
return packagePolicyClient.get(soClient, ELASTIC_CLOUD_APM_POLICY);
|
||||
}
|
|
@ -8,7 +8,6 @@
|
|||
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
|
||||
import { RouteRegisterParameters } from '.';
|
||||
import { getClient } from './compat';
|
||||
import { installLatestApmPackage, isApmPackageInstalled } from '../lib/setup/apm_package';
|
||||
import {
|
||||
enableResourceManagement,
|
||||
setMaximumBuckets,
|
||||
|
@ -18,8 +17,6 @@ import {
|
|||
import {
|
||||
createCollectorPackagePolicy,
|
||||
createSymbolizerPackagePolicy,
|
||||
updateApmPolicy,
|
||||
validateApmPolicy,
|
||||
validateCollectorPackagePolicy,
|
||||
validateSymbolizerPackagePolicy,
|
||||
} from '../lib/setup/fleet_policies';
|
||||
|
@ -103,8 +100,6 @@ export function registerSetupRoute({
|
|||
}
|
||||
|
||||
const verifyFunctions = [
|
||||
isApmPackageInstalled,
|
||||
validateApmPolicy,
|
||||
validateCollectorPackagePolicy,
|
||||
validateMaximumBuckets,
|
||||
validateResourceManagement,
|
||||
|
@ -173,8 +168,6 @@ export function registerSetupRoute({
|
|||
|
||||
const partialStates = await Promise.all(
|
||||
[
|
||||
isApmPackageInstalled,
|
||||
validateApmPolicy,
|
||||
validateCollectorPackagePolicy,
|
||||
validateMaximumBuckets,
|
||||
validateResourceManagement,
|
||||
|
@ -185,8 +178,6 @@ export function registerSetupRoute({
|
|||
const mergedState = mergePartialSetupStates(state, partialStates);
|
||||
|
||||
const executeFunctions = [
|
||||
...(mergedState.packages.installed ? [] : [installLatestApmPackage]),
|
||||
...(mergedState.policies.apm.installed ? [] : [updateApmPolicy]),
|
||||
...(mergedState.policies.collector.installed ? [] : [createCollectorPackagePolicy]),
|
||||
...(mergedState.policies.symbolizer.installed ? [] : [createSymbolizerPackagePolicy]),
|
||||
...(mergedState.resource_management.enabled ? [] : [enableResourceManagement]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue