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

Provide custom infinite values for some configs #1576

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions frontend/src/components/pages/topics/TopicConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import type { FC } from 'react';
import { useState } from 'react';
import { Controller, type SubmitHandler, useForm } from 'react-hook-form';
import type { ConfigEntryExtended } from '../../../state/restInterfaces';
import { formatConfigValue } from '../../../utils/formatters/ConfigValueFormatter';
import {
entryHasInfiniteValue,
formatConfigValue,
getInfiniteValueForEntry,
} from '../../../utils/formatters/ConfigValueFormatter';
import { DataSizeSelect, DurationSelect, NumInput, RatioInput } from './CreateTopicModal/CreateTopicModal';
import './TopicConfiguration.scss';
import { MdInfoOutline } from 'react-icons/md';
Expand Down Expand Up @@ -62,8 +66,8 @@ const ConfigEditorForm: FC<{
watch,
} = useForm<Inputs>({
defaultValues: {
valueType: editedEntry.isExplicitlySet ? (editedEntry.value === '-1' ? 'infinite' : 'custom') : 'default',
customValue: editedEntry.isExplicitlySet && editedEntry.value !== '-1' ? editedEntry.value : undefined,
valueType: editedEntry.isExplicitlySet ? (entryHasInfiniteValue(editedEntry) ? 'infinite' : 'custom') : 'default',
customValue: editedEntry.isExplicitlySet && !entryHasInfiniteValue(editedEntry) ? editedEntry.value : '',
},
});

Expand Down Expand Up @@ -92,7 +96,7 @@ const ConfigEditorForm: FC<{

let value: number | string | undefined | null = undefined;
if (valueType === 'infinite') {
value = -1;
value = getInfiniteValueForEntry(editedEntry);
} else if (valueType === 'custom') {
value = customValue;
}
Expand Down Expand Up @@ -276,14 +280,19 @@ const ConfigGroup = observer(
<div className="configGroupSpacer" />
{p.groupName && <div className="configGroupTitle">{p.groupName}</div>}
{p.entries.map((e) => (
<ConfigEntry key={e.name} entry={e} onEditEntry={p.onEditEntry} hasEditPermissions={p.hasEditPermissions} />
<ConfigEntryComponent
key={e.name}
entry={e}
onEditEntry={p.onEditEntry}
hasEditPermissions={p.hasEditPermissions}
/>
))}
</>
);
},
);

const ConfigEntry = observer(
const ConfigEntryComponent = observer(
(p: {
onEditEntry: (configEntry: ConfigEntryExtended) => void;
entry: ConfigEntryExtended;
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/utils/formatters/ConfigValueFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@
* by the Apache License, Version 2.0
*/

import type { ConfigEntry, ConfigEntryExtended } from '../../state/restInterfaces';
import { prettyBytesOrNA, prettyMilliseconds } from '../utils';

export const CONFIG_INFINITE_VALUES: Record<string, number> = {
'flush.ms': 9223372036854,
};

export const entryHasInfiniteValue = (entry: ConfigEntry) =>
Number(entry.value) === CONFIG_INFINITE_VALUES[entry.name] || entry.value === '-1';

export const getInfiniteValueForEntry = (entry: ConfigEntryExtended) => {
return CONFIG_INFINITE_VALUES[entry.name] ?? -1;
};

export function formatConfigValue(
name: string,
value: string | null | undefined,
Expand Down Expand Up @@ -53,6 +65,10 @@ export function formatConfigValue(
return `${prettyBytesOrNA(num)}/s${suffix}`;
}

if (CONFIG_INFINITE_VALUES[name] && num >= CONFIG_INFINITE_VALUES[name]) {
return `Infinite${suffix}`;
}

// Time
const timeExtensions: [string, number][] = [
// name ending -> conversion to milliseconds
Expand Down
Loading