Skip to content

Commit d12dfc0

Browse files
authored
Revert "[Fleet] Improve validation for dynamic Kafka topics" (#219415)
Reverts #212422 We don't want to surface this Beats-specific syntax for dynamic topics because it greatly harms our ability to migrate users to OTel. The recommended way to handle complex multi-field interpolations for topic names is to use an `add_field` Beats processor to add the desired topic name as a distinct field, and then use that field for the dynamic topic name in the Fleet-managed Kafka output. I'll be filing a docs issue to get this in our public docs as well.
1 parent 07be70d commit d12dfc0

File tree

6 files changed

+12
-62
lines changed

6 files changed

+12
-62
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
114114
configuration: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/configuring-howto-filebeat.html`,
115115
elasticsearchModule: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-module-elasticsearch.html`,
116116
elasticsearchOutput: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/elasticsearch-output.html`,
117-
kafkaOutput: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/kafka-output.html`,
118117
startup: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-starting.html`,
119118
exportedFields: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/exported-fields.html`,
120119
suricataModule: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-module-suricata.html`,
@@ -863,6 +862,7 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
863862
fleetServerAddFleetServer: `${FLEET_DOCS}add-a-fleet-server.html`,
864863
settings: `${FLEET_DOCS}fleet-settings.html`,
865864
kafkaSettings: `${FLEET_DOCS}kafka-output-settings.html`,
865+
kafkaOutputTopicsSettings: `${FLEET_DOCS}kafka-output-settings.html#_topics_settings`,
866866
logstashSettings: `${FLEET_DOCS}ls-output-settings.html`,
867867
esSettings: `${FLEET_DOCS}es-output-settings.html`,
868868
settingsFleetServerHostSettings: `${FLEET_DOCS}fleet-settings.html#fleet-server-hosts-setting`,

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

Lines changed: 1 addition & 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;
@@ -493,6 +492,7 @@ export interface DocLinks {
493492
settings: string;
494493
logstashSettings: string;
495494
kafkaSettings: string;
495+
kafkaOutputTopicsSettings: string;
496496
settingsFleetServerHostSettings: string;
497497
settingsFleetServerProxySettings: string;
498498
troubleshooting: string;

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const OutputFormKafkaTopics: React.FunctionComponent<{ inputs: OutputForm
3838
const dynamicOptions: Array<EuiComboBoxOptionOption<string>> = useMemo(() => {
3939
const options = KAFKA_DYNAMIC_FIELDS.map((option) => ({
4040
label: option,
41-
value: `%{[${option}]}`,
41+
value: option,
4242
}));
4343
return options;
4444
}, []);
@@ -78,13 +78,17 @@ export const OutputFormKafkaTopics: React.FunctionComponent<{ inputs: OutputForm
7878
label={
7979
<FormattedMessage
8080
id="xpack.fleet.settings.editOutputFlyout.kafkaDynamicTopicLabel"
81-
defaultMessage="Topic from field(s). For more info, see our {guideLink}"
81+
defaultMessage="Topic from field(s). For more info, see our {guideLink}."
8282
values={{
8383
guideLink: (
84-
<EuiLink href={docLinks.links.filebeat.kafkaOutput} target="_blank" external>
84+
<EuiLink
85+
href={docLinks.links.fleet.kafkaOutputTopicsSettings}
86+
target="_blank"
87+
external
88+
>
8589
<FormattedMessage
8690
id="xpack.fleet.settings.kafkaGuideLink"
87-
defaultMessage="docs."
91+
defaultMessage="docs"
8892
/>
8993
</EuiLink>
9094
),

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)