Skip to content

Commit

Permalink
Merge branch 'master' into revert-side-car
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHassanabad committed Sep 27, 2021
2 parents ba00ba3 + cb37ae8 commit db725c0
Show file tree
Hide file tree
Showing 190 changed files with 12,992 additions and 2,696 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
/examples/url_generators_examples/ @elastic/kibana-app-services
/examples/url_generators_explorer/ @elastic/kibana-app-services
/examples/field_formats_example/ @elastic/kibana-app-services
/examples/partial_results_example/ @elastic/kibana-app-services
/packages/elastic-datemath/ @elastic/kibana-app-services
/packages/kbn-interpreter/ @elastic/kibana-app-services
/src/plugins/bfetch/ @elastic/kibana-app-services
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ as uiSettings within the code.
|Console provides the user with tools for storing and executing requests against Elasticsearch.
|{kib-repo}blob/{branch}/src/plugins/custom_integrations/README.md[customIntegrations]
|Register add-data cards
|<<kibana-dashboard-plugin>>
|- Registers the dashboard application.
- Adds a dashboard embeddable that can be used in other applications.
Expand Down
9 changes: 9 additions & 0 deletions examples/partial_results_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Partial Results Example

The partial results is a feature of the expressions plugin allowing to emit intermediate execution results over time.

This example plugin demonstrates:

1. An expression function emitting a datatable with intermediate results (`getEvents`).
2. An expression function emitting an infinite number of results (`countEvent`).
3. A combination of those two functions using the `mapColumn` function that continuously updates the resulting table.
12 changes: 12 additions & 0 deletions examples/partial_results_example/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "paertialResultsExample",
"version": "0.1.0",
"kibanaVersion": "kibana",
"ui": true,
"owner": {
"name": "App Services",
"githubTeam": "kibana-app-services"
},
"description": "A plugin demonstrating partial results in the expressions plugin",
"requiredPlugins": ["developerExamples", "expressions"]
}
90 changes: 90 additions & 0 deletions examples/partial_results_example/public/app/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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 React, { useContext, useEffect, useState } from 'react';
import { pluck } from 'rxjs/operators';
import {
EuiBasicTable,
EuiCallOut,
EuiCodeBlock,
EuiPage,
EuiPageBody,
EuiPageContent,
EuiPageContentBody,
EuiPageHeader,
EuiPageHeaderSection,
EuiSpacer,
EuiText,
EuiTitle,
} from '@elastic/eui';
import type { Datatable } from 'src/plugins/expressions';
import { ExpressionsContext } from './expressions_context';

const expression = `getEvents
| mapColumn name="Count" expression={
countEvent {pluck "event"}
}
`;

export function App() {
const expressions = useContext(ExpressionsContext);
const [datatable, setDatatable] = useState<Datatable>();

useEffect(() => {
const subscription = expressions
?.execute<null, Datatable>(expression, null)
.getData()
.pipe(pluck('result'))
.subscribe((value) => setDatatable(value as Datatable));

return () => subscription?.unsubscribe();
}, [expressions]);

return (
<EuiPage>
<EuiPageBody style={{ maxWidth: 1200, margin: '0 auto' }}>
<EuiPageHeader>
<EuiPageHeaderSection>
<EuiTitle size="l">
<h1>Partial Results Demo</h1>
</EuiTitle>
</EuiPageHeaderSection>
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentBody style={{ maxWidth: 800, margin: '0 auto' }}>
<EuiText data-test-subj="example-help">
<p>
This example listens for the window events and adds them to the table along with a
trigger counter.
</p>
</EuiText>
<EuiSpacer size={'m'} />
<EuiCodeBlock>{expression}</EuiCodeBlock>
<EuiSpacer size={'m'} />
{datatable ? (
<EuiBasicTable
textOnly={true}
data-test-subj={'example-table'}
columns={datatable.columns?.map(({ id: field, name }) => ({
field,
name,
'data-test-subj': `example-column-${field.toLowerCase()}`,
}))}
items={datatable.rows ?? []}
/>
) : (
<EuiCallOut color="success">
<p>Click or press any key.</p>
</EuiCallOut>
)}
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
</EuiPage>
);
}
12 changes: 12 additions & 0 deletions examples/partial_results_example/public/app/expressions_context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 { createContext } from 'react';
import type { ExpressionsServiceStart } from 'src/plugins/expressions';

export const ExpressionsContext = createContext<ExpressionsServiceStart | undefined>(undefined);
10 changes: 10 additions & 0 deletions examples/partial_results_example/public/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

export * from './app';
export * from './expressions_context';
40 changes: 40 additions & 0 deletions examples/partial_results_example/public/functions/count_event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 { Observable, fromEvent } from 'rxjs';
import { scan, startWith } from 'rxjs/operators';
import type { ExpressionFunctionDefinition } from 'src/plugins/expressions';

export interface CountEventArguments {
event: string;
}

export const countEvent: ExpressionFunctionDefinition<
'countEvent',
null,
CountEventArguments,
Observable<number>
> = {
name: 'countEvent',
type: 'number',
help: 'Subscribes for an event and counts a number of triggers.',
args: {
event: {
aliases: ['_'],
types: ['string'],
help: 'The event name.',
required: true,
},
},
fn(input, { event }) {
return fromEvent(window, event).pipe(
scan((count) => count + 1, 1),
startWith(1)
);
},
};
51 changes: 51 additions & 0 deletions examples/partial_results_example/public/functions/get_events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 { Observable, fromEvent, merge } from 'rxjs';
import { distinct, map, pluck, scan, take } from 'rxjs/operators';
import type { Datatable, ExpressionFunctionDefinition } from 'src/plugins/expressions';

const EVENTS: Array<keyof WindowEventMap> = [
'mousedown',
'mouseup',
'click',
'keydown',
'keyup',
'keypress',
];

export const getEvents: ExpressionFunctionDefinition<
'getEvents',
null,
{},
Observable<Datatable>
> = {
name: 'getEvents',
type: 'datatable',
help: 'Listens for the window events and returns a table with the triggered ones.',
args: {},
fn() {
return merge(...EVENTS.map((event) => fromEvent(window, event))).pipe(
pluck('type'),
distinct(),
take(EVENTS.length),
scan((events, event) => [...events, event], [] as string[]),
map((events) => ({
type: 'datatable',
columns: [
{
id: 'event',
meta: { type: 'string' },
name: 'Event',
},
],
rows: Array.from(events).map((event) => ({ event })),
}))
);
},
};
11 changes: 11 additions & 0 deletions examples/partial_results_example/public/functions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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.
*/

export * from './count_event';
export * from './get_events';
export * from './pluck';
32 changes: 32 additions & 0 deletions examples/partial_results_example/public/functions/pluck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { Datatable, ExpressionFunctionDefinition } from 'src/plugins/expressions';

export interface PluckArguments {
key: string;
}

export const pluck: ExpressionFunctionDefinition<'pluck', Datatable, PluckArguments, unknown> = {
name: 'pluck',
inputTypes: ['datatable'],
help: 'Takes a cell from the first table row.',
args: {
key: {
aliases: ['_'],
types: ['string'],
help: 'The column id.',
required: true,
},
},
fn({ rows }, { key }) {
const [{ [key]: value }] = rows;

return value;
},
};
12 changes: 12 additions & 0 deletions examples/partial_results_example/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 { PartialResultsExamplePlugin } from './plugin';

export function plugin() {
return new PartialResultsExamplePlugin();
}
57 changes: 57 additions & 0 deletions examples/partial_results_example/public/plugin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 React from 'react';
import ReactDOM from 'react-dom';
import type { ExpressionsService, ExpressionsServiceSetup } from 'src/plugins/expressions';
import { AppMountParameters, AppNavLinkStatus, CoreSetup, Plugin } from '../../../src/core/public';
import type { DeveloperExamplesSetup } from '../../developer_examples/public';
import { App, ExpressionsContext } from './app';
import { countEvent, getEvents, pluck } from './functions';

interface SetupDeps {
developerExamples: DeveloperExamplesSetup;
expressions: ExpressionsServiceSetup;
}

export class PartialResultsExamplePlugin implements Plugin<void, void, SetupDeps> {
private expressions?: ExpressionsService;

setup({ application }: CoreSetup, { expressions, developerExamples }: SetupDeps) {
this.expressions = expressions.fork();
this.expressions.registerFunction(countEvent);
this.expressions.registerFunction(getEvents);
this.expressions.registerFunction(pluck);

application.register({
id: 'partialResultsExample',
title: 'Partial Results Example',
navLinkStatus: AppNavLinkStatus.hidden,
mount: async ({ element }: AppMountParameters) => {
ReactDOM.render(
<ExpressionsContext.Provider value={this.expressions}>
<App />
</ExpressionsContext.Provider>,
element
);
return () => ReactDOM.unmountComponentAtNode(element);
},
});

developerExamples.register({
appId: 'partialResultsExample',
title: 'Partial Results Example',
description: 'Learn how to use partial results in the expressions plugin.',
});
}

start() {
return {};
}

stop() {}
}
19 changes: 19 additions & 0 deletions examples/partial_results_example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./target",
"skipLibCheck": true
},
"include": [
"index.ts",
"public/**/*.ts",
"public/**/*.tsx",
"../../typings/**/*"
],
"exclude": [],
"references": [
{ "path": "../../src/core/tsconfig.json" },
{ "path": "../developer_examples/tsconfig.json" },
{ "path": "../../src/plugins/expressions/tsconfig.json" },
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@
"tar-fs": "^2.1.0",
"tempy": "^0.3.0",
"terser": "^5.7.1",
"terser-webpack-plugin": "^2.1.2",
"terser-webpack-plugin": "^4.2.3",
"tough-cookie": "^4.0.0",
"ts-loader": "^7.0.5",
"ts-morph": "^9.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ pageLoadAssetSize:
expressionTagcloud: 27505
expressions: 239290
securitySolution: 231753
customIntegrations: 28810
Loading

0 comments on commit db725c0

Please sign in to comment.