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 45 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 @@ -220,7 +220,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
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> {}
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setupServer } from 'src/core/server/saved_objects/routes/integration_tests/test_utils';
import { setupServer } from 'src/core/server/test_utils';
import { registerJobGenerationRoutes } from './generation';
import { createMockReportingCore } from '../../test_helpers';
import { ReportingCore } from '..';
Expand Down
3 changes: 1 addition & 2 deletions x-pack/legacy/plugins/reporting/server/routes/jobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import supertest from 'supertest';
import { UnwrapPromise } from '@kbn/utility-types';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setupServer } from 'src/core/server/saved_objects/routes/integration_tests/test_utils';
import { setupServer } from 'src/core/server/test_utils';
import { registerJobInfoRoutes } from './jobs';
import { createMockReportingCore } from '../../test_helpers';
import { ReportingCore } from '..';
Expand Down
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);
});
});
});
27 changes: 27 additions & 0 deletions x-pack/plugins/global_search/common/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.
*/

// only one type for now, but already present for future-proof reasons
export type GlobalSearchFindErrorType = 'invalid-license';

/**
* Error thrown from the {@link GlobalSearchPluginStart.find | GlobalSearch find API}'s result observable
*
* @public
*/
export class GlobalSearchFindError extends Error {
public static invalidLicense(message: string) {
return new GlobalSearchFindError('invalid-license', message);
}

private constructor(public readonly type: GlobalSearchFindErrorType, message: string) {
super(message);

// Set the prototype explicitly, see:
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.setPrototypeOf(this, GlobalSearchFindError.prototype);
}
}
24 changes: 24 additions & 0 deletions x-pack/plugins/global_search/common/license_checker.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { ILicenseChecker } from './license_checker';

const createLicenseCheckerMock = (): jest.Mocked<ILicenseChecker> => {
const mock = {
getState: jest.fn(),
getLicense: jest.fn(),
clean: jest.fn(),
};

mock.getLicense.mockReturnValue(undefined);
mock.getState.mockReturnValue({ valid: true });

return mock;
};

export const licenseCheckerMock = {
create: createLicenseCheckerMock,
};
63 changes: 63 additions & 0 deletions x-pack/plugins/global_search/common/license_checker.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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 { Observable, of, BehaviorSubject } from 'rxjs';
import { licenseMock } from '../../licensing/common/licensing.mock';
import { ILicense, LicenseCheck } from '../../licensing/common/types';
import { LicenseChecker } from './license_checker';

describe('LicenseChecker', () => {
const createLicense = (check: LicenseCheck): ILicense => {
const license = licenseMock.createLicenseMock();
license.check.mockReturnValue(check);
return license;
};

const createLicense$ = (check: LicenseCheck): Observable<ILicense> => of(createLicense(check));

it('returns the correct state of the license', () => {
let checker = new LicenseChecker(createLicense$({ state: 'valid' }));
expect(checker.getState()).toEqual({ valid: true });

checker = new LicenseChecker(createLicense$({ state: 'expired' }));
expect(checker.getState()).toEqual({ valid: false, message: 'expired' });

checker = new LicenseChecker(createLicense$({ state: 'invalid' }));
expect(checker.getState()).toEqual({ valid: false, message: 'invalid' });

checker = new LicenseChecker(createLicense$({ state: 'unavailable' }));
expect(checker.getState()).toEqual({ valid: false, message: 'unavailable' });
});

it('updates the state when the license changes', () => {
const license$ = new BehaviorSubject<ILicense>(createLicense({ state: 'valid' }));

const checker = new LicenseChecker(license$);
expect(checker.getState()).toEqual({ valid: true });

license$.next(createLicense({ state: 'expired' }));
expect(checker.getState()).toEqual({ valid: false, message: 'expired' });

license$.next(createLicense({ state: 'valid' }));
expect(checker.getState()).toEqual({ valid: true });
});

it('removes the subscription when calling `clean`', () => {
const mockUnsubscribe = jest.fn();
const mockObs = {
subscribe: jest.fn().mockReturnValue({ unsubscribe: mockUnsubscribe }),
};

const checker = new LicenseChecker(mockObs as any);

expect(mockObs.subscribe).toHaveBeenCalledTimes(1);
expect(mockUnsubscribe).not.toHaveBeenCalled();

checker.clean();

expect(mockUnsubscribe).toHaveBeenCalledTimes(1);
});
});
49 changes: 49 additions & 0 deletions x-pack/plugins/global_search/common/license_checker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 { Observable, Subscription } from 'rxjs';
import { ILicense } from '../../licensing/common/types';

export type LicenseState = { valid: false; message: string } | { valid: true };

export type CheckLicense = (license: ILicense) => LicenseState;

const checkLicense: CheckLicense = (license) => {
const check = license.check('globalSearch', 'basic');
switch (check.state) {
case 'expired':
return { valid: false, message: 'expired' };
case 'invalid':
return { valid: false, message: 'invalid' };
case 'unavailable':
return { valid: false, message: 'unavailable' };
case 'valid':
return { valid: true };
default:
throw new Error(`Invalid license state: ${check.state}`);
}
};

export type ILicenseChecker = PublicMethodsOf<LicenseChecker>;

export class LicenseChecker {
private subscription: Subscription;
private state: LicenseState = { valid: false, message: 'unknown' };

constructor(license$: Observable<ILicense>) {
this.subscription = license$.subscribe((license) => {
this.state = checkLicense(license);
});
}

public getState() {
return this.state;
}

public clean() {
this.subscription.unsubscribe();
}
}
Loading