docs(NA): adds @kbn/cli-dev-mode into ops devdocs (#133012)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Tiago Costa 2022-06-01 23:19:42 +01:00 committed by GitHub
parent d06c193915
commit 93204a9297
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 39 deletions

View file

@ -50,5 +50,6 @@ layout: landing
{ pageId: "kibDevDocsOpsAmbientUiTypes" },
{ pageId: "kibDevDocsOpsTestSubjSelector" },
{ pageId: "kibDevDocsOpsBazelRunner" },
{ pageId: "kibDevDocsOpsCliDevMode" }
]}
/>

View file

@ -205,7 +205,8 @@
{ "id": "kibDevDocsOpsAmbientStorybookTypes" },
{ "id": "kibDevDocsOpsAmbientUiTypes" },
{ "id": "kibDevDocsOpsTestSubjSelector" },
{ "id": "kibDevDocsOpsBazelRunner" }
{ "id": "kibDevDocsOpsBazelRunner" },
{ "id": "kibDevDocsOpsCliDevMode" }
]
}
]

View file

@ -21,7 +21,6 @@ filegroup(
NPM_MODULE_EXTRA_FILES = [
"package.json",
"README.md"
]
RUNTIME_DEPS = [

View file

@ -1,37 +0,0 @@
# `CliDevMode`
A class that manages the alternate behavior of the Kibana cli when using the `--dev` flag. This mode provides several useful features in a single CLI for a nice developer experience:
- automatic server restarts when code changes
- runs the `@kbn/optimizer` to build browser bundles
- runs a base path proxy which helps developers test that they are writing code which is compatible with custom basePath settings while they work
- pauses requests when the server or optimizer are not ready to handle requests so that when users load Kibana in the browser it's always using the code as it exists on disk
To accomplish this, and to make it easier to test, the `CliDevMode` class manages several objects:
## `Watcher`
The `Watcher` manages a [chokidar](https://github.com/paulmillr/chokidar) instance to watch the server files, logs about file changes observed and provides an observable to the `DevServer` via its `serverShouldRestart$()` method.
## `DevServer`
The `DevServer` object is responsible for everything related to running and restarting the Kibana server process:
- listens to restart notifications from the `Watcher` object, sending `SIGKILL` to the existing server and launching a new instance with the current code
- writes the stdout/stderr logs from the Kibana server to the parent process
- gracefully kills the process if the SIGINT signal is sent
- kills the server if the SIGTERM signal is sent, process.exit() is used, a second SIGINT is sent, or the gracefull shutdown times out
- proxies SIGHUP notifications to the child process, though the core team is working on migrating this functionality to the KP and making this unnecessary
## `Optimizer`
The `Optimizer` object manages a `@kbn/optimizer` instance, adapting its configuration and logging to the data available to the CLI.
## `BasePathProxyServer`
This proxy injects a random three character base path in the URL that Kibana is served from to help ensure that Kibana features
are written to adapt to custom base path configurations from users.
The basePathProxy also has another important job, ensuring that requests don't fail because the server is restarting and
that the browser receives front-end assets containing all saved changes. We accomplish this by observing the ready state of
the `Optimizer` and `DevServer` objects and pausing all requests through the proxy until both objects report that
they aren't building/restarting based on recently saved changes.

View file

@ -0,0 +1,57 @@
---
id: kibDevDocsOpsCliDevMode
slug: /kibana-dev-docs/ops/cli-dev-mode
title: "@kbn/cli-dev-mode"
description: A package to manage the Kibana cli behavior when in development
date: 2022-05-24
tags: ['kibana', 'dev', 'contributor', 'operations', 'cli', 'dev', 'mode']
---
This package exposes a function that manages the alternate behavior of the Kibana cli when using
the `--dev` flag. This mode provides several useful features in a single CLI for a nice developer
experience:
- automatic server restarts when code changes
- runs the `@kbn/optimizer` to build browser bundles
- runs a base path proxy which helps developers test that they are writing code which is
compatible with custom basePath settings while they work
- pauses requests when the server or optimizer are not ready to handle requests so that when
users load Kibana in the browser it's always using the code as it exists on disk
To accomplish this, and to make it easier to test, the `CliDevMode` class manages the following
objects.
## `Watcher`
The `Watcher` manages a [chokidar](https://github.com/paulmillr/chokidar) instance to watch the
server files, logs about file changes observed and provides an observable to the `DevServer` via
its `serverShouldRestart$()` method.
## `DevServer`
The `DevServer` object is responsible for everything related to running and restarting the Kibana
server process:
- listens to restart notifications from the `Watcher` object, sending `SIGKILL` to the existing
server and launching a new instance with the current code
- writes the stdout/stderr logs from the Kibana server to the parent process
- gracefully kills the process if the SIGINT signal is sent
- kills the server if the SIGTERM signal is sent, process.exit() is used, a second SIGINT is
sent, or the graceful shutdown times out
- proxies SIGHUP notifications to the child process, though the core team is working on
migrating this functionality to the KP and making this unnecessary
## `Optimizer`
The `Optimizer` object manages a `@kbn/optimizer` instance, adapting its configuration and
logging to the data available to the CLI.
## `BasePathProxyServer`
This proxy injects a random three character base path in the URL that Kibana is served from to
help ensure that Kibana features are written to adapt to custom base path configurations from users.
The basePathProxy also has another important job, ensuring that requests don't fail because the
server is restarting and that the browser receives front-end assets containing all saved
changes. We accomplish this by observing the ready state of the `Optimizer` and `DevServer`
objects and pausing all requests through the proxy until both objects report that they
aren't building/restarting based on recently saved changes.