Skip to content

Commit

Permalink
Merge branch 'master' into case-api-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored May 11, 2020
2 parents 77e142d + b180fd3 commit 83d71bc
Show file tree
Hide file tree
Showing 58 changed files with 1,211 additions and 496 deletions.
2 changes: 1 addition & 1 deletion .backportrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"targetPRLabels": ["backport"],
"branchLabelMapping": {
"^v7.8.0$": "7.x",
"^v7.9.0$": "7.x",
"^v(\\d+).(\\d+).\\d+$": "$1.$2"
}
}
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-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsMigrationLogger](./kibana-plugin-core-server.savedobjectsmigrationlogger.md) &gt; [error](./kibana-plugin-core-server.savedobjectsmigrationlogger.error.md)

## SavedObjectsMigrationLogger.error property

<b>Signature:</b>

```typescript
error: (msg: string, meta: LogMeta) => void;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface SavedObjectsMigrationLogger
| Property | Type | Description |
| --- | --- | --- |
| [debug](./kibana-plugin-core-server.savedobjectsmigrationlogger.debug.md) | <code>(msg: string) =&gt; void</code> | |
| [error](./kibana-plugin-core-server.savedobjectsmigrationlogger.error.md) | <code>(msg: string, meta: LogMeta) =&gt; void</code> | |
| [info](./kibana-plugin-core-server.savedobjectsmigrationlogger.info.md) | <code>(msg: string) =&gt; void</code> | |
| [warn](./kibana-plugin-core-server.savedobjectsmigrationlogger.warn.md) | <code>(msg: string) =&gt; void</code> | |
| [warning](./kibana-plugin-core-server.savedobjectsmigrationlogger.warning.md) | <code>(msg: string) =&gt; void</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- 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; [IIndexPattern](./kibana-plugin-plugins-data-server.iindexpattern.md) &gt; [getTimeField](./kibana-plugin-plugins-data-server.iindexpattern.gettimefield.md)

## IIndexPattern.getTimeField() method

<b>Signature:</b>

```typescript
getTimeField?(): IFieldType | undefined;
```
<b>Returns:</b>
`IFieldType | undefined`
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('DocumentMigrator', () => {
migrationVersion: { dog: '10.2.0' },
})
).toThrow(
/Document "smelly" has property "dog" which belongs to a more recent version of Kibana \(10\.2\.0\)/i
/Document "smelly" has property "dog" which belongs to a more recent version of Kibana \[10\.2\.0\]\. The last known version is \[undefined\]/i
);
});

Expand All @@ -315,7 +315,7 @@ describe('DocumentMigrator', () => {
migrationVersion: { dawg: '1.2.4' },
})
).toThrow(
/Document "fleabag" has property "dawg" which belongs to a more recent version of Kibana \(1\.2\.4\)/i
/Document "fleabag" has property "dawg" which belongs to a more recent version of Kibana \[1\.2\.4\]\. The last known version is \[1\.2\.3\]/i
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function nextUnmigratedProp(doc: SavedObjectUnsanitizedDoc, migrations: ActiveMi
if (docVersion && (!latestVersion || Semver.gt(docVersion, latestVersion))) {
throw Boom.badData(
`Document "${doc.id}" has property "${p}" which belongs to a more recent` +
` version of Kibana (${docVersion}).`,
` version of Kibana [${docVersion}]. The last known version is [${latestVersion}]`,
doc
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ async function migrateSourceToDest(context: Context) {
await Index.write(
callCluster,
dest.indexName,
migrateRawDocs(serializer, documentMigrator.migrate, docs)
migrateRawDocs(serializer, documentMigrator.migrate, docs, log)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import _ from 'lodash';
import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry';
import { SavedObjectsSerializer } from '../../serialization';
import { migrateRawDocs } from './migrate_raw_docs';
import { createSavedObjectsMigrationLoggerMock } from '../../migrations/mocks';

describe('migrateRawDocs', () => {
test('converts raw docs to saved objects', async () => {
Expand All @@ -31,7 +32,8 @@ describe('migrateRawDocs', () => {
[
{ _id: 'a:b', _source: { type: 'a', a: { name: 'AAA' } } },
{ _id: 'c:d', _source: { type: 'c', c: { name: 'DDD' } } },
]
],
createSavedObjectsMigrationLoggerMock()
);

expect(result).toEqual([
Expand All @@ -48,7 +50,8 @@ describe('migrateRawDocs', () => {
expect(transform).toHaveBeenCalled();
});

test('passes invalid docs through untouched', async () => {
test('passes invalid docs through untouched and logs error', async () => {
const logger = createSavedObjectsMigrationLoggerMock();
const transform = jest.fn<any, any>((doc: any) =>
_.set(_.cloneDeep(doc), 'attributes.name', 'TADA')
);
Expand All @@ -58,7 +61,8 @@ describe('migrateRawDocs', () => {
[
{ _id: 'foo:b', _source: { type: 'a', a: { name: 'AAA' } } },
{ _id: 'c:d', _source: { type: 'c', c: { name: 'DDD' } } },
]
],
logger
);

expect(result).toEqual([
Expand All @@ -82,5 +86,7 @@ describe('migrateRawDocs', () => {
},
],
]);

expect(logger.error).toBeCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import { SavedObjectsRawDoc, SavedObjectsSerializer } from '../../serialization';
import { TransformFn } from './document_migrator';
import { SavedObjectsMigrationLogger } from '.';

/**
* Applies the specified migration function to every saved object document in the list
Expand All @@ -35,7 +36,8 @@ import { TransformFn } from './document_migrator';
export function migrateRawDocs(
serializer: SavedObjectsSerializer,
migrateDoc: TransformFn,
rawDocs: SavedObjectsRawDoc[]
rawDocs: SavedObjectsRawDoc[],
log: SavedObjectsMigrationLogger
): SavedObjectsRawDoc[] {
return rawDocs.map(raw => {
if (serializer.isRawSavedObject(raw)) {
Expand All @@ -47,6 +49,10 @@ export function migrateRawDocs(
});
}

log.error(
`Error: Unable to migrate the corrupt Saved Object document ${raw._id}. To prevent Kibana from performing a migration on every restart, please delete or fix this document by ensuring that the namespace and type in the document's id matches the values in the namespace and type fields.`,
{ rawDocument: raw }
);
return raw;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@

