Skip to content

Commit

Permalink
Merge branch 'master' into ml-licence-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jul 12, 2021
2 parents a5de770 + 832d349 commit 3a982c1
Show file tree
Hide file tree
Showing 101 changed files with 681 additions and 2,167 deletions.
61 changes: 61 additions & 0 deletions dev_docs/tutorials/debugging.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
id: kibDevTutorialDebugging
slug: /kibana-dev-docs/tutorial/debugging
title: Debugging in development
summary: Learn how to debug Kibana while running from source
date: 2021-04-26
tags: ['kibana', 'onboarding', 'dev', 'tutorials', 'debugging']
---

There are multiple ways to go about debugging Kibana when running from source.

## Debugging using Chrome DevTools

You will need to run Node using `--inspect` or `--inspect-brk` in order to enable the inspector. Additional information can be found in the [Node.js docs](https://nodejs.org/en/docs/guides/debugging-getting-started/).

Once Node is running with the inspector enabled, you can open `chrome://inspect` in your Chrome browser. You should see a remote target for the inspector running. Click "inspect". You can now begin using the debugger.

Next we will go over how to exactly enable the inspector for different aspects of the codebase.

### Jest Unit Tests

You will need to run Jest directly from the Node script:

`node --inspect-brk scripts/jest [TestPathPattern]`

### Functional Test Runner

`node --inspect-brk scripts/functional_test_runner`

### Development Server

`node --inspect-brk scripts/kibana`

## Debugging using logging

When running Kibana, it's sometimes helpful to enable verbose logging.

`yarn start --verbose`

Using verbose logging usually results in much more information than you're interested in. The [logging documentation](https://www.elastic.co/guide/en/kibana/current/logging-settings.html) covers ways to change the log level of certain types.

In the following example of a configuration stored in `config/kibana.dev.yml` we are logging all Elasticsearch queries and any logs created by the Management plugin.

```
logging:
appenders:
console:
type: console
layout:
type: pattern
highlight: true
root:
appenders: [default, console]
level: info
loggers:
- name: plugins.management
level: debug
- name: elasticsearch.query
level: debug
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { setScopedHistory, setServices, setDocViewsRegistry } from '../../../../
import { coreMock } from '../../../../../../../core/public/mocks';
import { dataPluginMock } from '../../../../../../data/public/mocks';
import { navigationPluginMock } from '../../../../../../navigation/public/mocks';
import { initAngularBootstrap } from '../../../../../../kibana_legacy/public/angular_bootstrap';
import { getInnerAngularModule } from '../../get_inner_angular';
import { createBrowserHistory } from 'history';

Expand All @@ -41,6 +42,9 @@ describe('Doc Table', () => {
// Stub out a minimal mapping of 4 fields
let mapping;

beforeAll(async () => {
await initAngularBootstrap();
});
beforeAll(() => setScopedHistory(createBrowserHistory()));
beforeEach(() => {
angular.element.prototype.slice = jest.fn(function (index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import hits from '../../../__fixtures__/real_hits';
import { coreMock } from '../../../../../../core/public/mocks';
import { dataPluginMock } from '../../../../../data/public/mocks';
import { navigationPluginMock } from '../../../../../navigation/public/mocks';
import { initAngularBootstrap } from '../../../../../kibana_legacy/public/angular_bootstrap';
import { setScopedHistory, setServices } from '../../../kibana_services';
import { getInnerAngularModule } from '../get_inner_angular';

Expand Down Expand Up @@ -54,6 +55,9 @@ describe('docTable', () => {
const core = coreMock.createStart();
let $elem;

beforeAll(async () => {
await initAngularBootstrap();
});
beforeAll(() => setScopedHistory(createBrowserHistory()));
beforeEach(() => {
angular.element.prototype.slice = jest.fn(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ import { createDocViewerDirective } from './doc_viewer';
import { createDiscoverGridDirective } from './create_discover_grid_directive';
import { createRenderCompleteDirective } from './directives/render_complete';
import {
initAngularBootstrap,
configureAppAngularModule,
PrivateProvider,
PromiseServiceCreator,
registerListenEventListener,
watchMultiDecorator,
} from '../../../../kibana_legacy/public';
import { PromiseServiceCreator } from './helpers';
import { DiscoverStartPlugins } from '../../plugin';
import { getScopedHistory } from '../../kibana_services';
import { createDiscoverDirective } from './create_discover_directive';
Expand All @@ -54,7 +53,6 @@ export function getInnerAngularModule(
deps: DiscoverStartPlugins,
context: PluginInitializerContext
) {
initAngularBootstrap();
const module = initializeInnerAngularModule(name, core, deps.navigation, deps.data);
configureAppAngularModule(module, { core, env: context.env }, true, getScopedHistory);
return module;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

export { formatRow, formatTopLevelObject } from './row_formatter';
export { handleSourceColumnState } from './state_helpers';
export { PromiseServiceCreator } from './promises';
2 changes: 2 additions & 0 deletions src/plugins/discover/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export class DiscoverPlugin
}
// this is used by application mount and tests
const { getInnerAngularModule } = await import('./application/angular/get_inner_angular');
await plugins.kibanaLegacy.loadAngularBootstrap();
const module = getInnerAngularModule(
innerAngularName,
core,
Expand Down Expand Up @@ -473,6 +474,7 @@ export class DiscoverPlugin
throw Error('Discover plugin getEmbeddableInjector: initializeServices is undefined');
}
const { core, plugins } = await this.initializeServices();
await getServices().kibanaLegacy.loadAngularBootstrap();
getServices().kibanaLegacy.loadFontAwesome();
const { getInnerAngularModuleEmbeddable } = await import(
'./application/angular/get_inner_angular'
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/kibana_legacy/public/angular/angular_config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ILocationProvider,
IModule,
IRootScopeService,
IRequestConfig,
} from 'angular';
import $ from 'jquery';
import { set } from '@elastic/safer-lodash-set';
Expand All @@ -22,7 +23,6 @@ import { ChromeBreadcrumb, EnvironmentMode, PackageInfo } from 'kibana/public';
import { History } from 'history';

import { CoreStart } from 'kibana/public';
import { isSystemApiRequest } from '../utils';
import { formatAngularHttpError, isAngularHttpError } from '../notify/lib';

export interface RouteConfiguration {
Expand All @@ -38,6 +38,11 @@ export interface RouteConfiguration {
requireUICapability?: string;
}

function isSystemApiRequest(request: IRequestConfig) {
const { headers } = request;
return headers && !!headers['kbn-system-request'];
}

/**
* Detects whether a given angular route is a dummy route that doesn't
* require any action. There are two ways this can happen:
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/kibana_legacy/public/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* Side Public License, v 1.
*/

// @ts-ignore
export { PromiseServiceCreator } from './promises';
// @ts-ignore
export { watchMultiDecorator } from './watch_multi';
export * from './angular_config';
Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana_legacy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const plugin = (initializerContext: PluginInitializerContext) =>

export * from './plugin';

export { initAngularBootstrap } from './angular_bootstrap';
export { PaginateDirectiveProvider, PaginateControlsDirectiveProvider } from './paginate/paginate';
export * from './angular';
export * from './notify';
Expand Down
1 change: 1 addition & 0 deletions src/plugins/kibana_legacy/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const createStartContract = (): Start => ({
getHideWriteControls: jest.fn(),
},
loadFontAwesome: jest.fn(),
loadAngularBootstrap: jest.fn(),
});

export const kibanaLegacyPluginMock = {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana_legacy/public/notify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
* Side Public License, v 1.
*/

export * from './toasts';
export * from './lib';
100 changes: 0 additions & 100 deletions src/plugins/kibana_legacy/public/notify/toasts/TOAST_NOTIFICATIONS.md

This file was deleted.

9 changes: 0 additions & 9 deletions src/plugins/kibana_legacy/public/notify/toasts/index.ts

This file was deleted.

This file was deleted.

Loading

0 comments on commit 3a982c1

Please sign in to comment.