Skip to content

Commit

Permalink
[8.x] SKA: Misc cleanup and enhancements (#212207) (#212351)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [SKA: Misc cleanup and enhancements
(#212207)](#212207)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Gerard
Soldevila","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-02-24T13:31:00Z","message":"SKA:
Misc cleanup and enhancements (#212207)\n\n## Summary\n\n* Remove some
old paths pointing to `packages/kbn-pm` (no longer\nexists).\n* ~Fix
group and visibility for `@kbn/streams-app-wrapper-plugin`~.\n(done in
https://github.com/elastic/kibana/pull/212210)\n* Update
`scripts/relocate` logic with latest enhancements.\n* Convert
`@kbn/observability-synthetics-test-data` folder name to\ncamel-case
(messes up with pre-commit
hook).","sha":"a41badf96496c81587fca3d56c1c891abeb1a3a9","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","v9.0.0","backport:version","v8.18.0","v9.1.0","v8.19.0"],"title":"SKA:
Misc cleanup and
enhancements","number":212207,"url":"https://github.com/elastic/kibana/pull/212207","mergeCommit":{"message":"SKA:
Misc cleanup and enhancements (#212207)\n\n## Summary\n\n* Remove some
old paths pointing to `packages/kbn-pm` (no longer\nexists).\n* ~Fix
group and visibility for `@kbn/streams-app-wrapper-plugin`~.\n(done in
https://github.com/elastic/kibana/pull/212210)\n* Update
`scripts/relocate` logic with latest enhancements.\n* Convert
`@kbn/observability-synthetics-test-data` folder name to\ncamel-case
(messes up with pre-commit
hook).","sha":"a41badf96496c81587fca3d56c1c891abeb1a3a9"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/212207","number":212207,"mergeCommit":{"message":"SKA:
Misc cleanup and enhancements (#212207)\n\n## Summary\n\n* Remove some
old paths pointing to `packages/kbn-pm` (no longer\nexists).\n* ~Fix
group and visibility for `@kbn/streams-app-wrapper-plugin`~.\n(done in
https://github.com/elastic/kibana/pull/212210)\n* Update
`scripts/relocate` logic with latest enhancements.\n* Convert
`@kbn/observability-synthetics-test-data` folder name to\ncamel-case
(messes up with pre-commit
hook).","sha":"a41badf96496c81587fca3d56c1c891abeb1a3a9"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
  • Loading branch information
gsoldevila authored Feb 25, 2025
1 parent e3b2b50 commit 221205c
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ x-pack/solutions/observability/plugins/observability_logs_explorer @elastic/obs-
x-pack/solutions/observability/plugins/observability_onboarding @elastic/obs-ux-logs-team
x-pack/solutions/observability/plugins/observability @elastic/obs-ux-management-team
x-pack/solutions/observability/plugins/observability_shared @elastic/observability-ui
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 @@ -1476,7 +1476,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
3 changes: 1 addition & 2 deletions packages/kbn-relocate/healthcheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import fs from 'fs';
import path, { join } from 'path';
import { getPackages } from '@kbn/repo-packages';
import { REPO_ROOT } from '@kbn/repo-info';
import { EXCLUDED_FOLDERS, EXCLUDED_FOLDER_NAMES, EXTENSIONS } from './constants';
import { BASE_FOLDER } from './constants';
import { EXCLUDED_FOLDERS, EXCLUDED_FOLDER_NAMES, EXTENSIONS, BASE_FOLDER } from './constants';

const findPaths = (content: string): string[] => {
const regex = /([\.]{1,2}(\/[^\s)\]\['`#"]+)+)/g;
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 @@ -128,7 +128,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 @@ -1368,8 +1368,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 @@ -6590,7 +6590,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

0 comments on commit 221205c

Please sign in to comment.