import _ from 'lodash';
import { coordinateMigration } from './migration_coordinator';
import { createSavedObjectsMigrationLoggerMock } from '../mocks';

describe('coordinateMigration', () => {
const log = {
debug: jest.fn(),
warning: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
};
const log = createSavedObjectsMigrationLoggerMock();

test('waits for isMigrated, if there is an index conflict', async () => {
const pollInterval = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { Logger } from 'src/core/server/logging';
import { Logger, LogMeta } from '../../../logging';

/*
* This file provides a helper class for ensuring that all logging
Expand All @@ -35,6 +35,7 @@ export interface SavedObjectsMigrationLogger {
*/
warning: (msg: string) => void;
warn: (msg: string) => void;
error: (msg: string, meta: LogMeta) => void;
}

export class MigrationLogger implements SavedObjectsMigrationLogger {
Expand All @@ -48,4 +49,5 @@ export class MigrationLogger implements SavedObjectsMigrationLogger {
public debug = (msg: string) => this.logger.debug(msg);
public warning = (msg: string) => this.logger.warn(msg);
public warn = (msg: string) => this.logger.warn(msg);
public error = (msg: string, meta: LogMeta) => this.logger.error(msg, meta);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* (the shape of the mappings and documents in the index).
*/

import { Logger } from 'src/core/server/logging';
import { KibanaConfigType } from 'src/core/server/kibana_config';
import { BehaviorSubject } from 'rxjs';
import { Logger } from '../../../logging';
import { IndexMapping, SavedObjectsTypeMappingDefinitions } from '../../mappings';
import { SavedObjectUnsanitizedDoc, SavedObjectsSerializer } from '../../serialization';
import { docValidator, PropertyValidators } from '../../validation';
Expand Down
5 changes: 3 additions & 2 deletions src/core/server/saved_objects/migrations/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@
import { SavedObjectMigrationContext } from './types';
import { SavedObjectsMigrationLogger } from './core';

const createLoggerMock = (): jest.Mocked<SavedObjectsMigrationLogger> => {
export const createSavedObjectsMigrationLoggerMock = (): jest.Mocked<SavedObjectsMigrationLogger> => {
const mock = {
debug: jest.fn(),
info: jest.fn(),
warning: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
};

return mock;
};

const createContextMock = (): jest.Mocked<SavedObjectMigrationContext> => {
const mock = {
log: createLoggerMock(),
log: createSavedObjectsMigrationLoggerMock(),
};
return mock;
};
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ import { IngestGetPipelineParams } from 'elasticsearch';
import { IngestPutPipelineParams } from 'elasticsearch';
import { IngestSimulateParams } from 'elasticsearch';
import { KibanaConfigType } from 'src/core/server/kibana_config';
import { Logger as Logger_2 } from 'src/core/server/logging';
import { MGetParams } from 'elasticsearch';
import { MGetResponse } from 'elasticsearch';
import { MSearchParams } from 'elasticsearch';
Expand Down Expand Up @@ -2169,6 +2168,8 @@ export interface SavedObjectsMigrationLogger {
// (undocumented)
debug: (msg: string) => void;
// (undocumented)
error: (msg: string, meta: LogMeta) => void;
// (undocumented)
info: (msg: string) => void;
// (undocumented)
warn: (msg: string) => void;
Expand Down
19 changes: 16 additions & 3 deletions src/legacy/ui/public/new_platform/new_platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jest.mock('history');
import { setRootControllerMock, historyMock } from './new_platform.test.mocks';
import { legacyAppRegister, __reset__, __setup__, __start__ } from './new_platform';
import { coreMock } from '../../../../core/public/mocks';
import { AppMount } from '../../../../core/public';

describe('ui/new_platform', () => {
describe('legacyAppRegister', () => {
Expand All @@ -33,7 +34,7 @@ describe('ui/new_platform', () => {

const registerApp = () => {
const unmountMock = jest.fn();
const mountMock = jest.fn(() => unmountMock);
const mountMock = jest.fn<ReturnType<AppMount>, Parameters<AppMount>>(() => unmountMock);
legacyAppRegister({
id: 'test',
title: 'Test',
Expand Down Expand Up @@ -62,13 +63,25 @@ describe('ui/new_platform', () => {

controller(scopeMock, elementMock);
expect(mountMock).toHaveBeenCalledWith({
element: elementMock[0],
element: expect.any(HTMLElement),
appBasePath: '/test/base/path/app/test',
onAppLeave: expect.any(Function),
history: historyMock,
});
});

test('app is mounted in new div inside containing element', () => {
const { mountMock } = registerApp();
const controller = setRootControllerMock.mock.calls[0][1];
const scopeMock = { $on: jest.fn() };
const elementMock = [document.createElement('div')];

controller(scopeMock, elementMock);

const { element } = mountMock.mock.calls[0][0];
expect(element.parentElement).toEqual(elementMock[0]);
});

test('controller calls deprecated context app.mount when invoked', () => {
const unmountMock = jest.fn();
// Two arguments changes how this is called.
Expand All @@ -84,7 +97,7 @@ describe('ui/new_platform', () => {

controller(scopeMock, elementMock);
expect(mountMock).toHaveBeenCalledWith(expect.any(Object), {
element: elementMock[0],
element: expect.any(HTMLElement),
appBasePath: '/test/base/path/app/test',
onAppLeave: expect.any(Function),
history: historyMock,
Expand Down
3 changes: 2 additions & 1 deletion src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export const legacyAppRegister = (app: App<any>) => {
legacyAppRegistered = true;

require('ui/chrome').setRootController(app.id, ($scope: IScope, $element: JQLite) => {
const element = $element[0];
const element = document.createElement('div');
$element[0].appendChild(element);

// Root controller cannot return a Promise so use an internal async function and call it immediately
(async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dashboard/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export {
} from './application';
export { DashboardConstants, createDashboardEditUrl } from './dashboard_constants';

export { DashboardStart } from './plugin';
export { DashboardStart, DashboardUrlGenerator } from './plugin';
export { DASHBOARD_APP_URL_GENERATOR } from './url_generator';

export function plugin(initializerContext: PluginInitializerContext) {
Expand Down
19 changes: 15 additions & 4 deletions src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ import {
DataPublicPluginSetup,
esFilters,
} from '../../../plugins/data/public';
import { SharePluginSetup, SharePluginStart } from '../../../plugins/share/public';
import {
SharePluginSetup,
SharePluginStart,
UrlGeneratorContract,
} from '../../../plugins/share/public';
import { UiActionsSetup, UiActionsStart } from '../../../plugins/ui_actions/public';

import { Start as InspectorStartContract } from '../../../plugins/inspector/public';
Expand Down Expand Up @@ -77,7 +81,7 @@ import {
import {
DashboardAppLinkGeneratorState,
DASHBOARD_APP_URL_GENERATOR,
createDirectAccessDashboardLinkGenerator,
createDashboardUrlGenerator,
} from './url_generator';
import { createSavedDashboardLoader } from './saved_dashboards';
import { DashboardConstants } from './dashboard_constants';
Expand All @@ -89,6 +93,8 @@ declare module '../../share/public' {
}
}

export type DashboardUrlGenerator = UrlGeneratorContract<typeof DASHBOARD_APP_URL_GENERATOR>;

interface SetupDependencies {
data: DataPublicPluginSetup;
embeddable: EmbeddableSetup;
Expand All @@ -111,8 +117,10 @@ interface StartDependencies {
}

export type Setup = void;

export interface DashboardStart {
getSavedDashboardLoader: () => SavedObjectLoader;
dashboardUrlGenerator?: DashboardUrlGenerator;
}

declare module '../../../plugins/ui_actions/public' {
Expand All @@ -130,6 +138,8 @@ export class DashboardPlugin
private appStateUpdater = new BehaviorSubject<AngularRenderedAppUpdater>(() => ({}));
private stopUrlTracking: (() => void) | undefined = undefined;

private dashboardUrlGenerator?: DashboardUrlGenerator;

public setup(
core: CoreSetup<StartDependencies, DashboardStart>,
{ share, uiActions, embeddable, home, kibanaLegacy, data, usageCollection }: SetupDependencies
Expand All @@ -140,8 +150,8 @@ export class DashboardPlugin
const startServices = core.getStartServices();

if (share) {
share.urlGenerators.registerUrlGenerator(
createDirectAccessDashboardLinkGenerator(async () => {
this.dashboardUrlGenerator = share.urlGenerators.registerUrlGenerator(
createDashboardUrlGenerator(async () => {
const [coreStart, , selfStart] = await startServices;
return {
appBasePath: coreStart.application.getUrlForApp('dashboard'),
Expand Down Expand Up @@ -325,6 +335,7 @@ export class DashboardPlugin
});
return {
getSavedDashboardLoader: () => savedDashboardLoader,
dashboardUrlGenerator: this.dashboardUrlGenerator,
};
}

Expand Down
Loading

0 comments on commit 83d71bc

Please sign in to comment.