Skip to content

Commit 089249f

Browse files
Merge branch 'master' into cypress-siem-jenkins-new-data
2 parents 7d5741b + 0e0f114 commit 089249f

94 files changed

Lines changed: 1634 additions & 812 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/demo_search/common/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import { IKibanaSearchRequest, IKibanaSearchResponse } from '../../../src/plugins/data/public';
2121

2222
export const DEMO_SEARCH_STRATEGY = 'DEMO_SEARCH_STRATEGY';
23+
export const ASYNC_DEMO_SEARCH_STRATEGY = 'ASYNC_DEMO_SEARCH_STRATEGY';
2324

2425
export interface IDemoRequest extends IKibanaSearchRequest {
2526
mood: string | 'sad' | 'happy';
@@ -29,3 +30,11 @@ export interface IDemoRequest extends IKibanaSearchRequest {
2930
export interface IDemoResponse extends IKibanaSearchResponse {
3031
greeting: string;
3132
}
33+
34+
export interface IAsyncDemoRequest extends IKibanaSearchRequest {
35+
fibonacciNumbers: number;
36+
}
37+
38+
export interface IAsyncDemoResponse extends IKibanaSearchResponse {
39+
fibonacciSequence: number[];
40+
}

examples/demo_search/kibana.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "demoSearch",
33
"version": "0.0.1",
44
"kibanaVersion": "kibana",
5-
"configPath": ["demo_search"],
5+
"configPath": ["demoSearch"],
66
"server": true,
77
"ui": true,
88
"requiredPlugins": ["data"],
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { Observable } from 'rxjs';
21+
import {
22+
ISearchContext,
23+
TSearchStrategyProvider,
24+
ISearchStrategy,
25+
} from '../../../src/plugins/data/public';
26+
27+
import { ASYNC_DEMO_SEARCH_STRATEGY, IAsyncDemoResponse } from '../common';
28+
import { ASYNC_SEARCH_STRATEGY } from '../../../x-pack/plugins/data_enhanced/public';
29+
30+
/**
31+
* This demo search strategy provider simply provides a shortcut for calling the DEMO_ASYNC_SEARCH_STRATEGY
32+
* on the server side, without users having to pass it in explicitly, and it takes advantage of the
33+
* already registered ASYNC_SEARCH_STRATEGY that exists on the client.
34+
*
35+
* so instead of callers having to do:
36+
*
37+
* ```
38+
* search(
39+
* { ...request, serverStrategy: DEMO_ASYNC_SEARCH_STRATEGY },
40+
* options,
41+
* ASYNC_SEARCH_STRATEGY
42+
* ) as Observable<IDemoResponse>,
43+
*```
44+
45+
* They can instead just do
46+
*
47+
* ```
48+
* search(request, options, DEMO_ASYNC_SEARCH_STRATEGY);
49+
* ```
50+
*
51+
* and are ensured type safety in regard to the request and response objects.
52+
*
53+
* @param context - context supplied by other plugins.
54+
* @param search - a search function to access other strategies that have already been registered.
55+
*/
56+
export const asyncDemoClientSearchStrategyProvider: TSearchStrategyProvider<typeof ASYNC_DEMO_SEARCH_STRATEGY> = (
57+
context: ISearchContext
58+
): ISearchStrategy<typeof ASYNC_DEMO_SEARCH_STRATEGY> => {
59+
const asyncStrategyProvider = context.getSearchStrategy(ASYNC_SEARCH_STRATEGY);
60+
const { search } = asyncStrategyProvider(context);
61+
return {
62+
search: (request, options) => {
63+
return search(
64+
{ ...request, serverStrategy: ASYNC_DEMO_SEARCH_STRATEGY },
65+
options
66+
) as Observable<IAsyncDemoResponse>;
67+
},
68+
};
69+
};

examples/demo_search/public/demo_search_strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { DEMO_SEARCH_STRATEGY, IDemoResponse } from '../common';
4343
* ```
4444
* context.search(request, options, DEMO_SEARCH_STRATEGY);
4545
* ```
46-
*
46+
*
4747
* and are ensured type safety in regard to the request and response objects.
4848
*
4949
* @param context - context supplied by other plugins.

examples/demo_search/public/plugin.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@
1919

2020
import { DataPublicPluginSetup } from '../../../src/plugins/data/public';
2121
import { Plugin, CoreSetup } from '../../../src/core/public';
22-
import { DEMO_SEARCH_STRATEGY } from '../common';
22+
import {
23+
DEMO_SEARCH_STRATEGY,
24+
IDemoRequest,
25+
IDemoResponse,
26+
ASYNC_DEMO_SEARCH_STRATEGY,
27+
IAsyncDemoRequest,
28+
IAsyncDemoResponse,
29+
} from '../common';
2330
import { demoClientSearchStrategyProvider } from './demo_search_strategy';
24-
import { IDemoRequest, IDemoResponse } from '../common';
31+
import { asyncDemoClientSearchStrategyProvider } from './async_demo_search_strategy';
2532

2633
interface DemoDataSearchSetupDependencies {
2734
data: DataPublicPluginSetup;
@@ -39,10 +46,12 @@ interface DemoDataSearchSetupDependencies {
3946
declare module '../../../src/plugins/data/public' {
4047
export interface IRequestTypesMap {
4148
[DEMO_SEARCH_STRATEGY]: IDemoRequest;
49+
[ASYNC_DEMO_SEARCH_STRATEGY]: IAsyncDemoRequest;
4250
}
4351

4452
export interface IResponseTypesMap {
4553
[DEMO_SEARCH_STRATEGY]: IDemoResponse;
54+
[ASYNC_DEMO_SEARCH_STRATEGY]: IAsyncDemoResponse;
4655
}
4756
}
4857

@@ -52,6 +61,10 @@ export class DemoDataPlugin implements Plugin {
5261
DEMO_SEARCH_STRATEGY,
5362
demoClientSearchStrategyProvider
5463
);
64+
deps.data.search.registerSearchStrategyProvider(
65+
ASYNC_DEMO_SEARCH_STRATEGY,
66+
asyncDemoClientSearchStrategyProvider
67+
);
5568
}
5669

5770
public start() {}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { TSearchStrategyProvider } from '../../../src/plugins/data/server';
21+
import { ASYNC_DEMO_SEARCH_STRATEGY } from '../common';
22+
23+
function getFibonacciSequence(n = 0) {
24+
const beginning = [0, 1].slice(0, n);
25+
return Array(Math.max(0, n))
26+
.fill(null)
27+
.reduce((sequence, value, i) => {
28+
if (i < 2) return sequence;
29+
return [...sequence, sequence[i - 1] + sequence[i - 2]];
30+
}, beginning);
31+
}
32+
33+
const generateId = (() => {
34+
let id = 0;
35+
return () => `${id++}`;
36+
})();
37+
38+
const loadedMap = new Map<string, number>();
39+
const totalMap = new Map<string, number>();
40+
41+
export const asyncDemoSearchStrategyProvider: TSearchStrategyProvider<typeof ASYNC_DEMO_SEARCH_STRATEGY> = () => {
42+
return {
43+
search: async request => {
44+
const id = request.id ?? generateId();
45+
46+
const loaded = (loadedMap.get(id) ?? 0) + 1;
47+
loadedMap.set(id, loaded);
48+
49+
const total = request.fibonacciNumbers ?? totalMap.get(id);
50+
totalMap.set(id, total);
51+
52+
const fibonacciSequence = getFibonacciSequence(loaded);
53+
return { id, total, loaded, fibonacciSequence };
54+
},
55+
cancel: async id => {
56+
loadedMap.delete(id);
57+
totalMap.delete(id);
58+
},
59+
};
60+
};

examples/demo_search/server/plugin.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
import { Plugin, CoreSetup, PluginInitializerContext } from 'kibana/server';
2121
import { PluginSetup as DataPluginSetup } from 'src/plugins/data/server';
2222
import { demoSearchStrategyProvider } from './demo_search_strategy';
23-
import { DEMO_SEARCH_STRATEGY, IDemoRequest, IDemoResponse } from '../common';
23+
import {
24+
DEMO_SEARCH_STRATEGY,
25+
IDemoRequest,
26+
IDemoResponse,
27+
ASYNC_DEMO_SEARCH_STRATEGY,
28+
IAsyncDemoRequest,
29+
IAsyncDemoResponse,
30+
} from '../common';
31+
import { asyncDemoSearchStrategyProvider } from './async_demo_search_strategy';
2432

2533
interface IDemoSearchExplorerDeps {
2634
data: DataPluginSetup;
@@ -38,10 +46,12 @@ interface IDemoSearchExplorerDeps {
3846
declare module '../../../src/plugins/data/server' {
3947
export interface IRequestTypesMap {
4048
[DEMO_SEARCH_STRATEGY]: IDemoRequest;
49+
[ASYNC_DEMO_SEARCH_STRATEGY]: IAsyncDemoRequest;
4150
}
4251

4352
export interface IResponseTypesMap {
4453
[DEMO_SEARCH_STRATEGY]: IDemoResponse;
54+
[ASYNC_DEMO_SEARCH_STRATEGY]: IAsyncDemoResponse;
4555
}
4656
}
4757

@@ -54,6 +64,11 @@ export class DemoDataPlugin implements Plugin<void, void, IDemoSearchExplorerDep
5464
DEMO_SEARCH_STRATEGY,
5565
demoSearchStrategyProvider
5666
);
67+
deps.data.search.registerSearchStrategyProvider(
68+
this.initializerContext.opaqueId,
69+
ASYNC_DEMO_SEARCH_STRATEGY,
70+
asyncDemoSearchStrategyProvider
71+
);
5772
}
5873

5974
public start() {}

examples/search_explorer/kibana.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "search_explorer",
2+
"id": "searchExplorer",
33
"version": "0.0.1",
44
"kibanaVersion": "kibana",
55
"configPath": ["search_explorer"],

examples/search_explorer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "search_explorer",
2+
"name": "searchExplorer",
33
"version": "1.0.0",
44
"main": "target/examples/search_explorer",
55
"kibana": {

examples/search_explorer/public/application.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { AppMountParameters, CoreStart } from '../../../src/core/public';
3232
import { EsSearchTest } from './es_strategy';
3333
import { Page } from './page';
3434
import { DemoStrategy } from './demo_strategy';
35+
import { AsyncDemoStrategy } from './async_demo_strategy';
3536
import { DocumentationPage } from './documentation';
3637
import { SearchApiPage } from './search_api';
3738
import { AppPluginStartDependencies, SearchBarComponentParams } from './types';
@@ -94,6 +95,11 @@ const SearchApp = ({ basename, data, application }: SearchBarComponentParams) =>
9495
id: 'demoSearch',
9596
component: <DemoStrategy search={data.search.search} />,
9697
},
98+
{
99+
title: 'Async demo search strategy',
100+
id: 'asyncDemoSearch',
101+
component: <AsyncDemoStrategy search={data.search.search} />,
102+
},
97103
];
98104

99105
const routes = pages.map((page, i) => (

0 commit comments

Comments
 (0)