-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into revert-side-car
- Loading branch information
Showing
190 changed files
with
12,992 additions
and
2,696 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
examples/partial_results_example/public/app/expressions_context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
examples/partial_results_example/public/functions/count_event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
examples/partial_results_example/public/functions/get_events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
examples/partial_results_example/public/functions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
examples/partial_results_example/public/functions/pluck.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.