Skip to content

Commit

Permalink
Merge branch '7.9' into backport/7.9/pr-76079
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Aug 31, 2020
2 parents 5f20546 + bbb51b5 commit aee259c
Show file tree
Hide file tree
Showing 109 changed files with 966 additions and 263 deletions.
2 changes: 1 addition & 1 deletion docs/developer/getting-started/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ you can switch to the correct version when using nvm by running:
nvm use
----

Install the latest version of https://yarnpkg.com[yarn].
Install the latest version of https://classic.yarnpkg.com/en/docs/install[yarn v1].

Bootstrap {kib} and install all the dependencies:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ export interface SavedObjectsBulkCreateObject<T = unknown>
| [migrationVersion](./kibana-plugin-core-server.savedobjectsbulkcreateobject.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
| [references](./kibana-plugin-core-server.savedobjectsbulkcreateobject.references.md) | <code>SavedObjectReference[]</code> | |
| [type](./kibana-plugin-core-server.savedobjectsbulkcreateobject.type.md) | <code>string</code> | |
| [version](./kibana-plugin-core-server.savedobjectsbulkcreateobject.version.md) | <code>string</code> | |

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions
| [overwrite](./kibana-plugin-core-server.savedobjectscreateoptions.overwrite.md) | <code>boolean</code> | Overwrite existing documents (defaults to false) |
| [references](./kibana-plugin-core-server.savedobjectscreateoptions.references.md) | <code>SavedObjectReference[]</code> | |
| [refresh](./kibana-plugin-core-server.savedobjectscreateoptions.refresh.md) | <code>MutatingOperationRefreshSetting</code> | The Elasticsearch Refresh setting for this operation |
| [version](./kibana-plugin-core-server.savedobjectscreateoptions.version.md) | <code>string</code> | An opaque version number which changes on each successful write operation. Can be used in conjunction with <code>overwrite</code> for implementing optimistic concurrency control. |

This file was deleted.

7 changes: 1 addition & 6 deletions src/core/server/saved_objects/import/import_saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
SavedObjectsImportOptions,
} from './types';
import { validateReferences } from './validate_references';
import { SavedObject } from '../types';

