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

[Profiling] Manage indices via Elasticsearch #157949

Merged
merged 33 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9fd5fe9
Manage indices via Elasticsearch
jbcrail May 17, 2023
b314e81
Minor formatting
jbcrail May 26, 2023
0d48c4e
Remove unused code
jbcrail May 25, 2023
2c29c45
Initialize Elasticsearch before other steps
jbcrail May 26, 2023
603fff8
Inline cloud enabled check into setup endpoints
jbcrail May 26, 2023
2919e5e
Refactor how steps are checked
jbcrail May 26, 2023
c17f53b
Refactor how setup steps are executed
jbcrail May 26, 2023
526e24d
Fix check for valid APM policy
jbcrail May 26, 2023
4a60e58
Add interface for response body
jbcrail May 26, 2023
b7735a4
Remove mget interface from client
jbcrail May 26, 2023
84525be
Add profiling status endpoint to client
jbcrail May 26, 2023
396326b
Check profiling status
jbcrail May 26, 2023
d3f9a2c
Refactor how resources are setup and verified
jbcrail May 27, 2023
286604c
Check data existence and setup status at same time
jbcrail May 30, 2023
34aa563
Parallelize resource checks
jbcrail May 31, 2023
cff4196
Return error if cloud not enabled when setting up
jbcrail May 31, 2023
da4a8df
Remove check for existing data when setting up
jbcrail May 31, 2023
dbdabfb
Return early if resources are already created
jbcrail May 31, 2023
20fe917
Use accepted status code when setting up
jbcrail May 31, 2023
3bb6ad6
Enable resource management plugin in Elasticsearch
jbcrail May 31, 2023
bf21024
Rename method
jbcrail May 31, 2023
8cf55c7
Update fixtures
jbcrail May 31, 2023
e6ce7cc
Ensure Fleet setup is complete
jbcrail Jun 1, 2023
6e7ab59
Use stricter typing when modifying APM policy
jbcrail Jun 1, 2023
ee49062
Refactor type for setup state
jbcrail Jun 1, 2023
d28d518
Validate policies for collector and symbolizer
jbcrail Jun 1, 2023
a9a6b8c
Simplify how state is managed when checking status
jbcrail Jun 1, 2023
08c6746
Use type variable to simplify
jbcrail Jun 2, 2023
a2ba531
Remove useless async/await syntax
jbcrail Jun 2, 2023
9e4f020
Add comment
jbcrail Jun 2, 2023
6a3e6bc
Find latest package version when creating policy
jbcrail Jun 2, 2023
fb63bb6
Add explicit type
jbcrail Jun 2, 2023
43f4404
Support recursive partial SetupState
jbcrail Jun 2, 2023
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
108 changes: 108 additions & 0 deletions x-pack/plugins/profiling/common/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* 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 { RecursivePartial } from '@kbn/apm-plugin/typings/common';

export interface SetupState {
cloud: {
available: boolean;
required: boolean;
};
data: {
available: boolean;
};
packages: {
installed: boolean;
};
permissions: {
configured: boolean;
};
policies: {
apm: {
installed: boolean;
};
collector: {
installed: boolean;
};
symbolizer: {
installed: boolean;
};
};
resource_management: {
enabled: boolean;
};
resources: {
created: boolean;
};
settings: {
configured: boolean;
};
}

export type PartialSetupState = RecursivePartial<SetupState>;

export function createDefaultSetupState(): SetupState {
return {
cloud: {
available: false,
required: true,
},
data: {
available: false,
},
packages: {
installed: false,
},
permissions: {
configured: false,
},
policies: {
apm: {
installed: false,
},
collector: {
installed: false,
},
symbolizer: {
installed: false,
},
},
resource_management: {
enabled: false,
},
resources: {
created: false,
},
settings: {
configured: false,
},
};
}

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
);
}

function mergeRecursivePartial<T>(base: T, partial: RecursivePartial<T>): T {
return { ...base, ...partial };
}

