Skip to content

Commit

Permalink
Merge branch 'cases-rbac-poc' of github.com:elastic/kibana into cases…
Browse files Browse the repository at this point in the history
…-rbac-audit-log-refactor
  • Loading branch information
jonathan-buttner committed Jun 1, 2021
2 parents 294c99e + c08ac43 commit 20e49ed
Show file tree
Hide file tree
Showing 316 changed files with 8,649 additions and 3,304 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions docs/user/dashboard/lens.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ A subset of *Lens* visualizations support value labels.
[role="screenshot"]
image::images/lens_value_labels_xychart_toggle.png[Lens Bar chart value labels menu]

NOTE: In bar charts, you are unable to move the label positions.

* *Pie*, *Donut*, and *Treemap*
+
[role="screenshot"]
Expand Down Expand Up @@ -243,6 +245,9 @@ refer to <<explore-fields-in-your-data,Explore the fields in your data>>.

Sorting dimensions in visualizations is unsupported in *Lens*.

You can sort the dimensions for a single column in data tables: click the column header, then select the sorting criteria you want to use.
If you use the dimension as `Columns`, then all the columns that belong to the same dimension are sorted in the table.

[float]
[[is-it-possible-to-use-saved-serches-in-lens]]
===== How do I visualize saved searches?
Expand All @@ -254,3 +259,47 @@ Visualizing saved searches in unsupported in *Lens*.
===== How do I change the number of suggestions?

Configuring the *Suggestions* that *Lens* automatically populates is unsupported.

[float]
[[is-it-possible-to-use-different-indexpatterns-in-lens]]
===== Can I visualize multiple index patterns in a single visualization?

You can create *Bar*, *Line* and *Area* charts from multiple index patterns.

Each *Layer* in a visualization is associated with an index pattern and mutiple *Layers* can be combined together within the same visualization. Each *Layer* also has a chart switcher button in order to select the best type of visualization for the specific dataset.
You can also change the index pattern for a single *Layer*.

[float]
[[why-my-field-x-is-missing-from-the-fields-list]]
===== Why is my field X missing from the fields list?

*Lens* does not support the visualization of full-text fields, therefore it is not showing them in the data summary.

[float]
[[how-to-handle-gaps-in-time-series-visualizations]]
===== How do I handle gaps in time series visualizations?

*Lens* provides a set of features to handle missing values for *Area* and *Line* charts, which is useful for sparse data in time series data.

To select a different way to represent missing values, open the *Visual options* menu, then select how to handle missing values. The default is to hide the missing values.
+
[role="screenshot"]
image::images/lens_missing_values_strategy.png[Lens Missing values strategies menu]

[float]
[[is-it-possible-to-change-the-scale-of-Y-axis]]
===== Is it possible to statically define the scale of the y-axis in a visualization?

The ability to start the y-axis from another value than 0, or use a logarithmic scale, is unsupported in *Lens*.

[float]
[[is-it-possible-to-have-pagination-for-datatable]]
===== Is it possible to have pagination in a data table?

Pagination in a data table is unsupported in *Lens*. However, the <<types-of-visualizations,aggregation-based data table>> supports pagination.

[float]
[[is-it-possible-to-have-more-than-one-Y-axis-scale]]
===== Is it possible to have more than one y-axis scale in visualizations?

*Lens* lets you pick, for each Y dimension, up to two distinct axis: *left* and *right*. Each axis can have a different scale.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,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
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
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
27 changes: 27 additions & 0 deletions src/core/server/deprecations/deprecations_factory.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import type { DeprecationsFactory } from './deprecations_factory';
type DeprecationsFactoryContract = PublicMethodsOf<DeprecationsFactory>;

const createDeprecationsFactoryMock = () => {
const mocked: jest.Mocked<DeprecationsFactoryContract> = {
getRegistry: jest.fn(),
getDeprecations: jest.fn(),
getAllDeprecations: jest.fn(),
};

mocked.getDeprecations.mockResolvedValue([]);
mocked.getAllDeprecations.mockResolvedValue([]);
return mocked as jest.Mocked<DeprecationsFactory>;
};

export const mockDeprecationsFactory = {
create: createDeprecationsFactoryMock,
};
2 changes: 1 addition & 1 deletion src/core/server/deprecations/deprecations_factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { GetDeprecationsContext } from './types';
import type { GetDeprecationsContext } from './types';
import { DeprecationsFactory } from './deprecations_factory';
import { loggerMock } from '../logging/logger.mock';

Expand Down
37 changes: 37 additions & 0 deletions src/core/server/deprecations/deprecations_registry.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import type { DeprecationsRegistry } from './deprecations_registry';
import type { GetDeprecationsContext } from './types';
import { elasticsearchClientMock } from '../elasticsearch/client/mocks';
import { savedObjectsClientMock } from '../saved_objects/service/saved_objects_client.mock';
type DeprecationsRegistryContract = PublicMethodsOf<DeprecationsRegistry>;

const createDeprecationsRegistryMock = () => {
const mocked: jest.Mocked<DeprecationsRegistryContract> = {
registerDeprecations: jest.fn(),
getDeprecations: jest.fn(),
};

return mocked as jest.Mocked<DeprecationsRegistry>;
};

const createGetDeprecationsContextMock = () => {
const mocked: jest.Mocked<GetDeprecationsContext> = {
esClient: elasticsearchClientMock.createScopedClusterClient(),
savedObjectsClient: savedObjectsClientMock.create(),
};

return mocked;
};

export const mockDeprecationsRegistry = {
create: createDeprecationsRegistryMock,
createGetDeprecationsContext: createGetDeprecationsContextMock,
};
2 changes: 1 addition & 1 deletion src/core/server/deprecations/deprecations_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

/* eslint-disable dot-notation */
import { RegisterDeprecationsConfig, GetDeprecationsContext } from './types';
import type { RegisterDeprecationsConfig, GetDeprecationsContext } from './types';
import { DeprecationsRegistry } from './deprecations_registry';

describe('DeprecationsRegistry', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/core/server/deprecations/deprecations_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
* Side Public License, v 1.
*/

import { DeprecationsDetails, RegisterDeprecationsConfig, GetDeprecationsContext } from './types';
import type {
DeprecationsDetails,
RegisterDeprecationsConfig,
GetDeprecationsContext,
} from './types';

export class DeprecationsRegistry {
private readonly deprecationContexts: RegisterDeprecationsConfig[] = [];
Expand Down
Loading

0 comments on commit 20e49ed

Please sign in to comment.