Skip to content

Commit

Permalink
Merge branch 'master' into tests-sov2
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jun 1, 2021
2 parents 6e3675f + 77f0a2a commit 469a6af
Show file tree
Hide file tree
Showing 211 changed files with 4,300 additions and 1,647 deletions.
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"console": "src/plugins/console",
"core": "src/core",
"discover": "src/plugins/discover",
"bfetch": "src/plugins/bfetch",
"dashboard": "src/plugins/dashboard",
"data": "src/plugins/data",
"embeddableApi": "src/plugins/embeddable",
Expand Down
129 changes: 129 additions & 0 deletions dev_docs/tutorials/expressions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
id: kibDevTutorialExpressions
slug: /kibana-dev-docs/tutorials/expressions
title: Kibana Expressions Service
summary: Kibana Expressions Service
date: 2021-06-01
tags: ['kibana', 'onboarding', 'dev', 'architecture']
---

## Expressions service

Expression service exposes a registry of reusable functions primary used for fetching and transposing data and a registry of renderer functions that can render data into a DOM element.
Adding functions is easy and so is reusing them. An expression is a chain of functions with provided arguments, which given a single input translates to a single output.
Each expression is representable by a human friendly string which a user can type.

### creating expressions

Here is a very simple expression string:

essql 'select column1, column2 from myindex' | mapColumn name=column3 fn='{ column1 + 3 }' | table


It consists of 3 functions:

- essql which runs given sql query against elasticsearch and returns the results
- `mapColumn`, which computes a new column from existing ones;
- `table`, which prepares the data for rendering in a tabular format.

The same expression could also be constructed in the code:

