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

SKA: Misc cleanup and enhancements #212207

Merged
merged 7 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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 .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ x-pack/solutions/observability/packages/kbn-investigation-shared @elastic/obs-ux
x-pack/solutions/observability/packages/kbn-scout-oblt @elastic/appex-qa
x-pack/solutions/observability/packages/observability-ai/observability-ai-common @elastic/obs-ai-assistant
x-pack/solutions/observability/packages/observability-ai/observability-ai-server @elastic/obs-ai-assistant
x-pack/solutions/observability/packages/synthetics_test_data @elastic/obs-ux-management-team
x-pack/solutions/observability/packages/synthetics-test-data @elastic/obs-ux-management-team
x-pack/solutions/observability/packages/utils-browser @elastic/observability-ui
x-pack/solutions/observability/packages/utils-common @elastic/observability-ui
x-pack/solutions/observability/packages/utils-server @elastic/observability-ui
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@
"@kbn/manifest": "link:packages/kbn-manifest",
"@kbn/mock-idp-plugin": "link:packages/kbn-mock-idp-plugin",
"@kbn/mock-idp-utils": "link:packages/kbn-mock-idp-utils",
"@kbn/observability-synthetics-test-data": "link:x-pack/solutions/observability/packages/synthetics_test_data",
"@kbn/observability-synthetics-test-data": "link:x-pack/solutions/observability/packages/synthetics-test-data",
"@kbn/openapi-bundler": "link:packages/kbn-openapi-bundler",
"@kbn/openapi-generator": "link:packages/kbn-openapi-generator",
"@kbn/optimizer": "link:packages/kbn-optimizer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const MANAGED_CONFIG_KEYS: ManagedConfigKey[] = [
{
key: 'search.exclude',
value: {
['**/packages/kbn-pm/dist/index.js']: true,
['**/api_docs']: true,
['**/tsconfig.tsbuildinfo']: true,
['**/*.map']: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/kbn-relocate/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export const listModules = async (listFlag: string, log: ToolingLog) => {
? module.directory
: join(BASE_FOLDER, module.directory);

if (module.isDevOnly()) {
devOnly.push(module);
} else if (
if (
directory.includes(`/${KIBANA_FOLDER}/test/`) ||
directory.includes(`/${KIBANA_FOLDER}/x-pack/test/`)
) {
Expand Down
90 changes: 46 additions & 44 deletions packages/kbn-relocate/relocate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
getManualCommits,
} from './utils/git';

const SKIP_RESET = false;

const moveModule = async (module: Package, log: ToolingLog) => {
const destination = calculateModuleTargetFolder(module);
log.info(`Moving ${module.directory} to ${destination}`);
Expand Down Expand Up @@ -107,8 +109,6 @@ const findModules = ({ teams, paths, included, excluded }: FindModulesParams, lo
// find modules selected by user filters
return (
sortBy(modules, ['directory'])
// exclude devOnly modules (they will remain in /packages)
.filter(({ manifest }) => !manifest.devOnly)
// explicit exclusions
.filter(({ id }) => !EXCLUDED_MODULES.includes(id) && !excluded.includes(id))
// we don't want to move test and example modules (just yet)
Expand Down Expand Up @@ -181,55 +181,57 @@ export const findAndRelocateModules = async (params: RelocateModulesParams, log:
return;
}

if (prNumber) {
pr = await findPr(prNumber);

if (getManualCommits(pr.commits).length > 0) {
const resOverride = await inquirer.prompt({
type: 'confirm',
name: 'overrideManualCommits',
message:
'Manual commits detected in the PR. The script will try to cherry-pick them, but it might require manual intervention to resolve conflicts. Continue?',
});
if (!resOverride.overrideManualCommits) {
log.info('Aborting');
return;
if (!SKIP_RESET) {
if (prNumber) {
pr = await findPr(prNumber);

if (getManualCommits(pr.commits).length > 0) {
const resOverride = await inquirer.prompt({
type: 'confirm',
name: 'overrideManualCommits',
message:
'Manual commits detected in the PR. The script will try to cherry-pick them, but it might require manual intervention to resolve conflicts. Continue?',
});
if (!resOverride.overrideManualCommits) {
log.info('Aborting');
return;
}
}
}
}

const resConfirmReset = await inquirer.prompt({
type: 'confirm',
name: 'confirmReset',
message: `The script will RESET CHANGES in this repository. Proceed?`,
});

if (!resConfirmReset.confirmReset) {
log.info('Aborting');
return;
}

// start with a clean repo
await safeExec(`git restore --staged .`);
await safeExec(`git restore .`);
await safeExec(`git clean -f -d`);
await safeExec(`git checkout ${baseBranch} && git pull ${upstream} ${baseBranch}`);
const resConfirmReset = await inquirer.prompt({
type: 'confirm',
name: 'confirmReset',
message: `The script will RESET CHANGES in this repository. Proceed?`,
});

if (pr) {
// checkout existing PR, reset all commits, rebase from baseBranch
try {
await checkoutResetPr(pr, baseBranch);
} catch (error) {
log.error(`Error checking out / resetting PR #${prNumber}:`);
log.error(error);
if (!resConfirmReset.confirmReset) {
log.info('Aborting');
return;
}
} else {
// checkout new branch
await checkoutBranch(NEW_BRANCH);
}

await safeExec(`yarn kbn bootstrap`);
// start with a clean repo
await safeExec(`git restore --staged .`);
await safeExec(`git restore .`);
await safeExec(`git clean -f -d`);
await safeExec(`git checkout ${baseBranch} && git pull ${upstream} ${baseBranch}`);

if (pr) {
// checkout existing PR, reset all commits, rebase from baseBranch
try {
await checkoutResetPr(pr, baseBranch);
} catch (error) {
log.error(`Error checking out / resetting PR #${prNumber}:`);
log.error(error);
return;
}
} else {
// checkout new branch
await checkoutBranch(NEW_BRANCH);
}

await safeExec(`yarn kbn bootstrap`);
}
await inquirer.prompt({
type: 'confirm',
name: 'readyRelocate',
Expand Down
29 changes: 26 additions & 3 deletions packages/kbn-relocate/utils/relocate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { basename, join } from 'path';
import type { ToolingLog } from '@kbn/tooling-log';
import { orderBy } from 'lodash';
import type { Package } from '../types';
import { applyTransforms } from './transforms';
import { HARDCODED_MODULE_PATHS, applyTransforms } from './transforms';
import {
BASE_FOLDER,
BASE_FOLDER_DEPTH,
Expand Down Expand Up @@ -42,7 +42,12 @@ export const calculateModuleTargetFolder = (module: Package): string => {
: join(BASE_FOLDER, module.directory);

let moduleDelimiter: string;
if (!fullPath.includes('/plugins/') && !fullPath.includes('/packages/')) {
if (HARDCODED_MODULE_PATHS[module.id]) {
return join(BASE_FOLDER, HARDCODED_MODULE_PATHS[module.id]);
} else if (module.isDevOnly()) {
// only packages can be devOnly
moduleDelimiter = '/packages/';
} else if (!fullPath.includes('/plugins/') && !fullPath.includes('/packages/')) {
throw new Error(
`The module ${module.id} is not located under a '*/plugins/*' or '*/packages/*' folder`
);
Expand All @@ -63,6 +68,15 @@ export const calculateModuleTargetFolder = (module: Package): string => {
chunks.shift(); // remove the base path up to '/packages/' or '/plugins/'
const moduleFolder = chunks.join(moduleDelimiter); // in case there's an extra /packages/ or /plugins/ folder

if (
module.isDevOnly() &&
(!module.group || module.group === 'common') &&
fullPath.includes(`/${KIBANA_FOLDER}/packages/`) &&
!fullPath.includes(`/${KIBANA_FOLDER}/packages/core/`)
) {
// relocate all dev modules under /packages to /src/dev/packages
return applyTransforms(module, join(BASE_FOLDER, 'src', 'dev', 'packages', moduleFolder));
}
let path: string;

if (group === 'platform') {
Expand All @@ -85,7 +99,7 @@ export const calculateModuleTargetFolder = (module: Package): string => {
moduleFolder
);
}
} else {
} else if (group === 'observability' || group === 'security' || group === 'search') {
path = join(
BASE_FOLDER,
'x-pack', // all solution modules are 'x-pack'
Expand All @@ -94,6 +108,8 @@ export const calculateModuleTargetFolder = (module: Package): string => {
isPlugin ? 'plugins' : 'packages',
moduleFolder
);
} else {
path = fullPath;
}

// after-creation transforms
Expand All @@ -113,6 +129,13 @@ export const replaceReferences = async (module: Package, destination: string, lo
const relativeSource = source.replace(BASE_FOLDER, '');
const relativeDestination = destination.replace(BASE_FOLDER, '');

if (relativeSource.split('/').length === 1) {
log.warning(
`Cannot replace references of a 1-level relative path '${relativeSource}'. Skipping.`
);
return;
}

if (
(relativeSource.startsWith('src') && relativeDestination.startsWith('src')) ||
(relativeSource.startsWith('x-pack') && relativeDestination.startsWith('x-pack'))
Expand Down
22 changes: 9 additions & 13 deletions packages/kbn-relocate/utils/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@

import type { Package } from '../types';

export const HARDCODED_MODULE_PATHS: Record<string, string> = {
'@kbn/apm-ftr-e2e': 'x-pack/solutions/observability/plugins/apm/ftr_e2e',
'@kbn/core-test-helpers-kbn-server': 'src/core/test-helpers/kbn-server',
'@kbn/core-test-helpers-model-versions': 'src/core/test-helpers/model-versions',
'@kbn/synthetics-e2e': 'x-pack/solutions/observability/plugins/synthetics/e2e',
'@kbn/test-suites-src': 'src/platform/test',
};

type TransformFunction = (param: string) => string;
const TRANSFORMS: Record<string, string | TransformFunction> = {
'x-pack/platform/packages/shared/observability/': 'x-pack/platform/packages/shared/',
'src/platform/packages/shared/chart_expressions/common':
'src/platform/packages/shared/chart-expressions-common',
'x-pack/solutions/search/packages/shared_ui': 'x-pack/solutions/search/packages/shared_ui',
'x-pack/solutions/security/packages/security-solution/': 'x-pack/solutions/security/packages/',
'x-pack/platform/plugins/shared/observability_ai_assistant':
'x-pack/platform/plugins/shared/observability_ai_assistant',
'x-pack/solutions/observability/plugins/observability_solution/':
'x-pack/solutions/observability/plugins/',
'x-pack/solutions/observability/packages/observability/observability_utils/observability_':
'x-pack/solutions/observability/packages/',
'x-pack/solutions/observability/packages/observability/':
'x-pack/solutions/observability/packages/',
'src/core/packages/core/': (path: string) => {
const relativePath = path.split('src/core/packages/')[1];
const relativeChunks = relativePath.split('/');
Expand All @@ -40,6 +35,7 @@ const TRANSFORMS: Record<string, string | TransformFunction> = {
}
},
};

export const applyTransforms = (module: Package, path: string): string => {
const transform = Object.entries(TRANSFORMS).find(([what]) => path.includes(what));
if (!transform) {
Expand Down
1 change: 0 additions & 1 deletion src/dev/precommit_hook/casing_check_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export const IGNORE_DIRECTORY_GLOBS = [
'src/babel-*',
'packages/*',
'x-pack/packages/ai-infra/*',
'packages/kbn-pm/src/utils/__fixtures__/*',
'packages/kbn-check-prod-native-modules-cli/integration_tests/__fixtures__/*/node_modules/*',
'x-pack/dev-tools',
'packages/kbn-optimizer/src/__fixtures__/mock_repo/x-pack',
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1360,8 +1360,8 @@
"@kbn/observability-plugin/*": ["x-pack/solutions/observability/plugins/observability/*"],
"@kbn/observability-shared-plugin": ["x-pack/solutions/observability/plugins/observability_shared"],
"@kbn/observability-shared-plugin/*": ["x-pack/solutions/observability/plugins/observability_shared/*"],
"@kbn/observability-synthetics-test-data": ["x-pack/solutions/observability/packages/synthetics_test_data"],
"@kbn/observability-synthetics-test-data/*": ["x-pack/solutions/observability/packages/synthetics_test_data/*"],
"@kbn/observability-synthetics-test-data": ["x-pack/solutions/observability/packages/synthetics-test-data"],
"@kbn/observability-synthetics-test-data/*": ["x-pack/solutions/observability/packages/synthetics-test-data/*"],
"@kbn/observability-utils-browser": ["x-pack/solutions/observability/packages/utils-browser"],
"@kbn/observability-utils-browser/*": ["x-pack/solutions/observability/packages/utils-browser/*"],
"@kbn/observability-utils-common": ["x-pack/solutions/observability/packages/utils-common"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
module.exports = {
preset: '@kbn/test',
rootDir: '../../../../..',
roots: ['<rootDir>/x-pack/solutions/observability/packages/synthetics_test_data'],
roots: ['<rootDir>/x-pack/solutions/observability/packages/synthetics-test-data'],
};
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6589,7 +6589,7 @@
version "0.0.0"
uid ""

"@kbn/observability-synthetics-test-data@link:x-pack/solutions/observability/packages/synthetics_test_data":
"@kbn/observability-synthetics-test-data@link:x-pack/solutions/observability/packages/synthetics-test-data":
version "0.0.0"
uid ""

Expand Down