## Summary This pull request introduces a new feature to group dependency usage by package directories, alongside existing options for grouping by owner or source. It includes updates to the CLI, dependency graph logic, and new utility functions and tests to support the feature. ### CLI updates: * Enhanced the `group-by` option in `configureYargs` to allow grouping by `package` in addition to `owner` and `source`. (`packages/kbn-dependency-usage/src/cli.ts`, [packages/kbn-dependency-usage/src/cli.tsL50-R51](diffhunk://#diff-ef89f6725b6dde85fbfea1050625607f583373da328165c575070f0579e5f23aL50-R51)) ### Dependency graph logic: * Added the `groupByPackage` function to group dependencies by package directories, and integrated it into the `identifyDependencyUsageWithCruiser` method. (`packages/kbn-dependency-usage/src/dependency_graph/providers/cruiser.ts`, [[1]](diffhunk://#diff-19e7d98370cc898df6e0a28a61575490b35a0ff6013a8c5080aa8c9fa0065e71R17) [[2]](diffhunk://#diff-19e7d98370cc898df6e0a28a61575490b35a0ff6013a8c5080aa8c9fa0065e71R120-R123) ### Utility functions: * Implemented `groupByPackage` utility to identify package directories based on the presence of `kibana.jsonc` files and group dependencies accordingly. (`packages/kbn-dependency-usage/src/lib/group_by_package.ts`, [packages/kbn-dependency-usage/src/lib/group_by_package.tsR1-R80](diffhunk://#diff-4e2be55a320215ee636cd352393c09c0e90524a5b6121b034d1360a6afed4d67R1-R80)) ### Unit tests: * Added comprehensive tests for `groupByPackage`, covering scenarios such as nested directories, missing package files, and handling of empty dependencies. (`packages/kbn-dependency-usage/src/lib/group_by_package.test.ts`, [packages/kbn-dependency-usage/src/lib/group_by_package.test.tsR1-R231](diffhunk://#diff-69398d48b1e5a2ea0ed52ca35fc2d877e143a6dcefd71d2399931ba242b962b5R1-R231)) ### Example usage ```sh (base) ➜ kibana git:(dep-usage/group-by-package) ✗ ./scripts/dependency_usage.sh -c 20 -g package -p x-pack/solutions/security Searching for dependencies in paths: x-pack/solutions/security Dependencies will be collapsed to depth: 20 cruiser is used for building dependency graph Successfully built dependency graph using cruiser. Analyzing... No output file specified, displaying results below: { "x-pack/solutions/security/packages/connectors": [ "minimatch", "@elastic/eui", "@emotion/react", "@testing-library/react", "react", "lodash" ], "x-pack/solutions/security/packages/data-stream-adapter": [ "lodash" ], "x-pack/solutions/security/packages/data-table": [ "io-ts", "enzyme", "lodash", "react", "@elastic/eui", "@hello-pangea/dnd", "@tanstack/react-query", "react-redux", "redux", "styled-components", "@testing-library/react", "memoize-one", "typescript-fsa", "typescript-fsa-reducers", "reselect" ], "x-pack/solutions/security/packages/distribution-bar": [ "@elastic/eui", "react", "@testing-library/react", "@elastic/numeral", "@emotion/react" ], "x-pack/solutions/security/packages/ecs-data-quality-dashboard": [ "minimatch", "react", "@testing-library/react", "@testing-library/user-event", "@elastic/eui", "@emotion/react", "@elastic/ecs", "@elastic/numeral", "lodash", "@emotion/styled", "moment-timezone", "moment", "@elastic/charts", "uuid", "@tanstack/react-query", "rxjs", "@testing-library/jest-dom" ], "x-pack/solutions/security/packages/expandable-flyout": [ "@testing-library/react", "react", "@elastic/eui", "@emotion/react", "lodash", "@testing-library/user-event", "@emotion/css", "react-router-dom", "rxjs", "react-redux", "@reduxjs/toolkit", "react-fast-compare", "reselect" ], "x-pack/solutions/security/packages/features": [ "minimatch" ], "x-pack/solutions/security/packages/index-adapter": [ "@elastic/elasticsearch", "lodash", "@elastic/ecs", "rxjs" ], "x-pack/solutions/security/packages/kbn-cloud-security-posture/graph": [ "babel-jest", "@emotion/react", "react", "@storybook/addon-actions", "rxjs", "@tanstack/react-query", "webpack-merge", "@storybook/manager-api", "@storybook/theming", "@testing-library/jest-dom", "@elastic/eui", "@testing-library/react", "react-use", "@xyflow/react", "lodash", "@emotion/styled", "polished", "@storybook/react", "@testing-library/user-event", "expect", "@dagrejs/dagre" ], "x-pack/solutions/security/packages/kbn-cloud-security-posture/public": [ "@elastic/eui", "@emotion/react", "react", "react-dom", "@testing-library/react", "@tanstack/react-query", "rxjs", "react-router-dom" ], "x-pack/solutions/security/packages/kbn-securitysolution-autocomplete": [ "@testing-library/jest-dom", "@testing-library/react", "react", "@elastic/eui", "enzyme", "lodash", "moment" ], "x-pack/solutions/security/packages/kbn-securitysolution-exception-list-components": [ "@testing-library/jest-dom", "@testing-library/react", "react", "@elastic/eui", "@emotion/react", "@emotion/css", "@emotion/styled" ], "x-pack/solutions/security/packages/kbn-securitysolution-hook-utils": [ "@testing-library/react", "react", "rxjs" ], "x-pack/solutions/security/packages/kbn-securitysolution-io-ts-alerting-types": [ "io-ts", "fp-ts", "uuid" ], "x-pack/solutions/security/packages/kbn-securitysolution-io-ts-list-types": [ "fp-ts", "io-ts" ], "x-pack/solutions/security/packages/kbn-securitysolution-list-api": [ "fp-ts" ], "x-pack/solutions/security/packages/kbn-securitysolution-list-hooks": [ "fp-ts", "react", "@tanstack/react-query", "@testing-library/react" ], "x-pack/solutions/security/packages/kbn-securitysolution-list-utils": [ "lodash", "uuid" ], "x-pack/solutions/security/packages/kbn-securitysolution-t-grid": [ "lodash" ], "x-pack/solutions/security/packages/kbn-securitysolution-utils": [ "uuid", "axios", "p-limit" ], "x-pack/solutions/security/packages/navigation": [ "minimatch", "react", "@elastic/eui", "@emotion/react", "@testing-library/react" ], "x-pack/solutions/security/packages/side-nav": [ "minimatch", "@elastic/eui", "@emotion/react", "react", "@emotion/css", "@testing-library/react", "classnames", "@testing-library/user-event", "lodash" ], "x-pack/solutions/security/packages/storybook/config": [ "@storybook/addon-actions", "@storybook/manager-api", "@storybook/theming", "jest-mock" ], "x-pack/solutions/security/packages/upselling": [ "minimatch", "@elastic/eui", "react", "@testing-library/react", "@emotion/react", "@emotion/styled", "rxjs" ], "x-pack/solutions/security/plugins/cloud_security_posture": [ "react", "@testing-library/react", "history", "@tanstack/react-query", "react-router-dom", "@elastic/eui", "@emotion/react", "lodash", "react-use", "chance", "@emotion/css", "uuid", "@testing-library/user-event", "semver", "@testing-library/jest-dom", "moment", "@elastic/charts", "msw", "rxjs", "io-ts", "@testing-library/dom", "@elastic/elasticsearch" ], "x-pack/solutions/security/plugins/ecs_data_quality_dashboard": [ "minimatch", "rxjs", "moment-timezone", "fp-ts", "io-ts" ], "x-pack/solutions/security/plugins/elastic_assistant": [ "@elastic/elasticsearch", "axios", "p-limit", "yargs", "@langchain/core", "langchain", "globby", "uuid", "lodash", "p-retry", "rxjs", "js-yaml", "langsmith", "@langchain/langgraph", "moment", "@elastic/ecs", "p-map", "@testing-library/react", "elastic-apm-node", "moment-timezone", "expect" ], "x-pack/solutions/security/plugins/lists": [ "moment", "react", "@elastic/eui", "enzyme", "styled-components", "@storybook/addon-actions", "@testing-library/react", "fast-deep-equal", "@tanstack/react-query", "uuid", "lodash", "io-ts", "fp-ts", "elastic-apm-node", "sinon", "@hapi/boom", "mustache", "p-retry" ], "x-pack/solutions/security/plugins/security_solution_ess": [ "react", "rxjs", "@testing-library/react", "@elastic/eui" ], "x-pack/solutions/security/plugins/security_solution_serverless": [ "react", "@elastic/eui", "@emotion/react", "@testing-library/react", "rxjs", "@emotion/styled", "chance", "lodash", "node-fetch" ], "x-pack/solutions/security/plugins/security_solution": [ "lodash", "io-ts", "fp-ts", "seedrandom", "uuid", "semver", "moment", "axios", "ipaddr.js", "rxjs", "@emotion/react", "@elastic/eui", "react", "copy-to-clipboard", "@testing-library/react", "react-router-dom", "react-redux", "react-use", "react-reverse-portal", "styled-components", "react-dom", "@elastic/charts", "@testing-library/user-event", "@tanstack/react-query", "@testing-library/dom", "@emotion/css", "@testing-library/jest-dom", "remark-parse-no-trim", "unified", "@emotion/styled", "react-router-dom-v5-compat", "d3", "minimatch", "enzyme", "deepmerge", "fast-deep-equal", "@emotion/jest", "@elastic/numeral", "polished", "@hello-pangea/dnd", "use-resize-observer", "jest-styled-components", "moment-timezone", "classnames", "react-hook-form", "query-string", "fetch-mock", "@storybook/addon-actions", "react-markdown", "reselect", "redux", "mustache", "memoize-one", "history", "react-router", "typescript-fsa", "typescript-fsa-reducers", "@reduxjs/toolkit", "immer", "reduce-reducers", "redux-devtools-extension", "redux-thunk", "@formatjs/intl-utils", "react-diff-view", "unidiff", "diff", "json-stable-stringify", "sinon", "dedent", "object-hash", "papaparse", "d3-scale", "i18n-iso-countries", "@elastic/ecs", "@cypress/grep", "cypress-data-session", "cypress-recurse", "execa", "p-retry", "@cypress/debugging-proxy", "p-map", "pretty-ms", "@elastic/apm-rum", "ts-easing", "rbush", "suricata-sid-db", "react-window", "formik", "extract-zip", "js-yaml", "tar", "chalk", "@hapi/hapi", "node-fetch", "strip-ansi", "inquirer", "@elastic/elasticsearch", "yargs", "minimist", "del", "globby", "xml2js", "@langchain/core", "cypress", "find-cypress-specs", "cli-table3", "@babel/generator", "@babel/parser", "@langchain/langgraph", "langchain", "node-diff3", "snakecase-keys", "@hapi/boom", "elastic-apm-node", "set-value", "murmurhash", "js-sha256", "fastest-levenshtein", "langsmith", "adm-zip", "camelcase-keys" ], "x-pack/solutions/security/plugins/session_view": [ "react", "@elastic/eui", "@emotion/react", "@testing-library/user-event", "@testing-library/react", "lodash", "uuid", "memoize-one", "@tanstack/react-query", "byte-size", "react-use", "xterm", "use-resize-observer", "strip-ansi", "history" ], "x-pack/solutions/security/test": [ "moment", "chance", "lodash", "expect", "fast-deep-equal", "@mswjs/http-middleware", "msw", "uuid" ] } ``` --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> |
||
---|---|---|
.. | ||
codeql | ||
archive_migration_functions.sh | ||
backport.js | ||
build.js | ||
build_api_docs.js | ||
build_kibana_platform_plugins.js | ||
build_plugin_list_docs.js | ||
build_product_doc_artifacts.js | ||
capture_oas_snapshot.js | ||
check_file_casing.js | ||
check_ftr_code_owners.js | ||
check_ftr_configs.js | ||
check_jest_configs.js | ||
check_licenses.js | ||
check_mappings_update.js | ||
check_prod_native_modules.js | ||
chromium_version.js | ||
classify_source.js | ||
create_observability_rules.js | ||
delete_kibana_indices.sh | ||
dependency_ownership.js | ||
dependency_usage.sh | ||
dev_docs.sh | ||
docs.js | ||
download_pr_list.js | ||
eis.js | ||
enabled_ftr_configs.js | ||
es.js | ||
es_archiver.js | ||
eslint.js | ||
eslint_with_types.js | ||
extract_performance_testing_dataset.js | ||
find_babel_runtime_helpers_in_use.js | ||
find_node_libs_browser_polyfills_in_use.js | ||
functional_test_runner.js | ||
functional_tests.js | ||
functional_tests_server.js | ||
generate.js | ||
generate_console_definitions.js | ||
generate_openapi.js | ||
generate_plugin.js | ||
generate_team_assignments.js | ||
get_owners_for_file.js | ||
i18n_check.js | ||
i18n_extract.js | ||
i18n_integrate.js | ||
ingest_coverage.js | ||
jest.js | ||
jest_integration.js | ||
kbn.js | ||
kbn_archiver.js | ||
kibana.js | ||
kibana_encryption_keys.js | ||
kibana_keystore.js | ||
kibana_plugin.js | ||
kibana_setup.js | ||
kibana_verification_code.js | ||
langfuse.js | ||
licenses_csv_report.js | ||
lint_packages.js | ||
lint_ts_projects.js | ||
makelogs.js | ||
manifest.js | ||
notice.js | ||
phoenix.js | ||
plugin_check.js | ||
plugin_helpers.js | ||
precommit_hook.js | ||
prettier_topology_check.js | ||
profile.js | ||
quick_checks.js | ||
read_jest_help.mjs | ||
README.md | ||
register_git_hook.js | ||
relocate.js | ||
report_failed_tests.js | ||
report_performance_metrics.js | ||
rewrite_buildkite_definitions.js | ||
run_performance.js | ||
run_scalability.js | ||
saved_objs_info.js | ||
scout.js | ||
ship_ci_stats.js | ||
snapshot_plugin_types.js | ||
stage_by_owner.js | ||
storybook.js | ||
styled_components_mapping.js | ||
stylelint.js | ||
synthtrace.js | ||
telemetry_check.js | ||
telemetry_extract.js | ||
test_hardening.js | ||
type_check.js | ||
update_prs.js | ||
update_vscode_config.js | ||
validate_next_docs.js | ||
whereis_pkg.js | ||
yarn_deduplicate.js |
Kibana Dev Scripts
This directory contains scripts useful for interacting with Kibana tools in development. Use the node executable and --help
flag to learn about how they work:
node scripts/{{script name}} --help
For Developers
This directory is excluded from the build and tools within it should help users discover their capabilities. Each script in this directory must:
- require
src/setup_node_env
to bootstrap NodeJS environment - call out to source code in the
src
orpackages
directories - react to the
--help
flag - run everywhere OR check and fail fast when a required OS or toolchain is not available
Functional Test Scripts
node scripts/functional_tests [--config src/platform/test/functional/config.base.js --config test/api_integration/config.js]
Runs all the functional tests: selenium tests and api integration tests. List configs with multiple --config
arguments. Uses the @kbn/test library to run Elasticsearch and Kibana servers and tests against those servers, for multiple server+test setups. In particular, calls out to runTests()
. Can be run on a single config.
node scripts/functional_tests_server [--config src/platform/test/functional/config.base.js]
Starts just the Elasticsearch and Kibana servers given a single config, i.e. via --config src/platform/test/functional/config.base.js
or --config test/api_integration/config
. Allows the user to start just the servers with this script, and keep them running while running tests against these servers. The idea is that the same config file configures both Elasticsearch and Kibana servers. Uses the startServers()
method from @kbn/test library.
Example. Start servers and run tests, separately, but using the same config:
# Just the servers
node scripts/functional_tests_server --config path/to/config
In another terminal:
# Just the tests--against the running servers
node scripts/functional_test_runner --config path/to/config
For details on how the internal methods work, read this readme.
ES archiver
Loading data
If you wish to load up specific es archived data for your test, you can do so via:
node scripts/es_archiver.js load <archive> [--es-url=http://username:password@localhost:9200] [--kibana-url=http://username:password@localhost:5601/{basepath?}]
That will load the specified archive located in the archive directory specified by the default functional config file, located in src/platform/test/functional/config.base.js
. To load archives from other function config files you can pass --config path/to/config.js
.
Note: The --es-url
and --kibana-url
options may or may not be neccessary depending on your current Kibana configuration settings, and their values
may also change based on those settings (for example if you are not running with security you will not need the username:password
portion).
Saving data
You can save existing data into an archive by using the save
command:
node scripts/es_archiver.js save <archive name for kibana data> [space separated list of index patterns to include]
You may want to store the .kibana index separate from data. Since adding a lot of data will bloat our repo size, we have many tests that reuse the same
data indices but use their own .kibana
index.