export function mergePartialSetupStates(
base: SetupState,
partials: PartialSetupState[]
): SetupState {
return partials.reduce<SetupState>(mergeRecursivePartial, base);
}
12 changes: 12 additions & 0 deletions x-pack/plugins/profiling/common/stack_traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@

import { ProfilingESField } from './elasticsearch';

export interface ProfilingStatusResponse {
profiling: {
enabled: boolean;
};
resource_management: {
enabled: boolean;
};
resources: {
created: boolean;
};
}

interface ProfilingEvents {
[key: string]: number;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
{
"has_setup": true,
"has_data": false,
"steps": [
{
"name": "is_cloud",
"completed": false
},
{
"name": "apm_package",
"completed": false
},
{
"name": "cluster_settings",
"completed": false
},
{
"name": "ilm",
"completed": false
},
{
"name": "component_templates",
"completed": false
},
{
"name": "index_templates",
"completed": false
},
{
"name": "create_events_data_streams",
"completed": false
},
{
"name": "create_indices",
"completed": false
},
{
"name": "security",
"completed": false
},
{
"name": "fleet_policy",
"completed": false
}
]
}
"has_data": false
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
{
"has_setup": false,
"has_data": false,
"steps": [
{
"name": "is_cloud",
"completed": false
},
{
"name": "apm_package",
"completed": false
},
{
"name": "cluster_settings",
"completed": false
},
{
"name": "ilm",
"completed": false
},
{
"name": "component_templates",
"completed": false
},
{
"name": "index_templates",
"completed": false
},
{
"name": "create_events_data_streams",
"completed": false
},
{
"name": "create_indices",
"completed": false
},
{
"name": "security",
"completed": false
},
{
"name": "fleet_policy",
"completed": false
}
]
}
"has_data": false
}
3 changes: 3 additions & 0 deletions x-pack/plugins/profiling/e2e/cypress_test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export async function cypressTestRunner({
auth: `${username}:${password}`,
});

// Ensure Fleet setup is complete
await axios.post(`${kibanaUrlWithAuth}/api/fleet/setup`, {}, { headers: { 'kbn-xsrf': true } });

const profilingResources = await axios.get<{ has_setup: boolean; has_data: boolean }>(
`${kibanaUrlWithAuth}/api/profiling/v1/setup/es_resources`,
{ headers: { 'kbn-xsrf': true } }
Expand Down
46 changes: 46 additions & 0 deletions x-pack/plugins/profiling/server/lib/setup/apm_package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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,
});
}
61 changes: 61 additions & 0 deletions x-pack/plugins/profiling/server/lib/setup/cluster_settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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 { ProfilingSetupOptions } from './types';
import { PartialSetupState } from '../../../common/setup';

const MAX_BUCKETS = 150000;

export async function validateMaximumBuckets({
client,
}: ProfilingSetupOptions): Promise<PartialSetupState> {
const settings = await client.getEsClient().cluster.getSettings({});
const maxBuckets = settings.persistent.search?.max_buckets;
return {
settings: {
configured: maxBuckets === MAX_BUCKETS.toString(),
},
};
}

export async function setMaximumBuckets({ client }: ProfilingSetupOptions) {
await client.getEsClient().cluster.putSettings({
persistent: {
search: {
max_buckets: MAX_BUCKETS,
},
},
});
}

export async function validateResourceManagement({
client,
}: ProfilingSetupOptions): Promise<PartialSetupState> {
const statusResponse = await client.profilingStatus();
return {
resource_management: {
enabled: statusResponse.resource_management.enabled,
},
resources: {
created: statusResponse.resources.created,
},
};
}

export async function enableResourceManagement({ client }: ProfilingSetupOptions) {
await client.getEsClient().cluster.putSettings({
persistent: {
xpack: {
profiling: {
templates: {
enabled: true,
},
},
},
},
});
}
Loading