@@ -32,7 +32,7 @@ import { useTranslation } from 'react-i18next';
3232import { useTheme } from '../utils/theme-hook' ;
3333import { Record } from '../api/ipfix' ;
3434import { GenericMetric , Stats , TopologyMetrics } from '../api/loki' ;
35- import { getGenericMetrics , getFlows , getTopologyMetrics } from '../api/routes' ;
35+ import { getGenericMetrics } from '../api/routes' ;
3636import {
3737 DisabledFilters ,
3838 Filter ,
@@ -45,13 +45,13 @@ import {
4545} from '../model/filters' ;
4646import {
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' ;
5656import { MetricScopeOptions } from '../model/metrics' ;
5757import { parseQuickFilters } from '../model/quick-filters' ;
@@ -142,6 +142,8 @@ import { exportToPng } from '../utils/export';
142142import { navigate } from './dynamic-loader/dynamic-loader' ;
143143import { LinksOverflow } from './overflow/links-overflow' ;
144144import { mergeFlowReporters } from '../utils/flows' ;
145+ import { getFetchFunctions as getBackAndForthFetch } from '../utils/back-and-forth' ;
146+ import { mergeStats } from '../utils/metrics' ;
145147
146148export 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 ( ( ) => {
0 commit comments