kibana/scripts
Spencer afb09ccf8a
Transpile packages on demand, validate all TS projects (#146212)
## Dearest Reviewers 👋 

I've been working on this branch with @mistic and @tylersmalley and
we're really confident in these changes. Additionally, this changes code
in nearly every package in the repo so we don't plan to wait for reviews
to get in before merging this. If you'd like to have a concern
addressed, please feel free to leave a review, but assuming that nobody
raises a blocker in the next 24 hours we plan to merge this EOD pacific
tomorrow, 12/22.

We'll be paying close attention to any issues this causes after merging
and work on getting those fixed ASAP. 🚀

---

The operations team is not confident that we'll have the time to achieve
what we originally set out to accomplish by moving to Bazel with the
time and resources we have available. We have also bought ourselves some
headroom with improvements to babel-register, optimizer caching, and
typescript project structure.

In order to make sure we deliver packages as quickly as possible (many
teams really want them), with a usable and familiar developer
experience, this PR removes Bazel for building packages in favor of
using the same JIT transpilation we use for plugins.

Additionally, packages now use `kbn_references` (again, just copying the
dx from plugins to packages).

Because of the complex relationships between packages/plugins and in
order to prepare ourselves for automatic dependency detection tools we
plan to use in the future, this PR also introduces a "TS Project Linter"
which will validate that every tsconfig.json file meets a few
requirements:

1. the chain of base config files extended by each config includes
`tsconfig.base.json` and not `tsconfig.json`
1. the `include` config is used, and not `files`
2. the `exclude` config includes `target/**/*`
3. the `outDir` compiler option is specified as `target/types`
1. none of these compiler options are specified: `declaration`,
`declarationMap`, `emitDeclarationOnly`, `skipLibCheck`, `target`,
`paths`

4. all references to other packages/plugins use their pkg id, ie:
	
	```js
    // valid
    {
      "kbn_references": ["@kbn/core"]
    }
    // not valid
    {
      "kbn_references": [{ "path": "../../../src/core/tsconfig.json" }]
    }
    ```

5. only packages/plugins which are imported somewhere in the ts code are
listed in `kbn_references`

This linter is not only validating all of the tsconfig.json files, but
it also will fix these config files to deal with just about any
violation that can be produced. Just run `node scripts/ts_project_linter
--fix` locally to apply these fixes, or let CI take care of
automatically fixing things and pushing the changes to your PR.

> **Example:** [`64e93e5`
(#146212)](64e93e5806)
When I merged main into my PR it included a change which removed the
`@kbn/core-injected-metadata-browser` package. After resolving the
conflicts I missed a few tsconfig files which included references to the
now removed package. The TS Project Linter identified that these
references were removed from the code and pushed a change to the PR to
remove them from the tsconfig.json files.

## No bazel? Does that mean no packages??
Nope! We're still doing packages but we're pretty sure now that we won't
be using Bazel to accomplish the 'distributed caching' and 'change-based
tasks' portions of the packages project.

This PR actually makes packages much easier to work with and will be
followed up with the bundling benefits described by the original
packages RFC. Then we'll work on documentation and advocacy for using
packages for any and all new code.

We're pretty confident that implementing distributed caching and
change-based tasks will be necessary in the future, but because of
recent improvements in the repo we think we can live without them for
**at least** a year.

## Wait, there are still BUILD.bazel files in the repo
Yes, there are still three webpack bundles which are built by Bazel: the
`@kbn/ui-shared-deps-npm` DLL, `@kbn/ui-shared-deps-src` externals, and
the `@kbn/monaco` workers. These three webpack bundles are still created
during bootstrap and remotely cached using bazel. The next phase of this
project is to figure out how to get the package bundling features
described in the RFC with the current optimizer, and we expect these
bundles to go away then. Until then any package that is used in those
three bundles still needs to have a BUILD.bazel file so that they can be
referenced by the remaining webpack builds.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2022-12-22 19:00:29 -06:00
..
archive_migration_functions.sh [Archive Migrations] security_solution-timelines (#142363) 2022-11-04 10:06:25 +00:00
backport.js Bump backport to 8.5.0 (#133848) 2022-06-09 16:18:52 +01:00
build.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
build_api_docs.js Automatically generated Api documentation (#86232) 2021-02-24 19:23:19 -05:00
build_kibana_platform_plugins.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
build_plugin_list_docs.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
check_file_casing.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
check_ftr_configs.js [CI] Add a check to ensure all FTR configs are in the manifest (#132857) 2022-05-26 11:18:13 -04:00
check_jest_configs.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
check_licenses.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
chromium_version.js [Reporting/Build Chromium] Add a developer script to find the Chromium commit (#94033) 2021-03-10 10:57:29 -07:00
classify_source.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
dev_docs.sh [docs] Update yarn dev-docs config format (#137753) 2022-08-01 13:23:04 -07:00
docs.js [docs] rewrite docs cli to show logs and use modern apis (#117767) 2021-11-06 20:31:22 -05:00
download_pr_list.js Save github PR list in csv (#123276) 2022-01-20 20:28:09 +01:00
enabled_ftr_configs.js [Archive Migrations] Bash functions to facilitate es to kbn archive migrations (#135929) 2022-07-13 10:31:32 +01:00
es.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
es_archiver.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
eslint.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
eslint_with_types.js [eslint] enable type-specific lint rules (#114184) 2021-11-03 16:56:17 -06:00
extract_performance_testing_dataset.js [packages] add kbn-performance-testing-dataset-extractor (#131631) 2022-05-06 04:11:51 +02:00
find_babel_runtime_helpers_in_use.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
find_node_libs_browser_polyfills_in_use.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
find_plugins_ready_to_migrate_to_ts_refs.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
find_plugins_with_circular_deps.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
find_plugins_without_ts_refs.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
functional_test_runner.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
functional_tests.js [ftr] automatically determine config run order (#130983) 2022-05-04 17:05:58 -05:00
functional_tests_server.js [ftr] add first-class support for playwrite journeys (#140680) 2022-09-22 01:06:46 -07:00
generate.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
generate_plugin.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
generate_team_assignments.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
i18n_check.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
i18n_extract.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
i18n_integrate.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
ingest_coverage.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
jest.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
jest_integration.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn_archiver.js [kbn/test] add import/export support to KbnClient (#92526) 2021-02-25 16:13:27 -07:00
kibana.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
kibana_encryption_keys.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
kibana_keystore.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
kibana_plugin.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
kibana_setup.js Add interactive setup CLI (#114493) 2021-10-20 22:17:45 +01:00
kibana_verification_code.js Verification code CLI (#111707) 2021-09-14 21:58:25 +01:00
licenses_csv_report.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
makelogs.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
notice.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
plugin_helpers.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
precommit_hook.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
read_jest_help.mjs Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
README.md [ftr] automatically determine config run order (#130983) 2022-05-04 17:05:58 -05:00
register_git_hook.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
report_failed_tests.js [ftr] add first-class support for playwrite journeys (#140680) 2022-09-22 01:06:46 -07:00
report_performance_metrics.js ingest performance metrics to ci-stats (#134792) 2022-06-22 15:44:11 -07:00
run_performance.js Performance runner in js (#146129) 2022-11-29 19:43:35 +02:00
run_scalability.js [scalability testing] typescript runner (#147002) 2022-12-06 22:21:52 +01:00
saved_objs_info.js [QA][SO INFO SVC] Add cli (#108353) 2021-08-16 13:36:22 +01:00
ship_ci_stats.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
spec_to_console.js chore(NA): moving @kbn/spec-to-console into bazel (#103470) 2021-06-28 15:58:41 +01:00
storybook.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
stylelint.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
synthtrace.js [APM] Fix synthtrace cli script (#140219) 2022-09-07 12:52:50 -07:00
telemetry_check.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
telemetry_extract.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
test_hardening.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
ts_project_linter.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
type_check.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
update_prs.js Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00
update_vscode_config.js Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00

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 or packages 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 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 test/functional/config.base.js]

Starts just the Elasticsearch and Kibana servers given a single config, i.e. via --config 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 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.