```ts
import { buildExpression, buildExpressionFunction } from 'src/plugins/expressions';

const expression = buildExpression([
buildExpressionFunction<ExpressionFunctionEssql>('essql', [ q: 'select column1, column2 from myindex' ]),
buildExpressionFunction<ExpressionFunctionMapColumn>('mapColumn', [ name: 'column3', expression: 'column1 + 3' ]),
buildExpressionFunction<ExpressionFunctionTable>('table'),
]
```
Note: Consumers need to be aware which plugin registers specific functions with expressions function registry and import correct type definitions from there.
<DocCallOut title="Server Side Search">
The `expressions` service is available on both server and client, with similar APIs.
</DocCallOut>
### Running expressions
Expression service exposes `execute` method which allows you to execute an expression:
```ts
const executionContract = expressions.execute(expression, input);
const result = await executionContract.getData();
```
<DocCallOut title="Server Side Search">
Check the full spec of execute function [here](https://github.com/elastic/kibana/blob/master/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.execution.md)
</DocCallOut>
In addition, on the browser side, there are two additional ways to run expressions and render the results.
#### React expression renderer component
This is the easiest way to get expressions rendered inside your application.
```ts
<ReactExpressionRenderer expression={expression} />
```
<DocCallOut title="Server Side Search">
Check the full spec of ReactExpressionRenderer component props [here](https://github.com/elastic/kibana/blob/master/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.md)
</DocCallOut>
#### Expression loader
If you are not using React, you can use the loader expression service provides to achieve the same:
```ts
const handler = loader(domElement, expression, params);
```
<DocCallOut title="Server Side Search">
Check the full spec of expression loader params [here](https://github.com/elastic/kibana/blob/master/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iexpressionloaderparams.md)
</DocCallOut>
### Creating new expression functions
Creating a new expression function is easy, just call `registerFunction` method on expressions service setup contract with your function definition:
```ts
const functionDefinition = {
name: 'clog',
args: {},
help: 'Outputs the context to the console',
fn: (input: unknown) => {
// eslint-disable-next-line no-console
console.log(input);
return input;
},
};

expressions.registerFunction(functionDefinition);
```
<DocCallOut title="Server Side Search">
Check the full interface of ExpressionFuntionDefinition [here](https://github.com/elastic/kibana/blob/master/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionfunctiondefinition.md)
</DocCallOut>
### Creating new expression renderers
Adding new renderers is just as easy as adding functions:
```ts
const rendererDefinition = {
name: 'debug',
help: 'Outputs the context to the dom element',
render: (domElement, input, handlers) => {
// eslint-disable-next-line no-console
domElement.innerText = JSON.strinfigy(input);
handlers.done();
},
};

expressions.registerRenderer(rendererDefinition);
```
<DocCallOut title="Server Side Search">
Check the full interface of ExpressionRendererDefinition [here](https://github.com/elastic/kibana/blob/master/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionrenderdefinition.md)
</DocCallOut>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [DeprecationsDetails](./kibana-plugin-core-server.deprecationsdetails.md) &gt; [deprecationType](./kibana-plugin-core-server.deprecationsdetails.deprecationtype.md)

## DeprecationsDetails.deprecationType property

(optional) Used to identify between different deprecation types. Example use case: in Upgrade Assistant, we may want to allow the user to sort by deprecation type or show each type in a separate tab.

Feel free to add new types if necessary. Predefined types are necessary to reduce having similar definitions with different keywords across kibana deprecations.

<b>Signature:</b>

```typescript
deprecationType?: 'config' | 'feature';
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface DeprecationsDetails
| Property | Type | Description |
| --- | --- | --- |
| [correctiveActions](./kibana-plugin-core-server.deprecationsdetails.correctiveactions.md) | <code>{</code><br/><code> api?: {</code><br/><code> path: string;</code><br/><code> method: 'POST' &#124; 'PUT';</code><br/><code> body?: {</code><br/><code> [key: string]: any;</code><br/><code> };</code><br/><code> };</code><br/><code> manualSteps?: string[];</code><br/><code> }</code> | |
| [deprecationType](./kibana-plugin-core-server.deprecationsdetails.deprecationtype.md) | <code>'config' &#124; 'feature'</code> | (optional) Used to identify between different deprecation types. Example use case: in Upgrade Assistant, we may want to allow the user to sort by deprecation type or show each type in a separate tab.<!-- -->Feel free to add new types if necessary. Predefined types are necessary to reduce having similar definitions with different keywords across kibana deprecations. |
| [documentationUrl](./kibana-plugin-core-server.deprecationsdetails.documentationurl.md) | <code>string</code> | |
| [level](./kibana-plugin-core-server.deprecationsdetails.level.md) | <code>'warning' &#124; 'critical' &#124; 'fetch_error'</code> | levels: - warning: will not break deployment upon upgrade - critical: needs to be addressed before upgrade. - fetch\_error: Deprecations service failed to grab the deprecation details for the domain. |
| [message](./kibana-plugin-core-server.deprecationsdetails.message.md) | <code>string</code> | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## IndexPattern.addScriptedField() method

> Warning: This API is now obsolete.
>
>
Add scripted field to field list

<b>Signature:</b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## IndexPattern.getNonScriptedFields() method

> Warning: This API is now obsolete.
>
>
<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## IndexPattern.getScriptedFields() method

> Warning: This API is now obsolete.
>
>
<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## IndexPattern.removeScriptedField() method

> Warning: This API is now obsolete.
>
>
Remove scripted field from field list

<b>Signature:</b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## IndexPattern.addScriptedField() method

> Warning: This API is now obsolete.
>
>
Add scripted field to field list

<b>Signature:</b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## IndexPattern.getNonScriptedFields() method

> Warning: This API is now obsolete.
>
>
<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## IndexPattern.getScriptedFields() method

> Warning: This API is now obsolete.
>
>
<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## IndexPattern.removeScriptedField() method

> Warning: This API is now obsolete.
>
>
Remove scripted field from field list

<b>Signature:</b>
Expand Down
58 changes: 2 additions & 56 deletions docs/user/production-considerations/production.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* <<configuring-kibana-shield>>
* <<csp-strict-mode>>
* <<enabling-ssl>>
* <<load-balancing-es>>
* <<load-balancing-kibana>>
* <<accessing-load-balanced-kibana>>
* <<high-availability>>
Expand All @@ -22,9 +21,8 @@ Kibana instances that are all connected to the same Elasticsearch instance.

While Kibana isn't terribly resource intensive, we still recommend running Kibana
separate from your Elasticsearch data or master nodes. To distribute Kibana
traffic across the nodes in your Elasticsearch cluster, you can run Kibana
and an Elasticsearch client node on the same machine. For more information, see
<<load-balancing-es, Load balancing across multiple Elasticsearch nodes>>.
traffic across the nodes in your Elasticsearch cluster,
you can configure Kibana to use a list of Elasticsearch hosts.

[float]
[[configuring-kibana-shield]]
Expand Down Expand Up @@ -69,58 +67,6 @@ csp.strict: true

See <<configuring-tls>>.

[float]
[[load-balancing-es]]
=== Load Balancing across multiple {es} nodes
If you have multiple nodes in your Elasticsearch cluster, the easiest way to distribute Kibana requests
across the nodes is to run an Elasticsearch _Coordinating only_ node on the same machine as Kibana.
Elasticsearch Coordinating only nodes are essentially smart load balancers that are part of the cluster. They
process incoming HTTP requests, redirect operations to the other nodes in the cluster as needed, and
gather and return the results. For more information, see
{ref}/modules-node.html[Node] in the Elasticsearch reference.

To use a local client node to load balance Kibana requests:

. Install Elasticsearch on the same machine as Kibana.
. Configure the node as a Coordinating only node. In `elasticsearch.yml`, set `node.data`, `node.master` and `node.ingest` to `false`:
+
[source,js]
--------
# 3. You want this node to be neither master nor data node nor ingest node, but
# to act as a "search load balancer" (fetching data from nodes,
# aggregating results, etc.)
#
node.master: false
node.data: false
node.ingest: false
--------
. Configure the client node to join your Elasticsearch cluster. In `elasticsearch.yml`, set the `cluster.name` to the
name of your cluster.
+
[source,js]
--------
cluster.name: "my_cluster"
--------
. Check your transport and HTTP host configs in `elasticsearch.yml` under `network.host` and `transport.host`. The `transport.host` needs to be on the network reachable to the cluster members, the `network.host` is the network for the HTTP connection for Kibana (localhost:9200 by default).
+
[source,js]
--------
network.host: localhost
http.port: 9200
# by default transport.host refers to network.host
transport.host: <external ip>
transport.tcp.port: 9300 - 9400
--------
. Make sure Kibana is configured to point to your local client node. In `kibana.yml`, the `elasticsearch.hosts` setting should be set to
`["localhost:9200"]`.
+
[source,js]
--------
# The Elasticsearch instance to use for all your queries.
elasticsearch.hosts: ["http://localhost:9200"]
--------

[float]
[[load-balancing-kibana]]
=== Load balancing across multiple Kibana instances
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"**/prismjs": "1.23.0",
"**/react-syntax-highlighter": "^15.3.1",
"**/react-syntax-highlighter/**/highlight.js": "^10.4.1",
"**/refractor": "^3.3.1",
"**/request": "^2.88.2",
"**/trim": "1.0.1",
"**/typescript": "4.1.3",
Expand All @@ -102,7 +103,7 @@
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath/npm_module",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.4",
"@elastic/ems-client": "7.13.0",
"@elastic/eui": "32.1.0",
"@elastic/eui": "33.0.0",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "^9.0.1-kibana3",
"@elastic/maki": "6.3.0",
Expand Down Expand Up @@ -229,6 +230,7 @@
"expiry-js": "0.1.7",
"extract-zip": "^2.0.1",
"fast-deep-equal": "^3.1.1",
"fflate": "^0.6.9",
"file-saver": "^1.3.8",
"file-type": "^10.9.0",
"focus-trap-react": "^3.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-crypto/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/node-forge",
"@npm//@types/testing-library__jest-dom",
"@npm//resize-observer-polyfill"
]

DEPS = SRC_DEPS + TYPES_DEPS
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pageLoadAssetSize:
alerting: 106936
apm: 64385
apmOss: 18996
bfetch: 41874
bfetch: 51874
canvas: 1066647
charts: 195358
cloud: 21076
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-telemetry-tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/normalize-path",
"@npm//@types/testing-library__jest-dom",
"@npm//resize-observer-polyfill"
]

DEPS = SRC_DEPS + TYPES_DEPS
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-ui-shared-deps/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const Theme = require('./theme.ts');
export const Lodash = require('lodash');
export const LodashFp = require('lodash/fp');

export const Fflate = require('fflate/esm/browser');

// runtime deps which don't need to be copied across all bundles
export const TsLib = require('tslib');
export const KbnAnalytics = require('@kbn/analytics');
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ui-shared-deps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ exports.externals = {
'@elastic/eui/dist/eui_theme_dark.json': '__kbnSharedDeps__.Theme.euiDarkVars',
lodash: '__kbnSharedDeps__.Lodash',
'lodash/fp': '__kbnSharedDeps__.LodashFp',
fflate: '__kbnSharedDeps__.Fflate',

/**
* runtime deps which don't need to be copied across all bundles
Expand Down
Loading

0 comments on commit 469a6af

Please sign in to comment.