zmoog / public-notes

Apache License 2.0
0 stars 1 forks source link

Figure out how start and debug Kibana from sources #59

Open zmoog opened 11 months ago

zmoog commented 11 months ago

I want to make a change in the Fleet plugin in Kibana.

I need to:

zmoog commented 11 months ago

Let's start with run Kibana locally on my machine.

zmoog commented 11 months ago

Install the dependencies

Prerequisites

What version of nodejs do I need?

$ cat .node-version
18.18.2

Installing nodejs18.18.2 using asdf:

$ asdf install nodejs 18.18.2
Trying to update node-build... ok
Downloading node-v18.18.2-darwin-arm64.tar.gz...
-> https://nodejs.org/dist/v18.18.2/node-v18.18.2-darwin-arm64.tar.gz

WARNING: node-v18.18.2-darwin-arm64 is in LTS Maintenance mode and nearing its end of life.
It only receives *critical* security updates, *critical* bug fixes and documentation updates.

Installing node-v18.18.2-darwin-arm64...
Installed node-v18.18.2-darwin-arm64 to /Users/zmoog/.asdf/installs/nodejs/18.18.2

Set up 18.18.2 as the local version for this project:

asdf local nodejs 18.18.2

Finally, check everything is working as expected:

$ node --version
v18.18.2
# install yarn
$ npm install -g yarn

yarn set version 1.22.19

# bootstrap Kibana and install the remaining dependencies
$ yarn kbn bootstrap
yarn run v1.22.19

