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

Move KibanaMigrator into Server SavedObjectsService #43433

Merged
merged 47 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4b85ee9
Rename SavedObjectsService -> SavedObjectsLegacyService
rudolf Aug 13, 2019
6263726
Expose legacy pluginSpecs from Core LegacyService
rudolf Aug 13, 2019
13301e2
Expose legacy uiExports from Core LegacyService
rudolf Aug 13, 2019
19c9806
Move kibana config to NP
rudolf Aug 14, 2019
728e97d
Expose pluginExtendedConfig from LegacyService
rudolf Aug 15, 2019
b36daf3
Make KibanaMigrator NP compatible
rudolf Aug 15, 2019
4458c26
KibanaMigrator -> NP SavedObjectsService
rudolf Aug 15, 2019
6e1f026
SavedObjectsService never stop retrying ES connection error
rudolf Aug 21, 2019
86b6c62
Move waiting for migrations to complete till after legacy service start
rudolf Aug 21, 2019
b2cfb14
Fix ESArchiver's KibanaMigrator
rudolf Aug 21, 2019
6fea102
Fix reload logging config tests
rudolf Aug 21, 2019
ea6486a
Run migrations on savedobjects start
rudolf Aug 22, 2019
4b2e03e
Fix env tests
rudolf Aug 22, 2019
4c6f865
Fix and make legacy tests more robust/isolated
rudolf Aug 22, 2019
c06f07a
Cleanup code
rudolf Aug 23, 2019
8c44805
Fix invalid config test
rudolf Aug 23, 2019
f41538c
Fix SavedObject Migrations logging test
rudolf Aug 26, 2019
6b9f2c4
Merge branch 'master' into server-saved-objects-service
rudolf Aug 26, 2019
cec7235
SavedObjectsService tests
rudolf Aug 26, 2019
c0edd70
Lifecycle logging and improve getting kibanaConfig instance
rudolf Aug 26, 2019
ea77bd9
Fix awaitMigration bug and test
rudolf Aug 27, 2019
d27d816
Fix typing error
rudolf Aug 27, 2019
e8b0d12
Merge branch 'master' into server-saved-objects-service
rudolf Aug 28, 2019
6e1a527
Review comments
rudolf Aug 28, 2019
172209c
Remove unecessary KibanaConfig class
rudolf Sep 3, 2019
8b7835b
Merge branch 'master' into server-saved-objects-service
rudolf Sep 18, 2019
da017f7
Move legacy plugin config extension, specs, uiExports entirely into Core
rudolf Sep 20, 2019
0371aa3
Fix config deprecation test
rudolf Sep 20, 2019
04bb2df
Merge branch 'master' into server-saved-objects-service
rudolf Sep 20, 2019
cd759ea
Use existing logger mock
rudolf Sep 23, 2019
c2b1fd0
Create SavedObjectsConfig for migration config
rudolf Sep 23, 2019
03ce480
Define KibanaMigratorContract type
rudolf Sep 23, 2019
e14d0a4
Merge branch 'master' into server-saved-objects-service
rudolf Sep 23, 2019
d87836f
KibanaMigratorContract -> IKibanaMigrator + docs improvements
rudolf Sep 24, 2019
f7effb8
Fix esArchiver's KibanaMigrator
rudolf Sep 24, 2019
98aec57
Fix plugin generator integration test
rudolf Sep 25, 2019
da6a902
Merge branch 'master' into server-saved-objects-service
rudolf Sep 25, 2019
f783d48
Merge branch 'master' into server-saved-objects-service
rudolf Sep 25, 2019
14b16d4
Merge branch 'master' into server-saved-objects-service
rudolf Sep 27, 2019
870447e
ConfigServiceContract -> IConfigService
rudolf Sep 27, 2019
80b3ec8
Address review comments
rudolf Sep 27, 2019
3cd4cd2
Review nits
rudolf Sep 27, 2019
a214e44
Document migrations.skip config
rudolf Sep 27, 2019
38adb1a
Review comments continued...
rudolf Sep 27, 2019
86c9eef
awaitMigrations -> runMigrations
rudolf Sep 27, 2019
6e39936
Merge branch 'master' into server-saved-objects-service
rudolf Sep 30, 2019
6980d6a
Type improvements
rudolf Sep 30, 2019
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
9 changes: 6 additions & 3 deletions src/core/server/config/config_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import { ObjectToConfigAdapter } from './object_to_config_adapter';

import { IConfigService } from './config_service';

