Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into ts-project-re…
Browse files Browse the repository at this point in the history
…fs-es_ui/ingest_pipelines
  • Loading branch information
TinaHeiligers committed Jan 29, 2021
2 parents c5bfe87 + 5feca52 commit b0c63f9
Show file tree
Hide file tree
Showing 249 changed files with 1,240 additions and 3,615 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

## SearchSource.fetch() method

Fetch this source and reject the returned Promise on error
> Warning: This API is now obsolete.
>
> Use fetch$ instead
>
Fetch this source and reject the returned Promise on error

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchSource](./kibana-plugin-plugins-data-public.searchsource.md) &gt; [fetch$](./kibana-plugin-plugins-data-public.searchsource.fetch_.md)

## SearchSource.fetch$() method

Fetch this source from Elasticsearch, returning an observable over the response(s)

<b>Signature:</b>

```typescript
fetch$(options?: ISearchOptions): import("rxjs").Observable<import("elasticsearch").SearchResponse<any>>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| options | <code>ISearchOptions</code> | |

<b>Returns:</b>

`import("rxjs").Observable<import("elasticsearch").SearchResponse<any>>`

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export declare class SearchSource
| [createCopy()](./kibana-plugin-plugins-data-public.searchsource.createcopy.md) | | creates a copy of this search source (without its children) |
| [destroy()](./kibana-plugin-plugins-data-public.searchsource.destroy.md) | | Completely destroy the SearchSource. {<!-- -->undefined<!-- -->} |
| [fetch(options)](./kibana-plugin-plugins-data-public.searchsource.fetch.md) | | Fetch this source and reject the returned Promise on error |
| [fetch$(options)](./kibana-plugin-plugins-data-public.searchsource.fetch_.md) | | Fetch this source from Elasticsearch, returning an observable over the response(s) |
| [getField(field, recurse)](./kibana-plugin-plugins-data-public.searchsource.getfield.md) | | Gets a single field from the fields |
| [getFields()](./kibana-plugin-plugins-data-public.searchsource.getfields.md) | | returns all search source fields |
| [getId()](./kibana-plugin-plugins-data-public.searchsource.getid.md) | | returns search source id |
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/common/search/search_source/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Public License, v 1.
*/

import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, of } from 'rxjs';
import type { MockedKeys } from '@kbn/utility-types/jest';
import { uiSettingsServiceMock } from '../../../../../core/public/mocks';

Expand All @@ -27,6 +27,7 @@ export const searchSourceInstanceMock: MockedKeys<ISearchSource> = {
createChild: jest.fn().mockReturnThis(),
setParent: jest.fn(),
getParent: jest.fn().mockReturnThis(),
fetch$: jest.fn().mockReturnValue(of({})),
fetch: jest.fn().mockResolvedValue({}),
onRequestStart: jest.fn(),
getSearchRequestBody: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ describe('SearchSource', () => {
let searchSource: SearchSource;

beforeEach(() => {
mockSearchMethod = jest.fn().mockReturnValue(of({ rawResponse: '' }));
mockSearchMethod = jest
.fn()
.mockReturnValue(
of(
{ rawResponse: { isPartial: true, isRunning: true } },
{ rawResponse: { isPartial: false, isRunning: false } }
)
);

searchSourceDependencies = {
getConfig: jest.fn(),
Expand Down Expand Up @@ -564,6 +571,34 @@ describe('SearchSource', () => {
await searchSource.fetch(options);
expect(mockSearchMethod).toBeCalledTimes(1);
});

test('should return partial results', (done) => {
searchSource = new SearchSource({ index: indexPattern }, searchSourceDependencies);
const options = {};

const next = jest.fn();
const complete = () => {
expect(next).toBeCalledTimes(2);
expect(next.mock.calls[0]).toMatchInlineSnapshot(`
Array [
Object {
"isPartial": true,
"isRunning": true,
},
]
`);
expect(next.mock.calls[1]).toMatchInlineSnapshot(`
Array [
Object {
"isPartial": false,
"isRunning": false,
},
]
`);
done();
};
searchSource.fetch$(options).subscribe({ next, complete });
});
});

describe('#serialize', () => {
Expand Down
58 changes: 32 additions & 26 deletions src/plugins/data/common/search/search_source/search_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@

import { setWith } from '@elastic/safer-lodash-set';
import { uniqueId, keyBy, pick, difference, omit, isObject, isFunction } from 'lodash';
import { map } from 'rxjs/operators';
import { map, switchMap, tap } from 'rxjs/operators';
import { defer, from } from 'rxjs';
import { normalizeSortRequest } from './normalize_sort_request';
import { fieldWildcardFilter } from '../../../../kibana_utils/common';
import { IIndexPattern } from '../../index_patterns';
Expand Down Expand Up @@ -244,30 +245,35 @@ export class SearchSource {
}

/**
* Fetch this source and reject the returned Promise on error
*
* @async
* Fetch this source from Elasticsearch, returning an observable over the response(s)
* @param options
*/
async fetch(options: ISearchOptions = {}) {
fetch$(options: ISearchOptions = {}) {
const { getConfig } = this.dependencies;
await this.requestIsStarting(options);

const searchRequest = await this.flatten();
this.history = [searchRequest];

let response;
if (getConfig(UI_SETTINGS.COURIER_BATCH_SEARCHES)) {
response = await this.legacyFetch(searchRequest, options);
} else {
response = await this.fetchSearch(searchRequest, options);
}

// TODO: Remove casting when https://github.com/elastic/elasticsearch-js/issues/1287 is resolved
if ((response as any).error) {
throw new RequestFailure(null, response);
}
return defer(() => this.requestIsStarting(options)).pipe(
switchMap(() => {
const searchRequest = this.flatten();
this.history = [searchRequest];

return getConfig(UI_SETTINGS.COURIER_BATCH_SEARCHES)
? from(this.legacyFetch(searchRequest, options))
: this.fetchSearch$(searchRequest, options);
}),
tap((response) => {
// TODO: Remove casting when https://github.com/elastic/elasticsearch-js/issues/1287 is resolved
if ((response as any).error) {
throw new RequestFailure(null, response);
}
})
);
}

return response;
/**
* Fetch this source and reject the returned Promise on error
* @deprecated Use fetch$ instead
*/
fetch(options: ISearchOptions = {}) {
return this.fetch$(options).toPromise();
}

/**
Expand Down Expand Up @@ -305,16 +311,16 @@ export class SearchSource {
* Run a search using the search service
* @return {Promise<SearchResponse<unknown>>}
*/
private fetchSearch(searchRequest: SearchRequest, options: ISearchOptions) {
private fetchSearch$(searchRequest: SearchRequest, options: ISearchOptions) {
const { search, getConfig, onResponse } = this.dependencies;

const params = getSearchParamsFromRequest(searchRequest, {
getConfig,
});

return search({ params, indexType: searchRequest.indexType }, options)
.pipe(map(({ rawResponse }) => onResponse(searchRequest, rawResponse)))
.toPromise();
return search({ params, indexType: searchRequest.indexType }, options).pipe(
map(({ rawResponse }) => onResponse(searchRequest, rawResponse))
);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2360,6 +2360,8 @@ export class SearchSource {
createChild(options?: {}): SearchSource;
createCopy(): SearchSource;
destroy(): void;
fetch$(options?: ISearchOptions): import("rxjs").Observable<import("elasticsearch").SearchResponse<any>>;
// @deprecated
fetch(options?: ISearchOptions): Promise<import("elasticsearch").SearchResponse<any>>;
getField<K extends keyof SearchSourceFields>(field: K, recurse?: boolean): SearchSourceFields[K];
getFields(): {
Expand Down Expand Up @@ -2601,7 +2603,7 @@ export const UI_SETTINGS: {
// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:138:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:169:7 - (ae-forgotten-export) The symbol "RuntimeField" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/search/aggs/types.ts:139:51 - (ae-forgotten-export) The symbol "AggTypesRegistryStart" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/search/search_source/search_source.ts:186:7 - (ae-forgotten-export) The symbol "SearchFieldValue" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/search/search_source/search_source.ts:187:7 - (ae-forgotten-export) The symbol "SearchFieldValue" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/field_formats/field_formats_service.ts:56:3 - (ae-forgotten-export) The symbol "FormatFactory" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:55:23 - (ae-forgotten-export) The symbol "FILTERS" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:55:23 - (ae-forgotten-export) The symbol "getDisplayValueFromFilter" needs to be exported by the entry point index.d.ts
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/case/common/api/cases/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

import * as rt from 'io-ts';

import { ActionResult } from '../../../../actions/common';
import { ActionResult, ActionType } from '../../../../actions/common';
import { UserRT } from '../user';
import { CaseConnectorRt, ConnectorMappingsRt, ESCaseConnector } from '../connectors';

export type ActionConnector = ActionResult;
export type ActionTypeConnector = ActionType;

// TODO: we will need to add this type rt.literal('close-by-third-party')
const ClosureTypeRT = rt.union([rt.literal('close-by-user'), rt.literal('close-by-pushing')]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import {
CaseConfigureService,
ConnectorMappingsService,
} from '../../../services';
import { getActions } from '../__mocks__/request_responses';
import { getActions, getActionTypes } from '../__mocks__/request_responses';
import { authenticationMock } from '../__fixtures__';
import type { CasesRequestHandlerContext } from '../../../types';

export const createRouteContext = async (client: any, badAuth = false) => {
const actionsMock = actionsClientMock.create();
actionsMock.getAll.mockImplementation(() => Promise.resolve(getActions()));
actionsMock.listTypes.mockImplementation(() => Promise.resolve(getActionTypes()));

const log = loggingSystemMock.create().get('case');
const esClientMock = elasticsearchServiceMock.createClusterClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import {
ActionTypeConnector,
CasePostRequest,
CasesConfigureRequest,
ConnectorTypes,
Expand Down Expand Up @@ -73,6 +74,49 @@ export const getActions = (): FindActionResult[] => [
},
];

export const getActionTypes = (): ActionTypeConnector[] => [
{
id: '.email',
name: 'Email',
minimumLicenseRequired: 'gold',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
},
{
id: '.index',
name: 'Index',
minimumLicenseRequired: 'basic',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
},
{
id: '.servicenow',
name: 'ServiceNow',
minimumLicenseRequired: 'platinum',
enabled: false,
enabledInConfig: true,
enabledInLicense: true,
},
{
id: '.jira',
name: 'Jira',
minimumLicenseRequired: 'gold',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
},
{
id: '.resilient',
name: 'IBM Resilient',
minimumLicenseRequired: 'platinum',
enabled: false,
enabledInConfig: true,
enabledInLicense: true,
},
];

export const newConfiguration: CasesConfigureRequest = {
connector: {
id: '456',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,72 @@ describe('GET connectors', () => {
expect(res.status).toEqual(200);

const expected = getActions();
// The first connector returned by getActions is of type .webhook and we expect to be filtered
expected.shift();
expect(res.payload).toEqual(expected);
});

it('filters out connectors that are not enabled in license', async () => {
const req = httpServerMock.createKibanaRequest({
path: `${CASE_CONFIGURE_CONNECTORS_URL}/_find`,
method: 'get',
});

const context = await createRouteContext(
createMockSavedObjectsRepository({
caseConfigureSavedObject: mockCaseConfigure,
caseMappingsSavedObject: mockCaseMappings,
})
);

const actionsClient = context.actions.getActionsClient();
(actionsClient.listTypes as jest.Mock).mockImplementation(() =>
Promise.resolve([
{
id: '.servicenow',
name: 'ServiceNow',
minimumLicenseRequired: 'platinum',
enabled: false,
enabledInConfig: true,
// User does not have a platinum license
enabledInLicense: false,
},
{
id: '.jira',
name: 'Jira',
minimumLicenseRequired: 'gold',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
},
{
id: '.resilient',
name: 'IBM Resilient',
minimumLicenseRequired: 'platinum',
enabled: false,
enabledInConfig: true,
// User does not have a platinum license
enabledInLicense: false,
},
])
);

const res = await routeHandler(context, req, kibanaResponseFactory);
expect(res.status).toEqual(200);
expect(res.payload).toEqual([
{
id: '456',
actionTypeId: '.jira',
name: 'Connector without isCaseOwned',
config: {
apiUrl: 'https://elastic.jira.com',
},
isPreconfigured: false,
referencedByCount: 0,
},
]);
});

it('it throws an error when actions client is null', async () => {
const req = httpServerMock.createKibanaRequest({
path: `${CASE_CONFIGURE_CONNECTORS_URL}/_find`,
Expand Down
Loading

0 comments on commit b0c63f9

Please sign in to comment.