Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Use Search API in Timelion (sync) (#75115) #76884

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [ES\_SEARCH\_STRATEGY](./kibana-plugin-plugins-data-server.es_search_strategy.md)

## ES\_SEARCH\_STRATEGY variable

<b>Signature:</b>

```typescript
ES_SEARCH_STRATEGY = "es"
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export interface ISearchStart<SearchStrategyRequest extends IEsSearchRequest = I
| --- | --- | --- |
| [aggs](./kibana-plugin-plugins-data-server.isearchstart.aggs.md) | <code>AggsStart</code> | |
| [getSearchStrategy](./kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md) | <code>(name: string) =&gt; ISearchStrategy&lt;SearchStrategyRequest, SearchStrategyResponse&gt;</code> | Get other registered search strategies. For example, if a new strategy needs to use the already-registered ES search strategy, it can use this function to accomplish that. |
| [search](./kibana-plugin-plugins-data-server.isearchstart.search.md) | <code>(context: RequestHandlerContext, request: IKibanaSearchRequest, options: ISearchOptions) =&gt; Promise&lt;IKibanaSearchResponse&gt;</code> | |
| [search](./kibana-plugin-plugins-data-server.isearchstart.search.md) | <code>(context: RequestHandlerContext, request: IEsSearchRequest, options: ISearchOptions) =&gt; Promise&lt;IEsSearchResponse&gt;</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
search: (context: RequestHandlerContext, request: IKibanaSearchRequest, options: ISearchOptions) => Promise<IKibanaSearchResponse>;
search: (context: RequestHandlerContext, request: IEsSearchRequest, options: ISearchOptions) => Promise<IEsSearchResponse>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
| [AggGroupNames](./kibana-plugin-plugins-data-server.agggroupnames.md) | |
| [castEsToKbnFieldTypeName](./kibana-plugin-plugins-data-server.castestokbnfieldtypename.md) | Get the KbnFieldType name for an esType string |
| [config](./kibana-plugin-plugins-data-server.config.md) | |
| [ES\_SEARCH\_STRATEGY](./kibana-plugin-plugins-data-server.es_search_strategy.md) | |
| [esFilters](./kibana-plugin-plugins-data-server.esfilters.md) | |
| [esKuery](./kibana-plugin-plugins-data-server.eskuery.md) | |
| [esQuery](./kibana-plugin-plugins-data-server.esquery.md) | |
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export {
ISearchOptions,
IEsSearchRequest,
IEsSearchResponse,
ES_SEARCH_STRATEGY,
// tabify
TabbedAggColumn,
TabbedAggRow,
Expand Down
19 changes: 18 additions & 1 deletion src/plugins/data/server/search/routes/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,24 @@ describe('Search service', () => {
});

it('handler calls context.search.search with the given request and strategy', async () => {
const response = { id: 'yay' };
const response = {
id: 'yay',
rawResponse: {
took: 100,
timed_out: true,
_shards: {
total: 0,
successful: 0,
failed: 0,
skipped: 0,
},
hits: {
total: 0,
max_score: 0,
hits: [],
},
},
};
mockDataStart.search.search.mockResolvedValue(response);
const mockContext = {};
const mockBody = { id: undefined, params: {} };
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/data/server/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { RequestHandlerContext } from '../../../../core/server';
import { IKibanaSearchResponse, IKibanaSearchRequest, ISearchOptions } from '../../common/search';
import { ISearchOptions } from '../../common/search';
import { AggsSetup, AggsStart } from './aggs';
import { SearchUsage } from './collectors/usage';
import { IEsSearchRequest, IEsSearchResponse } from './es_search';
Expand Down Expand Up @@ -66,9 +66,9 @@ export interface ISearchStart<
) => ISearchStrategy<SearchStrategyRequest, SearchStrategyResponse>;
search: (
context: RequestHandlerContext,
request: IKibanaSearchRequest,
request: IEsSearchRequest,
options: ISearchOptions
) => Promise<IKibanaSearchResponse>;
) => Promise<IEsSearchResponse>;
}

/**
Expand Down
33 changes: 19 additions & 14 deletions src/plugins/data/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ export enum ES_FIELD_TYPES {
_TYPE = "_type"
}

// Warning: (ae-missing-release-tag) "ES_SEARCH_STRATEGY" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const ES_SEARCH_STRATEGY = "es";

// Warning: (ae-forgotten-export) The symbol "ExpressionFunctionDefinition" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Input" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Arguments" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -712,7 +717,7 @@ export interface ISearchStart<SearchStrategyRequest extends IEsSearchRequest = I
// Warning: (ae-forgotten-export) The symbol "RequestHandlerContext" needs to be exported by the entry point index.d.ts
//
// (undocumented)
search: (context: RequestHandlerContext, request: IKibanaSearchRequest, options: ISearchOptions) => Promise<IKibanaSearchResponse>;
search: (context: RequestHandlerContext, request: IEsSearchRequest, options: ISearchOptions) => Promise<IEsSearchResponse>;
}

// Warning: (ae-missing-release-tag) "ISearchStrategy" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -1088,19 +1093,19 @@ export function usageProvider(core: CoreSetup_2): SearchUsage;
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:127:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:127:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:221:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:221:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:221:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:221:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:223:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:224:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:233:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:234:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:235:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:239:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:240:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:244:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:247:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:222:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:222:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:222:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:222:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:224:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:225:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:234:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:235:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:236:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:240:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:241:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:245:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:248:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/plugin.ts:88:66 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/vis_type_timelion/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { first } from 'rxjs/operators';
import { TypeOf, schema } from '@kbn/config-schema';
import { RecursiveReadonly } from '@kbn/utility-types';

import { PluginStart } from '../../../../src/plugins/data/server';
import { CoreSetup, PluginInitializerContext } from '../../../../src/core/server';
import { deepFreeze } from '../../../../src/core/server';
import { configSchema } from '../config';
Expand All @@ -42,6 +43,10 @@ export interface PluginSetupContract {
uiEnabled: boolean;
}

export interface TimelionPluginStartDeps {
data: PluginStart;
}

/**
* Represents Timelion Plugin instance that will be managed by the Kibana plugin system.
*/
Expand Down Expand Up @@ -80,11 +85,12 @@ export class Plugin {
functions,
getFunction,
logger,
core,
};

functionsRoute(router, deps);
runRoute(router, deps);
validateEsRoute(router);
validateEsRoute(router, core);

core.uiSettings.register({
'timelion:es.timefield': {
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/vis_type_timelion/server/routes/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { IRouter, Logger } from 'kibana/server';
import { IRouter, Logger, CoreSetup } from 'kibana/server';
import { schema } from '@kbn/config-schema';
import Bluebird from 'bluebird';
import _ from 'lodash';
Expand All @@ -37,10 +37,12 @@ export function runRoute(
logger,
getFunction,
configManager,
core,
}: {
logger: Logger;
getFunction: (name: string) => TimelionFunctionInterface;
configManager: ConfigManager;
core: CoreSetup;
}
) {
router.post(
Expand Down Expand Up @@ -81,13 +83,14 @@ export function runRoute(
const uiSettings = await context.core.uiSettings.client.getAll();

const tlConfig = getTlConfig({
context,
request,
settings: _.defaults(uiSettings, timelionDefaults), // Just in case they delete some setting.
getFunction,
getStartServices: core.getStartServices,
allowedGraphiteUrls: configManager.getGraphiteUrls(),
esShardTimeout: configManager.getEsShardTimeout(),
savedObjectsClient: context.core.savedObjects.client,
esDataClient: () => context.core.elasticsearch.legacy.client,
});
const chainRunner = chainRunnerFn(tlConfig);
const sheet = await Bluebird.all(chainRunner.processRequest(request.body));
Expand Down
40 changes: 23 additions & 17 deletions src/plugins/vis_type_timelion/server/routes/validate_es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,49 @@
*/

import _ from 'lodash';
import { IRouter } from 'kibana/server';
import { IRouter, CoreSetup } from 'kibana/server';
import { ES_SEARCH_STRATEGY } from '../../../data/server';
import { TimelionPluginStartDeps } from '../plugin';

export function validateEsRoute(router: IRouter) {
export function validateEsRoute(router: IRouter, core: CoreSetup) {
router.get(
{
path: '/api/timelion/validate/es',
validate: false,
},
async function (context, request, response) {
const uiSettings = await context.core.uiSettings.client.getAll();

const { callAsCurrentUser } = context.core.elasticsearch.legacy.client;
const deps = (await core.getStartServices())[1] as TimelionPluginStartDeps;

const timefield = uiSettings['timelion:es.timefield'];

const body = {
index: uiSettings['es.default_index'],
body: {
aggs: {
maxAgg: {
max: {
field: timefield,
params: {
index: uiSettings['es.default_index'],
body: {
aggs: {
maxAgg: {
max: {
field: timefield,
},
},
},
minAgg: {
min: {
field: timefield,
minAgg: {
min: {
field: timefield,
},
},
},
size: 0,
},
size: 0,
},
};

let resp = {};
let resp;
try {
resp = await callAsCurrentUser('search', body);
resp = await deps.data.search.search(context, body, {
strategy: ES_SEARCH_STRATEGY,
});
resp = resp.rawResponse;
} catch (errResp) {
resp = errResp;
}
Expand Down
Loading