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

[Ingest pipelines] add support for registered_domain processor #99643

Merged
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