forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ingest pipelines] add support for registered_domain processor (elast…
…ic#99643) The Ingest Node Pipelines UI added support to configure a registered domain processor. This processor extracts the registered domain, sub-domain and top-level domain from a fully qualified domain name.
- Loading branch information
1 parent
3e54c46
commit 4fef34e
Showing
5 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
...lic/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ion/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters