@ -14,6 +14,7 @@ import SearchBar from '../../components/SearchBar';
interface ServiceMap {
interface ServiceMap {
activeTargets : Target [ ] ;
activeTargets : Target [ ] ;
droppedTargets : DroppedTarget [ ] ;
droppedTargets : DroppedTarget [ ] ;
droppedTargetCounts : Record < string , number > ;
}
}
export interface TargetLabels {
export interface TargetLabels {
@ -34,7 +35,7 @@ const droppedTargetKVSearch = new KVSearch<DroppedTarget>({
export const processSummary = (
export const processSummary = (
activeTargets : Target [ ] ,
activeTargets : Target [ ] ,
droppedTargets : DroppedTarget [ ]
droppedTargetCounts : Record < string , number >
) : Record < string , { active : number ; total : number } > = > {
) : Record < string , { active : number ; total : number } > = > {
const targets : Record < string , { active : number ; total : number } > = { } ;
const targets : Record < string , { active : number ; total : number } > = { } ;
@ -50,15 +51,15 @@ export const processSummary = (
targets [ name ] . total ++ ;
targets [ name ] . total ++ ;
targets [ name ] . active ++ ;
targets [ name ] . active ++ ;
}
}
for ( const target of droppedTargets ) {
for ( const name in targets ) {
const { job : name } = target . discoveredLabels ;
if ( ! targets [ name ] ) {
if ( ! targets [ name ] ) {
targets [ name ] = {
targets [ name ] = {
total : 0 ,
total : droppedTargetCounts [ name ] ,
active : 0 ,
active : 0 ,
} ;
} ;
} else {
targets [ name ] . total += droppedTargetCounts [ name ] ;
}
}
targets [ name ] . total ++ ;
}
}
return targets ;
return targets ;
@ -94,10 +95,10 @@ export const processTargets = (activeTargets: Target[], droppedTargets: DroppedT
return labels ;
return labels ;
} ;
} ;
export const ServiceDiscoveryContent : FC < ServiceMap > = ( { activeTargets , droppedTargets } ) = > {
export const ServiceDiscoveryContent : FC < ServiceMap > = ( { activeTargets , droppedTargets , droppedTargetCounts } ) = > {
const [ activeTargetList , setActiveTargetList ] = useState ( activeTargets ) ;
const [ activeTargetList , setActiveTargetList ] = useState ( activeTargets ) ;
const [ droppedTargetList , setDroppedTargetList ] = useState ( droppedTargets ) ;
const [ droppedTargetList , setDroppedTargetList ] = useState ( droppedTargets ) ;
const [ targetList , setTargetList ] = useState ( processSummary ( activeTargets , droppedTargets ) ) ;
const [ targetList , setTargetList ] = useState ( processSummary ( activeTargets , droppedTargetCount s ) ) ;
const [ labelList , setLabelList ] = useState ( processTargets ( activeTargets , droppedTargets ) ) ;
const [ labelList , setLabelList ] = useState ( processTargets ( activeTargets , droppedTargets ) ) ;
const handleSearchChange = useCallback (
const handleSearchChange = useCallback (
@ -118,9 +119,9 @@ export const ServiceDiscoveryContent: FC<ServiceMap> = ({ activeTargets, dropped
const defaultValue = useMemo ( getQuerySearchFilter , [ ] ) ;
const defaultValue = useMemo ( getQuerySearchFilter , [ ] ) ;
useEffect ( ( ) = > {
useEffect ( ( ) = > {
setTargetList ( processSummary ( activeTargetList , droppedTargetList ) ) ;
setTargetList ( processSummary ( activeTargetList , droppedTargetCounts ) ) ;
setLabelList ( processTargets ( activeTargetList , droppedTargetList ) ) ;
setLabelList ( processTargets ( activeTargetList , droppedTargetList ) ) ;
} , [ activeTargetList , droppedTargetList ] ) ;
} , [ activeTargetList , droppedTargetList , droppedTargetCounts ] ) ;
return (
return (
< >
< >