Skip to content

Commit b7975ad

Browse files
committed
Revert last change on sampling, instead remove from previous step
1 parent 09cceec commit b7975ad

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

web/src/components/forms/consumption.tsx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ import './forms.css';
1414

1515
export type ResourceCalculatorProps = {
1616
flowCollector: K8sResourceKind | null;
17-
changedSampling: number | null;
18-
setChangedSampling: (sampling: number | null) => void;
17+
setSampling?: (sampling: number) => void;
1918
};
2019

21-
export const Consumption: FC<ResourceCalculatorProps> = ({ flowCollector, changedSampling, setChangedSampling }) => {
20+
export const Consumption: FC<ResourceCalculatorProps> = ({ flowCollector, setSampling }) => {
2221
const { t } = useTranslation('plugin__netobserv-plugin');
2322

2423
const [receivedPackets, rpLoaded, rpError] = usePrometheusPoll({
@@ -31,19 +30,19 @@ export const Consumption: FC<ResourceCalculatorProps> = ({ flowCollector, change
3130
query: `sort_desc(sum(irate(container_network_transmit_packets_total{cluster="",namespace=~".+"}[4h])) by (node,namespace,pod))`
3231
});
3332

34-
const getCRSampling = React.useCallback(() => {
35-
return (flowCollector?.spec?.agent?.ebpf?.sampling as number) || 50;
33+
const getCurrentSampling = React.useCallback(() => {
34+
return flowCollector?.spec?.agent?.ebpf?.sampling || 50;
3635
}, [flowCollector?.spec?.agent?.ebpf?.sampling]);
3736

3837
const getSamplings = React.useCallback(() => {
39-
const current = getCRSampling();
40-
let samplings = [1, 25, 50, 100, 125, 150];
38+
const current = getCurrentSampling();
39+
let samplings = [1, 25, 50, 100, 500, 1000];
4140
if (!samplings.includes(current)) {
4241
samplings.push(current);
4342
samplings = _.sortBy(samplings);
4443
}
4544
return samplings;
46-
}, [getCRSampling]);
45+
}, [getCurrentSampling]);
4746

4847
const loadingComponent = () => <Spinner size="lg" />;
4948

@@ -102,9 +101,6 @@ export const Consumption: FC<ResourceCalculatorProps> = ({ flowCollector, change
102101
];
103102
}, [labelsCount]);
104103

105-
const initialSampling = getCRSampling();
106-
const currentSampling = changedSampling !== null ? changedSampling : initialSampling;
107-
108104
return (
109105
<Flex direction={{ default: 'column' }}>
110106
<FlexItem className="calculator-item">
@@ -183,23 +179,17 @@ export const Consumption: FC<ResourceCalculatorProps> = ({ flowCollector, change
183179
</Thead>
184180
<Tbody>
185181
{getSamplings().map((sampling, i) => {
186-
const isCurrent = currentSampling === sampling;
187-
let extraText = '';
188-
if (isCurrent) {
189-
extraText = changedSampling === null ? t('(current)') : t('(new value)');
190-
} else if (sampling === initialSampling) {
191-
extraText = t('(previous value)');
192-
}
182+
const current = getCurrentSampling() === sampling;
193183
const estimate = getEstimation(sampling);
194184
return (
195185
<Tr
196186
key={i}
197-
isSelectable
198-
isClickable
199-
isRowSelected={isCurrent}
200-
onClick={() => setChangedSampling(sampling === initialSampling ? null : sampling)}
187+
isSelectable={setSampling !== undefined}
188+
isClickable={setSampling !== undefined}
189+
isRowSelected={current}
190+
onClick={() => setSampling && setSampling(sampling)}
201191
>
202-
<Td>{`${sampling} ${extraText}`}</Td>
192+
<Td>{`${sampling} ${current ? t('(current)') : ''}`}</Td>
203193
<Td>{`${estimate.cpu}vCPUs`}</Td>
204194
<Td>{`${estimate.memory}GiB`}</Td>
205195
</Tr>

web/src/components/forms/flowCollector-wizard.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export const FlowCollectorWizard: FC<FlowCollectorWizardProps> = props => {
3434
const { t } = useTranslation('plugin__netobserv-plugin');
3535
const [schema, setSchema] = React.useState<RJSFSchema | null>(null);
3636
const [data, setData] = React.useState<any>(null);
37-
const [changedSampling, setChangedSampling] = React.useState<number | null>(null);
3837
const [paths, setPaths] = React.useState<string[]>(defaultPaths);
3938
const params = useParams();
4039

@@ -71,7 +70,6 @@ export const FlowCollectorWizard: FC<FlowCollectorWizardProps> = props => {
7170
'spec.kafka.address',
7271
'spec.kafka.topic',
7372
'spec.kafka.tls',
74-
'spec.agent.ebpf.sampling',
7573
'spec.agent.ebpf.privileged',
7674
'spec.agent.ebpf.features',
7775
'spec.processor.clusterName',
@@ -86,6 +84,17 @@ export const FlowCollectorWizard: FC<FlowCollectorWizardProps> = props => {
8684
}
8785
}, []);
8886

87+
const setSampling = React.useCallback(
88+
(sampling: number) => {
89+
if (!data) {
90+
return;
91+
}
92+
data.spec.agent.ebpf.sampling = sampling;
93+
setData({ ...data });
94+
},
95+
[data]
96+
);
97+
8998
return (
9099
<DynamicLoader>
91100
<ResourceWatcher
@@ -177,12 +186,7 @@ export const FlowCollectorWizard: FC<FlowCollectorWizardProps> = props => {
177186
<WizardFooterWrapper>
178187
<Button
179188
variant="primary"
180-
onClick={() => {
181-
if (changedSampling !== null) {
182-
data.spec.agent.ebpf.sampling = changedSampling;
183-
}
184-
ctx.onSubmit(data);
185-
}}
189+
onClick={() => ctx.onSubmit(data)}
186190
>
187191
{t('Submit')}
188192
</Button>
@@ -192,11 +196,7 @@ export const FlowCollectorWizard: FC<FlowCollectorWizardProps> = props => {
192196
</WizardFooterWrapper>
193197
}
194198
>
195-
<Consumption
196-
flowCollector={data}
197-
changedSampling={changedSampling}
198-
setChangedSampling={setChangedSampling}
199-
/>
199+
<Consumption flowCollector={data} setSampling={setSampling} />
200200
<>{!_.isEmpty(ctx.errors) && <ErrorTemplate errors={ctx.errors} />}</>
201201
</WizardStep>
202202
</Wizard>

0 commit comments

Comments
 (0)