Skip to content

Commit eeab9d6

Browse files
authored
Revert "[Fleet] Improve validation for dynamic Kafka topics (#212422)"
This reverts commit 5903c7a.
1 parent 477e2f7 commit eeab9d6

File tree

9 files changed

+8
-76
lines changed

9 files changed

+8
-76
lines changed

src/platform/packages/shared/kbn-doc-links/src/get_doc_links.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
115115
configuration: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/configuring-howto-filebeat.html`,
116116
elasticsearchModule: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-module-elasticsearch.html`,
117117
elasticsearchOutput: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/elasticsearch-output.html`,
118-
kafkaOutput: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/kafka-output.html`,
119118
startup: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-starting.html`,
120119
exportedFields: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/exported-fields.html`,
121120
suricataModule: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-module-suricata.html`,

src/platform/packages/shared/kbn-doc-links/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export interface DocLinks {
7171
readonly configuration: string;
7272
readonly elasticsearchOutput: string;
7373
readonly elasticsearchModule: string;
74-
readonly kafkaOutput: string;
7574
readonly startup: string;
7675
readonly exportedFields: string;
7776
readonly suricataModule: string;

x-pack/platform/plugins/private/translations/translations/fr-FR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19938,6 +19938,7 @@
1993819938
"xpack.fleet.settings.editOutputFlyout.kafkaCompressionTitle": "Compression",
1993919939
"xpack.fleet.settings.editOutputFlyout.kafkaConnectionTypeLabel": "Connexion",
1994019940
"xpack.fleet.settings.editOutputFlyout.kafkaDynamicTopicHelptext": "Sélectionnez un sujet dans la liste. Si un sujet n'est pas disponible, créez un sujet personnalisé.",
19941+
"xpack.fleet.settings.editOutputFlyout.kafkaDynamicTopicLabel": "Sujet du champ",
1994119942
"xpack.fleet.settings.editOutputFlyout.kafkaHeaderKeyInputLabel": "Clé",
1994219943
"xpack.fleet.settings.editOutputFlyout.kafkaHeadersTitle": "En-têtes",
1994319944
"xpack.fleet.settings.editOutputFlyout.kafkaHeaderValueInputLabel": "Valeur",

x-pack/platform/plugins/private/translations/translations/ja-JP.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19917,6 +19917,7 @@
1991719917
"xpack.fleet.settings.editOutputFlyout.kafkaCompressionTitle": "圧縮",
1991819918
"xpack.fleet.settings.editOutputFlyout.kafkaConnectionTypeLabel": "接続",
1991919919
"xpack.fleet.settings.editOutputFlyout.kafkaDynamicTopicHelptext": "リストからトピックを選択してください。トピックがない場合は、カスタムトピックを作成してください。",
19920+
"xpack.fleet.settings.editOutputFlyout.kafkaDynamicTopicLabel": "フィールドからのトピック",
1992019921
"xpack.fleet.settings.editOutputFlyout.kafkaHeaderKeyInputLabel": "キー",
1992119922
"xpack.fleet.settings.editOutputFlyout.kafkaHeadersTitle": "ヘッダー",
1992219923
"xpack.fleet.settings.editOutputFlyout.kafkaHeaderValueInputLabel": "値",

x-pack/platform/plugins/private/translations/translations/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19958,6 +19958,7 @@
1995819958
"xpack.fleet.settings.editOutputFlyout.kafkaCompressionTitle": "压缩",
1995919959
"xpack.fleet.settings.editOutputFlyout.kafkaConnectionTypeLabel": "连接",
1996019960
"xpack.fleet.settings.editOutputFlyout.kafkaDynamicTopicHelptext": "从列表中选择主题。如果主题不可用,请创建定制主题。",
19961+
"xpack.fleet.settings.editOutputFlyout.kafkaDynamicTopicLabel": "来自字段的主题",
1996119962
"xpack.fleet.settings.editOutputFlyout.kafkaHeaderKeyInputLabel": "钥匙",
1996219963
"xpack.fleet.settings.editOutputFlyout.kafkaHeadersTitle": "标题",
1996319964
"xpack.fleet.settings.editOutputFlyout.kafkaHeaderValueInputLabel": "值",

x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_kafka_topics.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ import {
1515
EuiTitle,
1616
EuiRadioGroup,
1717
EuiComboBox,
18-
EuiLink,
1918
} from '@elastic/eui';
2019
import { FormattedMessage } from '@kbn/i18n-react';
2120
import { i18n } from '@kbn/i18n';
2221

23-
import { useStartServices } from '../../../../hooks';
24-
2522
import {
2623
kafkaTopicsType,
2724
KAFKA_DYNAMIC_FIELDS,
@@ -33,12 +30,10 @@ import type { OutputFormInputsType } from './use_output_form';
3330
export const OutputFormKafkaTopics: React.FunctionComponent<{ inputs: OutputFormInputsType }> = ({
3431
inputs,
3532
}) => {
36-
const { docLinks } = useStartServices();
37-
3833
const dynamicOptions: Array<EuiComboBoxOptionOption<string>> = useMemo(() => {
3934
const options = KAFKA_DYNAMIC_FIELDS.map((option) => ({
4035
label: option,
41-
value: `%{[${option}]}`,
36+
value: option,
4237
}));
4338
return options;
4439
}, []);
@@ -78,17 +73,7 @@ export const OutputFormKafkaTopics: React.FunctionComponent<{ inputs: OutputForm
7873
label={
7974
<FormattedMessage
8075
id="xpack.fleet.settings.editOutputFlyout.kafkaDynamicTopicLabel"
81-
defaultMessage="Topic from field(s). For more info, see our {guideLink}"
82-
values={{
83-
guideLink: (
84-
<EuiLink href={docLinks.links.filebeat.kafkaOutput} target="_blank" external>
85-
<FormattedMessage
86-
id="xpack.fleet.settings.kafkaGuideLink"
87-
defaultMessage="docs."
88-
/>
89-
</EuiLink>
90-
),
91-
}}
76+
defaultMessage="Topic from field"
9277
/>
9378
}
9479
{...inputs.kafkaDynamicTopicInput.formRowProps}
@@ -98,7 +83,7 @@ export const OutputFormKafkaTopics: React.FunctionComponent<{ inputs: OutputForm
9883
fullWidth
9984
isClearable={true}
10085
options={dynamicOptions}
101-
customOptionText="Use custom field"
86+
customOptionText="Use custom field (not recommended)"
10287
singleSelection={{ asPlainText: true }}
10388
{...inputs.kafkaDynamicTopicInput.props}
10489
/>

x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_validators.test.tsx

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
validateKafkaHosts,
1515
validateKibanaURL,
1616
validateKibanaAPIKey,
17-
validateDynamicKafkaTopics,
1817
} from './output_form_validators';
1918

2019
describe('Output form validation', () => {
@@ -337,28 +336,4 @@ describe('Output form validation', () => {
337336
]);
338337
});
339338
});
340-
341-
describe('validateDynamicKafkaTopics', () => {
342-
const validTopics = [
343-
{ label: 'field1', value: '%{[field]}' },
344-
{ label: 'field2', value: 'field2' },
345-
{ label: 'field3', value: '%{[field2]}-%{[field3]}' },
346-
];
347-
const invalidBracketTopic = [{ label: '%{[field}', value: '%{[field}' }];
348-
const invalidPercentTopic = [{ label: '{[field]}', value: '{[field]}' }];
349-
it('should work with valid topics', () => {
350-
const res = validateDynamicKafkaTopics(validTopics);
351-
expect(res).toBeUndefined();
352-
});
353-
it("should return error with missing brackets in topic's name", () => {
354-
const res = validateDynamicKafkaTopics(invalidBracketTopic);
355-
expect(res).toEqual([
356-
'The topic should have a matching number of opening and closing brackets',
357-
]);
358-
});
359-
it("should return error with missing percent sign before opening brackets in topic's name", () => {
360-
const res = validateDynamicKafkaTopics(invalidPercentTopic);
361-
expect(res).toEqual(['Opening brackets should be preceded by a percent sign']);
362-
});
363-
});
364339
});

x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_validators.tsx

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ const toSecretValidator =
1919
return validator(value ?? '');
2020
};
2121

22-
const getAllIndices = (str: string, substring: string): number[] => {
23-
const indices = [];
24-
let index = str.indexOf(substring);
25-
while (index !== -1) {
26-
indices.push(index);
27-
index = str.indexOf(substring, index + 1);
28-
}
29-
return indices;
30-
};
3122
export function validateKafkaHosts(value: string[]) {
3223
const res: Array<{ message: string; index?: number }> = [];
3324
const urlIndexes: { [key: string]: number[] } = {};
@@ -371,31 +362,12 @@ export function validateKafkaStaticTopic(value: string) {
371362
export function validateDynamicKafkaTopics(value: Array<EuiComboBoxOptionOption<string>>) {
372363
const res = [];
373364
value.forEach((val, idx) => {
374-
if (!val || !val.value) {
365+
if (!val) {
375366
res.push(
376367
i18n.translate('xpack.fleet.settings.outputForm.kafkaTopicFieldRequiredMessage', {
377368
defaultMessage: 'Topic is required',
378369
})
379370
);
380-
} else {
381-
const openingBrackets = getAllIndices(val.value, '{[');
382-
const closingBrackets = getAllIndices(val.value, ']}');
383-
if (openingBrackets.length !== closingBrackets.length) {
384-
res.push(
385-
i18n.translate('xpack.fleet.settings.outputForm.kafkaTopicBracketsError', {
386-
defaultMessage:
387-
'The topic should have a matching number of opening and closing brackets',
388-
})
389-
);
390-
}
391-
// check for preceding percent sign
392-
if (!openingBrackets.every((item) => val?.value![item - 1] === '%')) {
393-
res.push(
394-
i18n.translate('xpack.fleet.settings.outputForm.kafkaTopicPercentError', {
395-
defaultMessage: 'Opening brackets should be preceded by a percent sign',
396-
})
397-
);
398-
}
399371
}
400372
});
401373

@@ -406,7 +378,6 @@ export function validateDynamicKafkaTopics(value: Array<EuiComboBoxOptionOption<
406378
})
407379
);
408380
}
409-
410381
if (res.length) {
411382
return res;
412383
}

x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/use_output_form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ export function useOutputForm(onSucess: () => void, output?: Output, defaultOupu
928928
}
929929
: kafkaTopicsInput.value === kafkaTopicsType.Dynamic && kafkaDynamicTopicInput.value
930930
? {
931-
topic: kafkaDynamicTopicInput.value,
931+
topic: `%{[${kafkaDynamicTopicInput.value}]}`,
932932
}
933933
: {}),
934934
headers: kafkaHeadersInput.value,

0 commit comments

Comments
 (0)