/**
* Import saved objects from given stream. See the {@link SavedObjectsImportOptions | options} for more
Expand Down Expand Up @@ -68,7 +67,7 @@ export async function importSavedObjectsFromStream({
}

// Create objects in bulk
const bulkCreateResult = await savedObjectsClient.bulkCreate(omitVersion(filteredObjects), {
const bulkCreateResult = await savedObjectsClient.bulkCreate(filteredObjects, {
overwrite,
namespace,
});
Expand All @@ -83,7 +82,3 @@ export async function importSavedObjectsFromStream({
...(errorAccumulator.length ? { errors: errorAccumulator } : {}),
};
}

export function omitVersion(objects: SavedObject[]): SavedObject[] {
return objects.map(({ version, ...object }) => object);
}
12 changes: 4 additions & 8 deletions src/core/server/saved_objects/import/resolve_import_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
SavedObjectsResolveImportErrorsOptions,
} from './types';
import { validateReferences } from './validate_references';
import { omitVersion } from './import_saved_objects';

/**
* Resolve and return saved object import errors.
Expand Down Expand Up @@ -92,7 +91,7 @@ export async function resolveSavedObjectsImportErrors({
// Bulk create in two batches, overwrites and non-overwrites
const { objectsToOverwrite, objectsToNotOverwrite } = splitOverwrites(filteredObjects, retries);
if (objectsToOverwrite.length) {
const bulkCreateResult = await savedObjectsClient.bulkCreate(omitVersion(objectsToOverwrite), {
const bulkCreateResult = await savedObjectsClient.bulkCreate(objectsToOverwrite, {
overwrite: true,
namespace,
});
Expand All @@ -103,12 +102,9 @@ export async function resolveSavedObjectsImportErrors({
successCount += bulkCreateResult.saved_objects.filter((obj) => !obj.error).length;
}
if (objectsToNotOverwrite.length) {
const bulkCreateResult = await savedObjectsClient.bulkCreate(
omitVersion(objectsToNotOverwrite),
{
namespace,
}
);
const bulkCreateResult = await savedObjectsClient.bulkCreate(objectsToNotOverwrite, {
namespace,
});
errorAccumulator = [
...errorAccumulator,
...extractErrors(bulkCreateResult.saved_objects, objectsToNotOverwrite),
Expand Down
42 changes: 2 additions & 40 deletions src/core/server/saved_objects/service/lib/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,8 @@ describe('SavedObjectsRepository', () => {
{ method, _index = expect.any(String), getId = () => expect.any(String) }
) => {
const body = [];
for (const { type, id, if_primary_term: ifPrimaryTerm, if_seq_no: ifSeqNo } of objects) {
body.push({
[method]: {
_index,
_id: getId(type, id),
...(ifPrimaryTerm && ifSeqNo
? { if_primary_term: expect.any(Number), if_seq_no: expect.any(Number) }
: {}),
},
});
for (const { type, id } of objects) {
body.push({ [method]: { _index, _id: getId(type, id) } });
body.push(expect.any(Object));
}
expectClusterCallArgs({ body });
Expand Down Expand Up @@ -537,27 +529,6 @@ describe('SavedObjectsRepository', () => {
expectClusterCallArgsAction([obj1, obj2], { method: 'index' });
});

it(`should use the ES index method with version if ID and version are defined and overwrite=true`, async () => {
await bulkCreateSuccess(
[
{
...obj1,
version: mockVersion,
},
obj2,
],
{ overwrite: true }
);

const obj1WithSeq = {
...obj1,
if_seq_no: mockVersionProps._seq_no,
if_primary_term: mockVersionProps._primary_term,
};

expectClusterCallArgsAction([obj1WithSeq, obj2], { method: 'index' });
});

it(`should use the ES create method if ID is defined and overwrite=false`, async () => {
await bulkCreateSuccess([obj1, obj2]);
expectClusterCallArgsAction([obj1, obj2], { method: 'create' });
Expand Down Expand Up @@ -1487,15 +1458,6 @@ describe('SavedObjectsRepository', () => {
expectClusterCalls('index');
});

it(`should use the ES index with version if ID and version are defined and overwrite=true`, async () => {
await createSuccess(type, attributes, { id, overwrite: true, version: mockVersion });
expectClusterCalls('index');
expectClusterCallArgs({
if_seq_no: mockVersionProps._seq_no,
if_primary_term: mockVersionProps._primary_term,
});
});

it(`should use the ES create action if ID is defined and overwrite=false`, async () => {
await createSuccess(type, attributes, { id });
expectClusterCalls('create');
Expand Down
12 changes: 1 addition & 11 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ export class SavedObjectsRepository {
overwrite = false,
references = [],
refresh = DEFAULT_REFRESH_SETTING,
version,
} = options;

if (!this._allowedTypes.includes(type)) {
Expand Down Expand Up @@ -261,7 +260,6 @@ export class SavedObjectsRepository {
index: this.getIndexForType(type),
refresh,
body: raw._source,
...(overwrite && version ? decodeRequestVersion(version) : {}),
});

return this._rawToSavedObject<T>({
Expand Down Expand Up @@ -341,12 +339,7 @@ export class SavedObjectsRepository {

let savedObjectNamespace;
let savedObjectNamespaces;
let versionProperties;
const {
esRequestIndex,
object: { version, ...object },
method,
} = expectedBulkGetResult.value;
const { esRequestIndex, object, method } = expectedBulkGetResult.value;
if (esRequestIndex !== undefined) {
const indexFound = bulkGetResponse.status !== 404;
const actualResult = indexFound ? bulkGetResponse.docs[esRequestIndex] : undefined;
Expand All @@ -363,14 +356,12 @@ export class SavedObjectsRepository {
};
}
savedObjectNamespaces = getSavedObjectNamespaces(namespace, docFound && actualResult);
versionProperties = getExpectedVersionProperties(version, actualResult);
} else {
if (this._registry.isSingleNamespace(object.type)) {
savedObjectNamespace = namespace;
} else if (this._registry.isMultiNamespace(object.type)) {
savedObjectNamespaces = getSavedObjectNamespaces(namespace);
}
versionProperties = getExpectedVersionProperties(version);
}

const expectedResult = {
Expand All @@ -395,7 +386,6 @@ export class SavedObjectsRepository {
[method]: {
_id: expectedResult.rawMigratedDoc._id,
_index: this.getIndexForType(object.type),
...(overwrite && versionProperties),
},
},
expectedResult.rawMigratedDoc._source
Expand Down
6 changes: 0 additions & 6 deletions src/core/server/saved_objects/service/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions {
id?: string;
/** Overwrite existing documents (defaults to false) */
overwrite?: boolean;
/**
* An opaque version number which changes on each successful write operation.
* Can be used in conjunction with `overwrite` for implementing optimistic concurrency control.
**/
version?: string;
/** {@inheritDoc SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
references?: SavedObjectReference[];
Expand All @@ -57,7 +52,6 @@ export interface SavedObjectsBulkCreateObject<T = unknown> {
id?: string;
type: string;
attributes: T;
version?: string;
references?: SavedObjectReference[];
/** {@inheritDoc SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
Expand Down
3 changes: 0 additions & 3 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1945,8 +1945,6 @@ export interface SavedObjectsBulkCreateObject<T = unknown> {
references?: SavedObjectReference[];
// (undocumented)
type: string;
// (undocumented)
version?: string;
}

// @public (undocumented)
Expand Down Expand Up @@ -2081,7 +2079,6 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions {
// (undocumented)
references?: SavedObjectReference[];
refresh?: MutatingOperationRefreshSetting;
version?: string;
}

// @public (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function createInstallRoute(
let createResults;
try {
createResults = await context.core.savedObjects.client.bulkCreate(
sampleDataset.savedObjects.map(({ version, ...savedObject }) => savedObject),
sampleDataset.savedObjects,
{ overwrite: true }
);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@ describe('importDashboards(req)', () => {
savedObjectClient.bulkCreate.mockResolvedValue({ saved_objects: [] });

importedObjects = [
{
id: 'dashboard-01',
type: 'dashboard',
attributes: { panelJSON: '{}' },
references: [],
version: 'foo',
},
{ id: 'dashboard-01', type: 'dashboard', attributes: { panelJSON: '{}' }, references: [] },
{ id: 'panel-01', type: 'visualization', attributes: { visState: '{}' }, references: [] },
];
});

test('should call bulkCreate with each asset, filtering out any version if present', async () => {
test('should call bulkCreate with each asset', async () => {
await importDashboards(savedObjectClient, importedObjects, { overwrite: false, exclude: [] });

expect(savedObjectClient.bulkCreate).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export async function importDashboards(
// docs are not seen as automatically up-to-date.
const docs = objects
.filter((item) => !exclude.includes(item.type))
// filter out any document version, if present
.map(({ version, ...doc }) => ({ ...doc, migrationVersion: doc.migrationVersion || {} }));
.map((doc) => ({ ...doc, migrationVersion: doc.migrationVersion || {} }));

const results = await savedObjectsClient.bulkCreate(docs, { overwrite });
return { objects: results.saved_objects };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const SetupGuide: React.FC = () => (
defaultMessage: 'App Search',
})}
productEuiIcon="logoAppSearch"
standardAuthLink="https://swiftype.com/documentation/app-search/self-managed/security#standard"
elasticsearchNativeAuthLink="https://swiftype.com/documentation/app-search/self-managed/security#elasticsearch-native-realm"
standardAuthLink="https://www.elastic.co/guide/en/app-search/current/security-and-users.html#app-search-self-managed-security-and-user-management-standard"
elasticsearchNativeAuthLink="https://www.elastic.co/guide/en/app-search/current/security-and-users.html#app-search-self-managed-security-and-user-management-elasticsearch-native-realm"
>
<SetBreadcrumbs text="Setup Guide" />
<SendTelemetry action="viewed" metric="setup_guide" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ export const TypeParameter = ({ isMultiField, isRootLevelField, showDocLink = fa
: filterTypesForNonRootFields(FIELD_TYPES_OPTIONS)
}
selectedOptions={typeField.value}
onChange={typeField.setValue}
onChange={(value) => {
if (value.length === 0) {
// Don't allow clearing the type. One must always be selected
return;
}
typeField.setValue(value);
}}
isClearable={false}
data-test-subj="fieldType"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import {
import { deleteKibanaSavedObjectsAssets } from '../../packages/remove';
import { getInstallationObject, savedObjectTypes } from '../../packages';

type SavedObjectToBe = Required<Omit<SavedObjectsBulkCreateObject, 'version'>> & {
type: AssetType;
};
type SavedObjectToBe = Required<SavedObjectsBulkCreateObject> & { type: AssetType };
export type ArchiveAsset = Pick<
SavedObject,
'id' | 'attributes' | 'migrationVersion' | 'references'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const utilityBar = (refetch: inputsModel.Refetch, totalCount: number) => (
<div data-test-subj="mock-utility-bar" />
);

const exceptionsModal = (refetch: inputsModel.Refetch) => (
<div data-test-subj="mock-exceptions-modal" />
);

const eventsViewerDefaultProps = {
browserFields: {},
columns: [],
Expand Down Expand Up @@ -460,4 +464,42 @@ describe('EventsViewer', () => {
});
});
});

describe('exceptions modal', () => {
test('it renders exception modal if "exceptionsModal" callback exists', async () => {
const wrapper = mount(
<TestProviders>
<MockedProvider mocks={mockEventViewerResponse} addTypename={false}>
<EventsViewer
{...eventsViewerDefaultProps}
exceptionsModal={exceptionsModal}
graphEventId=""
/>
</MockedProvider>
</TestProviders>
);

await waitFor(() => {
wrapper.update();

expect(wrapper.find(`[data-test-subj="mock-exceptions-modal"]`).exists()).toBeTruthy();
});
});

test('it does not render exception modal if "exceptionModal" callback does not exist', async () => {
const wrapper = mount(
<TestProviders>
<MockedProvider mocks={mockEventViewerResponse} addTypename={false}>
<EventsViewer {...eventsViewerDefaultProps} graphEventId="" />
</MockedProvider>
</TestProviders>
);

await waitFor(() => {
wrapper.update();

expect(wrapper.find(`[data-test-subj="mock-exceptions-modal"]`).exists()).toBeFalsy();
});
});
});
});
Loading

0 comments on commit aee259c

Please sign in to comment.