Skip to content

Commit

Permalink
Merge branch 'master' into 97247
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored May 17, 2021
2 parents d6c6765 + 391e9aa commit 3d00b8e
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The version in which this object type is being converted to a multi-namespace ty
<b>Signature:</b>

```typescript
convertToMultiNamespaceTypeVersion?: string;
readonly convertToMultiNamespaceTypeVersion?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ logger instance to be used by the migration handler
<b>Signature:</b>

```typescript
log: SavedObjectsMigrationLogger;
readonly log: SavedObjectsMigrationLogger;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The migration version that this migration function is defined for
<b>Signature:</b>

```typescript
migrationVersion: string;
readonly migrationVersion: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -661,13 +661,14 @@ function wrapWithTry(
migrationFn: SavedObjectMigrationFn,
log: Logger
) {
const context = Object.freeze({
log: new MigrationLogger(log),
migrationVersion: version,
convertToMultiNamespaceTypeVersion: type.convertToMultiNamespaceTypeVersion,
});

return function tryTransformDoc(doc: SavedObjectUnsanitizedDoc) {
try {
const context = {
log: new MigrationLogger(log),
migrationVersion: version,
convertToMultiNamespaceTypeVersion: type.convertToMultiNamespaceTypeVersion,
};
const result = migrationFn(doc, context);

// A basic sanity check to help migration authors detect basic errors
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/saved_objects/migrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ export interface SavedObjectMigrationContext {
/**
* logger instance to be used by the migration handler
*/
log: SavedObjectsMigrationLogger;
readonly log: SavedObjectsMigrationLogger;
/**
* The migration version that this migration function is defined for
*/
migrationVersion: string;
readonly migrationVersion: string;
/**
* The version in which this object type is being converted to a multi-namespace type
*/
convertToMultiNamespaceTypeVersion?: string;
readonly convertToMultiNamespaceTypeVersion?: string;
}

/**
Expand Down
25 changes: 25 additions & 0 deletions src/core/server/saved_objects/migrationsv2/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,31 @@ describe('migrations v2 model', () => {
});

describe('model transitions from', () => {
it('transition returns new state', () => {
const initState: State = {
...baseState,
controlState: 'INIT',
currentAlias: '.kibana',
versionAlias: '.kibana_7.11.0',
versionIndex: '.kibana_7.11.0_001',
};

const res: ResponseType<'INIT'> = Either.right({
'.kibana_7.11.0_001': {
aliases: {
'.kibana': {},
'.kibana_7.11.0': {},
},
mappings: {
properties: {},
},
settings: {},
},
});
const newState = model(initState, res);
expect(newState).not.toBe(initState);
});

describe('INIT', () => {
const initState: State = {
...baseState,
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/saved_objects/migrationsv2/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { gt, valid } from 'semver';
import * as Either from 'fp-ts/lib/Either';
import * as Option from 'fp-ts/lib/Option';
import { cloneDeep } from 'lodash';

import { AliasAction, FetchIndexResponse, isLeftTypeof, RetryableEsClientError } from './actions';
import { AllActionStates, InitState, State } from './types';
import { IndexMapping } from '../mappings';
Expand Down Expand Up @@ -187,7 +187,7 @@ export const model = (currentState: State, resW: ResponseType<AllActionStates>):
// control state using:
// `const res = resW as ResponseType<typeof stateP.controlState>;`

let stateP: State = cloneDeep(currentState);
let stateP: State = currentState;

// Handle retryable_es_client_errors. Other left values need to be handled
// by the control state specific code below.
Expand Down
5 changes: 3 additions & 2 deletions src/core/server/saved_objects/migrationsv2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export interface LegacyDeleteState extends LegacyBaseState {
readonly controlState: 'LEGACY_DELETE';
}

export type State =
export type State = Readonly<
| FatalState
| InitState
| DoneState
Expand Down Expand Up @@ -411,7 +411,8 @@ export type State =
| LegacySetWriteBlockState
| LegacyReindexState
| LegacyReindexWaitForTaskState
| LegacyDeleteState;
| LegacyDeleteState
>;

export type AllControlStates = State['controlState'];
/**
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2152,9 +2152,9 @@ export interface SavedObjectExportBaseOptions {

// @public
export interface SavedObjectMigrationContext {
convertToMultiNamespaceTypeVersion?: string;
log: SavedObjectsMigrationLogger;
migrationVersion: string;
readonly convertToMultiNamespaceTypeVersion?: string;
readonly log: SavedObjectsMigrationLogger;
readonly migrationVersion: string;
}

// @public
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/dashboard/common/saved_dashboard_references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import semverSatisfies from 'semver/functions/satisfies';
import Semver from 'semver';
import { SavedObjectAttributes, SavedObjectReference } from '../../../core/types';
import { DashboardContainerStateWithType, DashboardPanelState } from './types';
import { EmbeddablePersistableStateService } from '../../embeddable/common/types';
Expand All @@ -24,7 +23,7 @@ export interface SavedObjectAttributesAndReferences {
}

const isPre730Panel = (panel: Record<string, string>): boolean => {
return 'version' in panel ? semverSatisfies(panel.version, '<7.3') : true;
return 'version' in panel ? Semver.gt('7.3.0', panel.version) : true;
};

function dashboardAttributesToState(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { act } from 'react-dom/test-utils';
import { setup, SetupResult, getProcessorValue } from './processor.helpers';

// Default parameter values automatically added to the registered domain processor when saved
const defaultRegisteredDomainParameters = {
description: undefined,
if: undefined,
ignore_missing: undefined,
ignore_failure: undefined,
};

const REGISTERED_DOMAIN_TYPE = 'registered_domain';

describe('Processor: Registered Domain', () => {
let onUpdate: jest.Mock;
let testBed: SetupResult;

beforeAll(() => {
jest.useFakeTimers();
});

afterAll(() => {
jest.useRealTimers();
});

beforeEach(async () => {
onUpdate = jest.fn();

await act(async () => {
testBed = await setup({
value: {
processors: [],
},
onFlyoutOpen: jest.fn(),
onUpdate,
});
});

testBed.component.update();

// Open flyout to add new processor
testBed.actions.addProcessor();
// Add type (the other fields are not visible until a type is selected)
await testBed.actions.addProcessorType(REGISTERED_DOMAIN_TYPE);
});

test('prevents form submission if required fields are not provided', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Click submit button with only the type defined
await saveNewProcessor();

// Expect form error as "field" is required parameter
expect(form.getErrorsMessages()).toEqual(['A field value is required.']);
});

test('saves with default parameter values', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');
// Save the field
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, REGISTERED_DOMAIN_TYPE);
expect(processors[0][REGISTERED_DOMAIN_TYPE]).toEqual({
field: 'field_1',
...defaultRegisteredDomainParameters,
});
});

test('should still send ignore_missing:false when the toggle is disabled', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');

// Disable ignore missing toggle
form.toggleEuiSwitch('ignoreMissingSwitch.input');

// Save the field with new changes
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, REGISTERED_DOMAIN_TYPE);
expect(processors[0][REGISTERED_DOMAIN_TYPE]).toEqual({
...defaultRegisteredDomainParameters,
field: 'field_1',
ignore_missing: false,
});
});

test('allows optional parameters to be set', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');

// Set optional parameteres
form.setInputValue('targetField.input', 'target_field');

// Save the field with new changes
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, REGISTERED_DOMAIN_TYPE);
expect(processors[0][REGISTERED_DOMAIN_TYPE]).toEqual({
field: 'field_1',
target_field: 'target_field',
...defaultRegisteredDomainParameters,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export { Json } from './json';
export { Kv } from './kv';
export { Lowercase } from './lowercase';
export { Pipeline } from './pipeline';
export { RegisteredDomain } from './registered_domain';
export { Remove } from './remove';
export { Rename } from './rename';
export { Script } from './script';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';

import { from } from './shared';
import { FieldNameField } from './common_fields/field_name_field';
import { TargetField } from './common_fields/target_field';
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
import { SerializerFunc } from '../../../../../../shared_imports';

export const RegisteredDomain: FunctionComponent = () => {
return (
<>
<FieldNameField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.registeredDomain.fieldNameHelpText',
{ defaultMessage: 'Field containing the fully qualified domain name.' }
)}
/>

<TargetField />

<IgnoreMissingField
defaultValue={true}
serializer={from.undefinedIfValue(true) as SerializerFunc<boolean>}
/>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
Kv,
Lowercase,
Pipeline,
RegisteredDomain,
Remove,
Rename,
Script,
Expand Down Expand Up @@ -518,6 +519,28 @@ export const mapProcessorTypeToDescriptor: MapProcessorTypeToDescriptor = {
},
}),
},
registered_domain: {
FieldsComponent: RegisteredDomain,
docLinkPath: '/registered-domain-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.registeredDomain', {
defaultMessage: 'Registered domain',
}),
typeDescription: i18n.translate(
'xpack.ingestPipelines.processors.description.registeredDomain',
{
defaultMessage:
'Extracts the registered domain (effective top-level domain), sub-domain, and top-level domain from a fully qualified domain name.',
}
),
getDefaultDescription: ({ field }) =>
i18n.translate('xpack.ingestPipelines.processors.defaultDescription.registeredDomain', {
defaultMessage:
'Extracts the registered domain, sub-domain, and top-level domain from "{field}"',
values: {
field,
},
}),
},
remove: {
FieldsComponent: Remove,
docLinkPath: '/remove-processor.html',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_pipelines/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export {
ValidationConfig,
useFormData,
FormOptions,
SerializerFunc,
} from '../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib';

export {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions x-pack/plugins/reporting/public/components/report_listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ class ReportListingUi extends Component<Props, State> {
return (
<Fragment>
<EuiBasicTable
tableCaption={i18n.translate('xpack.reporting.listing.table.captionDescription', {
defaultMessage: 'Reports generated in Kibana applications',
})}
itemId="id"
items={this.state.jobs}
loading={this.state.isLoading}
Expand Down

0 comments on commit 3d00b8e

Please sign in to comment.