Skip to content

Commit a21bd6a

Browse files
authored
NETOBSERV-1269 refactor overlapping detection for BNF (#379)
This fix allows working on situations as described in https://issues.redhat.com/browse/NETOBSERV-1269 and, hopefully, is a more generic / consistent solution anyway. Changing how overlapping results are managed: work on results rather than on query to remove overlapping parts. When fetching flows, we don't explicitly remove the overlaps, but this is managed implicitly with the existing dedup functions When fetching metrics, we consider that the computed metrics for any label set is the ORIGINAL metrics + the SWAPPED metrics - the OVERLAP metrics. Add tests, fix tests Note that adjustment is necessary in MetricsQuerySummary test as the "endWithTolerance" calculation has changed a little bit, modifying computed rates ... new values are still close to the previous ones Rename callback function
1 parent bffb860 commit a21bd6a

File tree

9 files changed

+718
-430
lines changed

9 files changed

+718
-430
lines changed

web/src/components/netflow-traffic.tsx

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { useTranslation } from 'react-i18next';
3232
import { useTheme } from '../utils/theme-hook';
3333
import { Record } from '../api/ipfix';
3434
import { GenericMetric, Stats, TopologyMetrics } from '../api/loki';
35-
import { getGenericMetrics, getFlows, getTopologyMetrics } from '../api/routes';
35+
import { getGenericMetrics } from '../api/routes';
3636
import {
3737
DisabledFilters,
3838
Filter,
@@ -45,13 +45,13 @@ import {
4545
} from '../model/filters';
4646
import {
4747
FlowQuery,
48-
groupFilters,
4948
Match,
5049
MetricFunction,
5150
FlowScope,
5251
MetricType,
5352
PacketLoss,
54-
RecordType
53+
RecordType,
54+
filtersToString
5555
} from '../model/flow-query';
5656
import { MetricScopeOptions } from '../model/metrics';
5757
import { parseQuickFilters } from '../model/quick-filters';
@@ -142,6 +142,8 @@ import { exportToPng } from '../utils/export';
142142
import { navigate } from './dynamic-loader/dynamic-loader';
143143
import { LinksOverflow } from './overflow/links-overflow';
144144
import { mergeFlowReporters } from '../utils/flows';
145+
import { getFetchFunctions as getBackAndForthFetch } from '../utils/back-and-forth';
146+
import { mergeStats } from '../utils/metrics';
145147

146148
export type ViewId = 'overview' | 'table' | 'topology';
147149

@@ -339,9 +341,8 @@ export const NetflowTraffic: React.FC<{
339341

340342
const buildFlowQuery = React.useCallback((): FlowQuery => {
341343
const enabledFilters = getEnabledFilters(forcedFilters || filters);
342-
const groupedFilters = groupFilters(enabledFilters, match === 'any');
343344
const query: FlowQuery = {
344-
filters: groupedFilters,
345+
filters: filtersToString(enabledFilters.list, match === 'any'),
345346
limit: LIMIT_VALUES.includes(limit) ? limit : LIMIT_VALUES[0],
346347
recordType: recordType,
347348
dedup: !showDuplicates,
@@ -387,6 +388,13 @@ export const NetflowTraffic: React.FC<{
387388
topologyOptions.groupTypes
388389
]);
389390

391+
const getFetchFunctions = React.useCallback(() => {
392+
// check back-and-forth
393+
const enabledFilters = getEnabledFilters(forcedFilters || filters);
394+
const matchAny = match === 'any';
395+
return getBackAndForthFetch(enabledFilters, matchAny);
396+
}, [forcedFilters, filters, match]);
397+
390398
const manageWarnings = React.useCallback(
391399
(query: Promise<unknown>) => {
392400
Promise.race([query, new Promise((resolve, reject) => setTimeout(reject, 2000, 'slow'))]).then(
@@ -403,20 +411,12 @@ export const NetflowTraffic: React.FC<{
403411
[]
404412
);
405413

406-
const mergeStats = (prev: Stats | undefined, current: Stats): Stats => {
407-
if (!prev) {
408-
return current;
409-
}
410-
return {
411-
...prev,
412-
limitReached: prev.limitReached || current.limitReached,
413-
numQueries: prev.numQueries + current.numQueries
414-
};
415-
};
416-
417414
const fetchTable = React.useCallback(
418415
(fq: FlowQuery, droppedType: MetricType | undefined) => {
419416
setMetrics([]);
417+
418+
const { getFlows, getTopologyMetrics } = getFetchFunctions();
419+
420420
// table query is based on histogram range if available
421421
const tableQuery = { ...fq };
422422
if (histogramRange) {
@@ -452,12 +452,15 @@ export const NetflowTraffic: React.FC<{
452452
}
453453
return Promise.all(promises);
454454
},
455-
[histogramRange, range, showHistogram, showDuplicates]
455+
[histogramRange, range, showHistogram, showDuplicates, getFetchFunctions]
456456
);
457457

458458
const fetchOverview = React.useCallback(
459459
(fq: FlowQuery, droppedType: MetricType | undefined) => {
460460
setFlows([]);
461+
462+
const { getTopologyMetrics } = getFetchFunctions();
463+
461464
const promises: Promise<Stats>[] = [
462465
//get bytes or packets
463466
getTopologyMetrics(fq, range).then(res => {
@@ -555,12 +558,15 @@ export const NetflowTraffic: React.FC<{
555558
}
556559
return Promise.all(promises);
557560
},
558-
[range, config.features]
561+
[range, config.features, getFetchFunctions]
559562
);
560563

561564
const fetchTopology = React.useCallback(
562565
(fq: FlowQuery, droppedType: MetricType | undefined) => {
563566
setFlows([]);
567+
568+
const { getTopologyMetrics } = getFetchFunctions();
569+
564570
const promises: Promise<Stats>[] = [
565571
//get bytes or packets
566572
getTopologyMetrics(fq, range).then(res => {
@@ -581,7 +587,7 @@ export const NetflowTraffic: React.FC<{
581587
}
582588
return Promise.all(promises);
583589
},
584-
[range]
590+
[range, getFetchFunctions]
585591
);
586592

587593
const tick = React.useCallback(() => {

web/src/components/query-summary/__tests__/metrics-query-summary.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ describe('<MetricsQuerySummary />', () => {
2828

2929
it('should show summary', async () => {
3030
const wrapper = mount(<MetricsQuerySummary {...mocks} />);
31-
expect(wrapper.find('#bytesCount').last().text()).toBe('7 MB');
31+
expect(wrapper.find('#bytesCount').last().text()).toBe('6.8 MB');
3232
expect(wrapper.find('#packetsCount')).toHaveLength(0);
33-
expect(wrapper.find('#bpsCount').last().text()).toBe('23.2 kBps');
33+
expect(wrapper.find('#bpsCount').last().text()).toBe('22.79 kBps');
3434
expect(wrapper.find('#lastRefresh').last().text()).toBe(now.toLocaleTimeString());
3535
});
3636

0 commit comments

Comments
 (0)