[8.10] [Fleet][Kafka][Fix] Validate number of events fields (#165202) (#165318)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Fleet][Kafka][Fix] Validate number of events fields
(#165202)](https://github.com/elastic/kibana/pull/165202)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Konrad
Szwarc","email":"konrad.szwarc@elastic.co"},"sourceCommit":{"committedDate":"2023-08-31T12:01:50Z","message":"[Fleet][Kafka][Fix]
Validate number of events fields (#165202)\n\nThis PR adds field
verification for `Partitioning` part of `Kafka`\r\noutput UI.\r\nMight
close
1f0a3704-efec-40d7-9e3a-f5504ddd77af","sha":"99032dff872d03b7e27eeeecdfcafbd3dabc0f81","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v8.10.0","v8.11.0"],"number":165202,"url":"https://github.com/elastic/kibana/pull/165202","mergeCommit":{"message":"[Fleet][Kafka][Fix]
Validate number of events fields (#165202)\n\nThis PR adds field
verification for `Partitioning` part of `Kafka`\r\noutput UI.\r\nMight
close
1f0a3704-efec-40d7-9e3a-f5504ddd77af","sha":"99032dff872d03b7e27eeeecdfcafbd3dabc0f81"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/165202","number":165202,"mergeCommit":{"message":"[Fleet][Kafka][Fix]
Validate number of events fields (#165202)\n\nThis PR adds field
verification for `Partitioning` part of `Kafka`\r\noutput UI.\r\nMight
close
1f0a3704-efec-40d7-9e3a-f5504ddd77af","sha":"99032dff872d03b7e27eeeecdfcafbd3dabc0f81"}}]}]
BACKPORT-->

Co-authored-by: Konrad Szwarc <konrad.szwarc@elastic.co>
This commit is contained in:
Kibana Machine 2023-08-31 09:12:32 -04:00 committed by GitHub
parent 2a79eebee7
commit 28d2f060f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 8 deletions

View file

@ -55,6 +55,7 @@ export const OutputFormKafkaPartitioning: React.FunctionComponent<{
defaultMessage="Number of events"
/>
}
{...inputs.kafkaPartitionTypeRandomInput.formRowProps}
>
<EuiFieldText
data-test-subj="settingsOutputsFlyout.kafkaPartitionTypeRandomInput"
@ -73,6 +74,7 @@ export const OutputFormKafkaPartitioning: React.FunctionComponent<{
defaultMessage="Number of events"
/>
}
{...inputs.kafkaPartitionTypeRoundRobinInput.formRowProps}
>
<EuiFieldText
data-test-subj="settingsOutputsFlyout.kafkaPartitionTypeRoundRobinInput"

View file

@ -290,6 +290,20 @@ export function validateKafkaClientId(value: string) {
];
}
export function validateKafkaPartitioningGroupEvents(value: string) {
const regex = /^[0-9]+$/;
return regex.test(value)
? undefined
: [
i18n.translate(
'xpack.fleet.settings.outputForm.kafkaPartitioningGroupEventsFormattingMessage',
{
defaultMessage: 'Number of events must be a number',
}
),
];
}
export function validateKafkaTopics(
topics: Array<{
topic: string;

View file

@ -61,6 +61,7 @@ import {
validateKafkaTopics,
validateKafkaClientId,
validateKafkaHosts,
validateKafkaPartitioningGroupEvents,
} from './output_form_validators';
import { confirmUpdate } from './confirm_update';
@ -342,8 +343,10 @@ export function useOutputForm(onSucess: () => void, output?: Output) {
);
const kafkaPartitionTypeRandomInput = useInput(
kafkaOutput?.random?.group_events ? `${kafkaOutput.random.group_events}` : undefined,
undefined,
kafkaOutput?.random?.group_events ? `${kafkaOutput.random.group_events}` : '1',
kafkaPartitionTypeInput.value === kafkaPartitionType.Random
? validateKafkaPartitioningGroupEvents
: undefined,
isDisabled('partition')
);
const kafkaPartitionTypeHashInput = useInput(
@ -352,8 +355,10 @@ export function useOutputForm(onSucess: () => void, output?: Output) {
isDisabled('partition')
);
const kafkaPartitionTypeRoundRobinInput = useInput(
kafkaOutput?.round_robin?.group_events ? `${kafkaOutput.round_robin.group_events}` : undefined,
undefined,
kafkaOutput?.round_robin?.group_events ? `${kafkaOutput.round_robin.group_events}` : '1',
kafkaPartitionTypeInput.value === kafkaPartitionType.RoundRobin
? validateKafkaPartitioningGroupEvents
: undefined,
isDisabled('partition')
);
@ -492,6 +497,8 @@ export function useOutputForm(onSucess: () => void, output?: Output) {
const sslCertificateValid = sslCertificateInput.validate();
const sslKeyValid = sslKeyInput.validate();
const diskQueuePathValid = diskQueuePathInput.validate();
const partitioningRandomGroupEventsValid = kafkaPartitionTypeRandomInput.validate();
const partitioningRoundRobinGroupEventsValid = kafkaPartitionTypeRoundRobinInput.validate();
if (isLogstash) {
// validate logstash
@ -516,7 +523,9 @@ export function useOutputForm(onSucess: () => void, output?: Output) {
kafkaDefaultTopicValid &&
kafkaTopicsValid &&
additionalYamlConfigValid &&
kafkaClientIDValid
kafkaClientIDValid &&
partitioningRandomGroupEventsValid &&
partitioningRoundRobinGroupEventsValid
);
} else {
// validate ES
@ -546,6 +555,8 @@ export function useOutputForm(onSucess: () => void, output?: Output) {
sslCertificateInput,
sslKeyInput,
diskQueuePathInput,
kafkaPartitionTypeRandomInput,
kafkaPartitionTypeRoundRobinInput,
isLogstash,
isKafka,
]);
@ -674,7 +685,8 @@ export function useOutputForm(onSucess: () => void, output?: Output) {
: {}),
partition: kafkaPartitionTypeInput.value,
...(kafkaPartitionTypeRandomInput.value
...(kafkaPartitionTypeInput.value === kafkaPartitionType.Random &&
kafkaPartitionTypeRandomInput.value
? {
random: {
group_events: parseIntegerIfStringDefined(
@ -683,7 +695,8 @@ export function useOutputForm(onSucess: () => void, output?: Output) {
},
}
: {}),
...(kafkaPartitionTypeRoundRobinInput.value
...(kafkaPartitionTypeInput.value === kafkaPartitionType.RoundRobin &&
kafkaPartitionTypeRoundRobinInput.value
? {
round_robin: {
group_events: parseIntegerIfStringDefined(
@ -692,7 +705,8 @@ export function useOutputForm(onSucess: () => void, output?: Output) {
},
}
: {}),
...(kafkaPartitionTypeHashInput.value
...(kafkaPartitionTypeInput.value === kafkaPartitionType.Hash &&
kafkaPartitionTypeHashInput.value
? {
hash: {
hash: kafkaPartitionTypeHashInput.value,