const createConfigServiceMock = () => {
const createConfigServiceMock = ({
atPath = {},
getConfig$ = {},
}: { atPath?: unknown; getConfig$?: Record<string, any> } = {}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

with this approach atPath loses type safety. const configService = configServiceMock.create({ atPath: 1 });

const mocked: jest.Mocked<IConfigService> = {
atPath: jest.fn(),
getConfig$: jest.fn(),
Expand All @@ -32,8 +35,8 @@ const createConfigServiceMock = () => {
isEnabledAtPath: jest.fn(),
setSchema: jest.fn(),
};
mocked.atPath.mockReturnValue(new BehaviorSubject({}));
mocked.getConfig$.mockReturnValue(new BehaviorSubject(new ObjectToConfigAdapter({})));
mocked.atPath.mockReturnValue(new BehaviorSubject(atPath));
mocked.getConfig$.mockReturnValue(new BehaviorSubject(new ObjectToConfigAdapter(getConfig$)));
mocked.getUsedPaths.mockResolvedValue([]);
mocked.getUnusedPaths.mockResolvedValue([]);
mocked.isEnabledAtPath.mockResolvedValue(true);
Expand Down
18 changes: 9 additions & 9 deletions src/core/server/core_context.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import { loggingServiceMock } from './logging/logging_service.mock';
import { configServiceMock } from './config/config_service.mock';
import { ILoggingService } from './logging';

function create(
env?: Env,
logger?: jest.Mocked<ILoggingService>,
configService?: jest.Mocked<IConfigService>
): CoreContext {
env = env || Env.createDefault(getEnvOptions());
logger = logger || loggingServiceMock.create();
configService = configService || configServiceMock.create();

function create({
env = Env.createDefault(getEnvOptions()),
logger = loggingServiceMock.create(),
configService = configServiceMock.create(),
}: {
env?: Env;
logger?: jest.Mocked<ILoggingService>;
configService?: jest.Mocked<IConfigService>;
} = {}): CoreContext {
return { coreId: Symbol(), env, logger, configService };
}

Expand Down
47 changes: 39 additions & 8 deletions src/core/server/saved_objects/saved_objects_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ import { mockCoreContext } from '../core_context.mock';
import { KibanaMigrator } from './migrations/kibana/kibana_migrator';
import { of } from 'rxjs';
import elasticsearch from 'elasticsearch';

let coreContext: CoreContext;
beforeEach(() => {
coreContext = mockCoreContext.create();
});
import { Env } from '../config';
import { configServiceMock } from '../mocks';

afterEach(() => {
jest.clearAllMocks();
Expand All @@ -38,6 +35,7 @@ afterEach(() => {
describe('SavedObjectsService', () => {
describe('#setup()', () => {
it('creates a KibanaMigrator which retries NoConnections errors from callAsInternalUser', async () => {
const coreContext = mockCoreContext.create();
let i = 0;
const clusterClient = {
callAsInternalUser: jest
Expand All @@ -64,7 +62,40 @@ describe('SavedObjectsService', () => {
});

describe('#start()', () => {
it('skips KibanaMigrator migrations when --optimize=true', async () => {
const coreContext = mockCoreContext.create({
env: ({ cliArgs: { optimize: true }, packageInfo: { version: 'x.x.x' } } as unknown) as Env,
});
const soService = new SavedObjectsService(coreContext);
const coreSetup = ({
elasticsearch: { adminClient$: of({ callAsInternalUser: jest.fn() }) },
legacy: { uiExports: {}, pluginExtendedConfig: {} },
} as unknown) as SavedObjectsSetupDeps;

await soService.setup(coreSetup);
const migrator = (KibanaMigrator as jest.Mock<KibanaMigrator>).mock.instances[0];
await soService.start({});
expect(migrator.awaitMigration).toHaveBeenCalledWith(true);
});

it('skips KibanaMigrator migrations when migrations.skip=true', async () => {
const configService = configServiceMock.create({ atPath: { skip: true } });
const coreContext = mockCoreContext.create({ configService });
const soService = new SavedObjectsService(coreContext);
const coreSetup = ({
elasticsearch: { adminClient$: of({ callAsInternalUser: jest.fn() }) },
legacy: { uiExports: {}, pluginExtendedConfig: {} },
} as unknown) as SavedObjectsSetupDeps;

await soService.setup(coreSetup);
const migrator = (KibanaMigrator as jest.Mock<KibanaMigrator>).mock.instances[0];
await soService.start({});
expect(migrator.awaitMigration).toHaveBeenCalledWith(true);
});

it('resolves with KibanaMigrator after waiting for migrations to complete', async () => {
rudolf marked this conversation as resolved.
Show resolved Hide resolved
const configService = configServiceMock.create({ atPath: { skip: false } });
const coreContext = mockCoreContext.create({ configService });
const soService = new SavedObjectsService(coreContext);
const coreSetup = ({
elasticsearch: { adminClient$: of({ callAsInternalUser: jest.fn() }) },
Expand All @@ -74,9 +105,9 @@ describe('SavedObjectsService', () => {
await soService.setup(coreSetup);
const migrator = (KibanaMigrator as jest.Mock<KibanaMigrator>).mock.instances[0];
expect(migrator.awaitMigration).toHaveBeenCalledTimes(0);
await soService.start({}).then(result => {
expect(result.migrator).toBeInstanceOf(KibanaMigrator);
});
const startContract = await soService.start({});
expect(startContract.migrator).toBeInstanceOf(KibanaMigrator);
expect(migrator.awaitMigration).toHaveBeenCalledWith(false);
expect(migrator.awaitMigration).toHaveBeenCalledTimes(1);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/saved_objects/saved_objects_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class SavedObjectsService
config: coreSetup.legacy.pluginExtendedConfig,
savedObjectsConfig,
kibanaConfig,
callCluster: retryCallCluster(adminClient.callAsInternalUser.bind(adminClient)),
callCluster: retryCallCluster(adminClient.callAsInternalUser),
});

return ({} as any) as Promise<SavedObjectsServiceSetup>;
mshustov marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 4 additions & 1 deletion src/es_archiver/lib/indices/kibana_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export async function migrateKibanaIndex({ client, log, kibanaPluginIds }) {
error: log.error.bind(log),
},
version: kibanaVersion,
...uiExports,
savedObjectSchemas: uiExports.savedObjectSchemas,
savedObjectMappings: uiExports.savedObjectMappings,
savedObjectMigrations: uiExports.savedObjectMigrations,
savedObjectValidations: uiExports.savedObjectValidations,
callCluster: (path, ...args) => _.get(client, path).call(client, ...args),
};

Expand Down