$ node scripts/kbn bootstrap
info installing Bazel tools
success bazel tools installed
warn updated package map
warn updated tsconfig.json paths
[bazel] Extracting Bazel installation...
[bazel] Starting local Bazel server and connecting to it...
[bazel] INFO: Invocation ID: 29ca3f8b-c8fb-4b8e-890f-559f622f5d6c
[bazel] $ node ./preinstall_check
[bazel] [1/5] Validating package.json...
[bazel] [2/5] Resolving packages...
[bazel] warning Resolution field "@hello-pangea/dnd@16.2.0" is incompatible with requested version "@hello-pangea/dnd@^16.3.0"
[bazel] warning Resolution field "typescript@4.7.4" is incompatible with requested version "typescript@^3.3.3333"
[bazel] warning Resolution field "@types/node@18.18.5" is incompatible with requested version "@types/node@^10.1.0"
[bazel] warning Resolution field "@types/node@18.18.5" is incompatible with requested version "@types/node@^14.0.10 || ^16.0.0"
[bazel] warning Resolution field "trim@1.0.1" is incompatible with requested version "trim@0.0.1"
[bazel] warning Resolution field "@types/node@18.18.5" is incompatible with requested version "@types/node@^14.0.10 || ^16.0.0"
[bazel] warning Resolution field "@types/node@18.18.5" is incompatible with requested version "@types/node@^14.14.20 || ^16.0.0"
[bazel] warning Resolution field "typescript@4.7.4" is incompatible with requested version "typescript@^5.0.4"
[bazel] [3/5] Fetching packages...
[bazel] warning @elastic/synthetics@1.5.0: Invalid bin entry for "@elastic/synthetics" (in "@elastic/synthetics").
[bazel] [4/5] Linking dependencies...
[bazel] warning " > @elastic/apm-rum-react@2.0.1" has incorrect peer dependency "react-router-dom@>=6.0.0".
[bazel] warning " > @elastic/eui@89.1.0" has incorrect peer dependency "typescript@~4.5.3".
[bazel] warning " > @mapbox/mapbox-gl-rtl-text@0.2.3" has unmet peer dependency "mapbox-gl@>=0.32.1 <2.0.0".
[bazel] warning "@opentelemetry/exporter-metrics-otlp-grpc > @opentelemetry/core@1.8.0" has incorrect peer dependency "@opentelemetry/api@>=1.0.0 <1.4.0".
[bazel] warning "@opentelemetry/exporter-metrics-otlp-grpc > @opentelemetry/otlp-transformer@0.34.0" has incorrect peer dependency "@opentelemetry/api@>=1.3.0 <1.4.0".
[bazel] warning "@opentelemetry/exporter-metrics-otlp-grpc > @opentelemetry/resources@1.8.0" has incorrect peer dependency "@opentelemetry/api@>=1.0.0 <1.4.0".
[bazel] warning "@opentelemetry/exporter-metrics-otlp-grpc > @opentelemetry/sdk-metrics@1.8.0" has incorrect peer dependency "@opentelemetry/api@>=1.3.0 <1.4.0".
[bazel] warning "@opentelemetry/exporter-metrics-otlp-grpc > @opentelemetry/otlp-transformer > @opentelemetry/sdk-trace-base@1.8.0" has incorrect peer dependency "@opentelemetry/api@>=1.0.0 <1.4.0".
[bazel] warning "@opentelemetry/exporter-prometheus > @opentelemetry/core@1.5.0" has incorrect peer dependency "@opentelemetry/api@>=1.0.0 <1.2.0".
[bazel] warning "@opentelemetry/exporter-prometheus > @opentelemetry/sdk-metrics-base > @opentelemetry/resources@1.5.0" has incorrect peer dependency "@opentelemetry/api@>=1.0.0 <1.2.0".
[bazel] warning " > react-ace@7.0.5" has incorrect peer dependency "react@^0.13.0 || ^0.14.0 || ^15.0.1 || ^16.0.0".
[bazel] warning " > react-ace@7.0.5" has incorrect peer dependency "react-dom@^0.13.0 || ^0.14.0 || ^15.0.1 || ^16.0.0".
[bazel] warning " > react-intl@2.8.0" has incorrect peer dependency "react@^0.14.9 || ^15.0.0 || ^16.0.0".
[bazel] warning " > react-shortcuts@2.1.0" has incorrect peer dependency "react@^0.14.8 || ^15 || ^16".
[bazel] warning " > react-shortcuts@2.1.0" has incorrect peer dependency "react-dom@^0.14.8 || ^15 || ^16".
[bazel] warning " > recompose@0.30.0" has incorrect peer dependency "react@^0.14.0 || ^15.0.0 || ^16.0.0".
[bazel] warning " > @bazel/typescript@4.6.2" has incorrect peer dependency "typescript@>=3.0.0 <4.4.0".
[bazel] warning " > @elastic/eslint-plugin-eui@0.0.2" has incorrect peer dependency "eslint@>=5, <7".
[bazel] warning "@octokit/rest > @octokit/plugin-request-log@1.0.4" has unmet peer dependency "@octokit/core@>=3".
[bazel] warning "@storybook/addon-storyshots > preact-render-to-string@5.1.19" has unmet peer dependency "preact@>=10".
[bazel] warning " > @storybook/react@6.5.16" has unmet peer dependency "require-from-string@^2.0.2".
[bazel] warning Workspaces can only be enabled in private projects.
[bazel] [5/5] Building fresh packages...
[bazel] INFO: Analyzed 3 targets (775 packages loaded, 3249 targets configured).
[bazel] INFO: Found 3 targets...
[bazel] INFO: Elapsed time: 1223.412s, Critical Path: 17.10s
[bazel] INFO: 348 processes: 290 disk cache hit, 10 internal, 48 darwin-sandbox.
[bazel]
success shared bundles built
success yarn.lock analysis completed without any issues
success vscode config updated
✨  Done in 1235.68s. (20 mins)

Now Kibana is ready to run.

zmoog commented 11 months ago

Before kicking off Kibana, we need to start Elasticsearch.

Run Elasticsearch

The quickest way to run an Elasticsearch version that works with this version of Kibana, I can open another terminal an run:

yarn es snapshot --license trial

With --license trial we get all the features.

Run Kibana

yarn start

And the last step is open https://127.0.0.1:5601 and log in using elastic:changeme:

https://github.com/zmoog/public-notes/assets/25941/5d04674c-46cd-4542-b71b-4522b2b0e252

zmoog commented 11 months ago

Now I want to debug Kibana using vs code.

zmoog commented 11 months ago

Open the folder with the Kibana source code in vs code.

Add a launch configuration with this content:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Kibana Server",
            "port": 9230,
            "request": "attach",
            "restart": true,
            "skipFiles": [
                "<node_internals>/**"
            ],
            "type": "node"
        }
    ]
}

Start Kibana in debug mode:

yarn debug

On "Run and debug", click on "Kibana Server" to attach the vs code debugger to Kibana:

CleanShot 2023-10-30 at 15 45 09@2x

zmoog commented 11 months ago

I set a breakpoint in the _generateMappings() function, and here we are!

CleanShot 2023-10-30 at 15 54 37@2x