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

Add globalSearch x-pack plugin #66293

Merged
merged 55 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
c7381da
add skeleton for global_search plugin
pgayvallet May 11, 2020
4ca8898
base implementation of the server-side service
pgayvallet May 11, 2020
aa9a036
add utils tests
pgayvallet May 12, 2020
25e7449
add server-side mocks
pgayvallet May 12, 2020
c38d26f
move take_in_array to common folder
pgayvallet May 12, 2020
99af7a5
implements base of client-side plugin
pgayvallet May 12, 2020
e7657d1
add tests for server-side service
pgayvallet May 12, 2020
aea2702
fix server plugin tests
pgayvallet May 12, 2020
a1d0572
implement `navigateToUrl` core API
pgayvallet May 13, 2020
7e2ea49
extract processResults for the client-side
pgayvallet May 13, 2020
06391b9
fetch server results from the client side
pgayvallet May 13, 2020
1774885
factorize process_results
pgayvallet May 13, 2020
6032004
fix plugin start params
pgayvallet May 13, 2020
70d9592
move things around
pgayvallet May 13, 2020
72d9069
move all server types to single file
pgayvallet May 14, 2020
cc8c3ab
Merge remote-tracking branch 'upstream/master' into kbn-64284-global-…
pgayvallet May 14, 2020
5da479e
fix types imports
pgayvallet May 14, 2020
8e9ec76
add basic FTR tests
pgayvallet May 14, 2020
1d563a8
Merge remote-tracking branch 'upstream/master' into kbn-64284-global-…
pgayvallet May 18, 2020
54a4ccd
add client-side service tests
pgayvallet May 18, 2020
3b79054
add tests for addNavigate
pgayvallet May 18, 2020
1845286
add getDefaultPreference & tests
pgayvallet May 18, 2020
337b2a2
use optional for RequestHandlerContext
pgayvallet May 18, 2020
09324d3
add registerRoutes test
pgayvallet May 18, 2020
f911341
add base test for context
pgayvallet May 18, 2020
ee18aaf
resolve TODO
pgayvallet May 18, 2020
bcda46e
common nits/doc
pgayvallet May 18, 2020
c08042d
common nits/doc on public
pgayvallet May 18, 2020
4220fe1
update CODEOWNERS
pgayvallet May 18, 2020
bc67cde
add import for declare statement
pgayvallet May 18, 2020
114ec4d
add license check on the server-side
pgayvallet May 19, 2020
a8a58e6
Merge remote-tracking branch 'upstream/master' into kbn-64284-global-…
pgayvallet May 19, 2020
1c6d1f4
add license check on the client-side
pgayvallet May 19, 2020
c5356c2
Merge remote-tracking branch 'upstream/master' into kbn-64284-global-…
pgayvallet May 25, 2020
7fc6a77
eslint
pgayvallet May 25, 2020
a23a24c
Merge remote-tracking branch 'upstream/master' into kbn-64284-global-…
pgayvallet May 25, 2020
2fecc4e
address some review comments
pgayvallet Jun 2, 2020
9ba28ac
Merge remote-tracking branch 'upstream/master' into kbn-64284-global-…
pgayvallet Jun 2, 2020
fa3b8c0
use properly typed errors for obs
pgayvallet Jun 2, 2020
b66ccab
add integration tests for the find endpoint
pgayvallet Jun 2, 2020
ba1fcc0
fix unit tests
pgayvallet Jun 2, 2020
ab90710
use licensing start contract
pgayvallet Jun 2, 2020
05d1372
translate the error message
pgayvallet Jun 2, 2020
a044fbf
fix eslint rule for test_utils
pgayvallet Jun 2, 2020
d7a489c
fix test_utils imports
pgayvallet Jun 2, 2020
1bb244c
remove NavigableGlobalSearchResult, use `application.navigateToUrl` i…
pgayvallet Jun 3, 2020
526e15a
use coreProvider plugin in FTR tests
pgayvallet Jun 3, 2020
195d136
nits
pgayvallet Jun 3, 2020
dd39a4e
Merge remote-tracking branch 'upstream/master' into kbn-64284-global-…
pgayvallet Jun 3, 2020
7e6013d
fix service start params
pgayvallet Jun 3, 2020
d2a2f42
fix service start params, bis
pgayvallet Jun 3, 2020
b387dd6
I really need to fix this typecheck oom error
pgayvallet Jun 3, 2020
278638f
Merge remote-tracking branch 'upstream/master' into kbn-64284-global-…
pgayvallet Jun 4, 2020
979b113
add README, update missing jsdoc
pgayvallet Jun 4, 2020
3a89d29
nits on doc
pgayvallet Jun 4, 2020
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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ module.exports = {
'!src/core/server/index.ts', // relative import
'!src/core/server/mocks{,.ts}',
'!src/core/server/types{,.ts}',
'!src/core/server/test_utils',
'!src/core/server/test_utils{,.ts}',
// for absolute imports until fixed in
// https://github.com/elastic/kibana/issues/36096
'!src/core/server/*.test.mocks{,.ts}',
Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
/config/kibana.yml @elastic/kibana-platform
/x-pack/plugins/features/ @elastic/kibana-platform
/x-pack/plugins/licensing/ @elastic/kibana-platform
/x-pack/plugins/global_search/ @elastic/kibana-platform
/x-pack/plugins/cloud/ @elastic/kibana-platform
/packages/kbn-config-schema/ @elastic/kibana-platform
/src/legacy/server/config/ @elastic/kibana-platform
Expand Down
61 changes: 19 additions & 42 deletions rfcs/text/0011_global_search.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Notes:

### Plugin API

#### server API
#### Common types

```ts
/**
Expand All @@ -208,6 +208,21 @@ type GlobalSearchResult = Omit<GlobalSearchProviderResult, 'url'> & {
url: string;
};


/**
* Response returned from the {@link GlobalSearchServiceStart | global search service}'s `find` API
*/
type GlobalSearchBatchedResults = {
/**
* Results for this batch
*/
results: GlobalSearchResult[];
};
```

#### server API

```ts
/**
* Options for the server-side {@link GlobalSearchServiceStart.find | find API}
*/
Expand All @@ -226,16 +241,6 @@ interface GlobalSearchFindOptions {
aborted$?: Observable<void>;
}

/**
* Response returned from the server-side {@link GlobalSearchServiceStart | global search service}'s `find` API
*/
type GlobalSearchBatchedResults = {
/**
* Results for this batch
*/
results: GlobalSearchResult[];
};

/** @public */
interface GlobalSearchPluginSetup {
registerResultProvider(provider: GlobalSearchResultProvider);
Expand Down Expand Up @@ -265,28 +270,6 @@ interface GlobalSearchFindOptions {
aborted$?: Observable<void>;
}

/**
* Enhanced {@link GlobalSearchResult | result type} for the client-side,
* to allow navigating to a given result.
*/
interface NavigableGlobalSearchResult extends GlobalSearchResult {
/**
* Navigate to this result's associated url. If the result is on this kibana instance, user will be redirected to it
* in a SPA friendly way using `application.navigateToApp`, else, a full page refresh will be performed.
*/
navigate: () => Promise<void>;
}

/**
* Response returned from the client-side {@link GlobalSearchServiceStart | global search service}'s `find` API
*/
type GlobalSearchBatchedResults = {
/**
* Results for this batch
*/
results: NavigableGlobalSearchResult[];
};

/** @public */
interface GlobalSearchPluginSetup {
registerResultProvider(provider: GlobalSearchResultProvider);
Expand All @@ -304,9 +287,6 @@ Notes:
- The `registerResultProvider` setup APIs share the same signature, however the input `GlobalSearchResultProvider`
types are different on the client and server.
- The `find` start API signature got a `KibanaRequest` for `server`, when this parameter is not present for `public`.
- The `find` API returns a observable of `NavigableGlobalSearchResult` instead of plain `GlobalSearchResult`. This type
is here to enhance results with a `navigate` method to let the `GlobalSearch` plugin handle the navigation logic, which is
non-trivial. See the [Redirecting to a result](#redirecting-to-a-result) section for more info.

#### http API

Expand Down Expand Up @@ -395,14 +375,11 @@ In current specification, the only conversion step is to transform the `result.u

#### redirecting to a result

Parsing a relative or absolute result url to perform SPA navigation can be non trivial, and should remains the responsibility
of the GlobalSearch plugin API.

This is why `NavigableGlobalSearchResult.navigate` has been introduced on the client-side version of the `find` API
Parsing a relative or absolute result url to perform SPA navigation can be non trivial. This is why `ApplicationService.navigateToUrl` has been introduced on the client-side core API

When using `navigate` from a result instance, the following logic will be executed:
When using `navigateToUrl` with the url of a result instance, the following logic will be executed:

If all these criteria are true for `result.url`:
If all these criteria are true for `url`:

- (only for absolute URLs) The origin of the URL matches the origin of the browser's current location
- The pathname of the URL starts with the current basePath (eg. /mybasepath/s/my-space)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
import { registerBulkCreateRoute } from '../bulk_create';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer } from './test_utils';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
import { registerBulkGetRoute } from '../bulk_get';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer } from './test_utils';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
import { registerBulkUpdateRoute } from '../bulk_update';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer } from './test_utils';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
import { registerCreateRoute } from '../create';
import { savedObjectsClientMock } from '../../service/saved_objects_client.mock';
import { setupServer } from './test_utils';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
import { registerDeleteRoute } from '../delete';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer } from './test_utils';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
import { SavedObjectConfig } from '../../saved_objects_config';
import { registerExportRoute } from '../export';
import { setupServer, createExportableType } from './test_utils';
import { setupServer, createExportableType } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
const exportSavedObjectsToStream = exportMock.exportSavedObjectsToStream as jest.Mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import querystring from 'querystring';
import { UnwrapPromise } from '@kbn/utility-types';
import { registerFindRoute } from '../find';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer } from './test_utils';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { UnwrapPromise } from '@kbn/utility-types';
import { registerImportRoute } from '../import';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { SavedObjectConfig } from '../../saved_objects_config';
import { setupServer, createExportableType } from './test_utils';
import { setupServer, createExportableType } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
import { registerLogLegacyImportRoute } from '../log_legacy_import';
import { loggingServiceMock } from '../../../logging/logging_service.mock';
import { setupServer } from './test_utils';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
import { registerResolveImportErrorsRoute } from '../resolve_import_errors';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer, createExportableType } from './test_utils';
import { setupServer, createExportableType } from '../test_utils';
import { SavedObjectConfig } from '../../saved_objects_config';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
import { registerUpdateRoute } from '../update';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
import { setupServer } from './test_utils';
import { setupServer } from '../test_utils';

type setupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
* under the License.
*/

import { ContextService } from '../../../context';
import { createHttpServer, createCoreContext } from '../../../http/test_utils';
import { coreMock } from '../../../mocks';
import { SavedObjectsType } from '../../types';
import { ContextService } from '../../context';
import { createHttpServer, createCoreContext } from '../../http/test_utils';
import { coreMock } from '../../mocks';
import { SavedObjectsType } from '../types';

const coreId = Symbol('core');
const defaultCoreId = Symbol('core');

export const setupServer = async () => {
export const setupServer = async (coreId: symbol = defaultCoreId) => {
const coreContext = createCoreContext({ coreId });
const contextService = new ContextService(coreContext);

Expand Down
1 change: 1 addition & 0 deletions src/core/server/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

export { createHttpServer } from './http/test_utils';
export { ServiceStatusLevelSnapshotSerializer } from './status/test_utils';
export { setupServer } from './saved_objects/routes/test_utils';
1 change: 1 addition & 0 deletions src/core/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './capabilities';
export * from './app_category';
export * from './ui_settings';
export * from './saved_objects';
export * from './serializable';
32 changes: 32 additions & 0 deletions src/core/types/serializable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export type Serializable =
| string
| number
| boolean
| null
| SerializableArray
| SerializableRecord;

// we need interfaces instead of types here to allow cyclic references
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SerializableArray extends Array<Serializable> {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SerializableRecord extends Record<string, Serializable> {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "core_provider_plugin",
"version": "0.0.1",
"kibanaVersion": "kibana",
"optionalPlugins": ["core_plugin_a", "core_plugin_b", "licensing"],
"optionalPlugins": ["core_plugin_a", "core_plugin_b", "licensing", "globalSearchTest"],
"server": false,
"ui": true
}
1 change: 1 addition & 0 deletions x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"xpack.endpoint": "plugins/endpoint",
"xpack.features": "plugins/features",
"xpack.fileUpload": "plugins/file_upload",
"xpack.globalSearch": ["plugins/global_search"],
"xpack.graph": ["plugins/graph"],
"xpack.grokDebugger": "plugins/grokdebugger",
"xpack.idxMgmt": "plugins/index_management",
Expand Down
49 changes: 49 additions & 0 deletions x-pack/plugins/global_search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Kibana GlobalSearch plugin

The GlobalSearch plugin provides an easy way to search for various objects, such as applications
or dashboards from the Kibana instance, from both server and client-side plugins

## Consuming the globalSearch API

```ts
startDeps.globalSearch.find('some term').subscribe({
next: ({ results }) => {
addNewResultsToList(results);
},
error: () => {},
complete: () => {
showAsyncSearchIndicator(false);
}
});
```

## Registering custom result providers

The GlobalSearch API allows to extend provided results by registering your own provider.

```ts
setupDeps.globalSearch.registerResultProvider({
id: 'my_provider',
find: (term, options, context) => {
const resultPromise = myService.search(term, context.core.savedObjects.client);
return from(resultPromise).pipe(takeUntil(options.aborted$);
},
});
```

## Known limitations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can link the RFC for more details provided


### Client-side registered providers

Results from providers registered from the client-side `registerResultProvider` API will
not be available when performing a search from the server-side. For this reason, prefer
registering providers using the server-side API when possible.

Refer to the [RFC](rfcs/text/0011_global_search.md#result_provider_registration) for more details

### Search completion cause

There is currently no way to identify `globalSearch.find` observable completion cause:
searches completing because all providers returned all their results and searches
completing because the consumer aborted the search using the `aborted$` option or because
the internal timout period has been reaches will both complete the same way.
22 changes: 22 additions & 0 deletions x-pack/plugins/global_search/common/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { GlobalSearchFindError } from './errors';

describe('GlobalSearchFindError', () => {
describe('#invalidLicense', () => {
it('create an error with the correct `type`', () => {
const error = GlobalSearchFindError.invalidLicense('foobar');
expect(error.message).toBe('foobar');
expect(error.type).toBe('invalid-license');
});

it('can be identified via instanceof', () => {
const error = GlobalSearchFindError.invalidLicense('foo');
expect(error instanceof GlobalSearchFindError).toBe(true);
});
});
});
Loading