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

NETOBSERV-1720: fix issues with topology scopes #550

Merged
merged 1 commit into from
Jun 27, 2024
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
53 changes: 33 additions & 20 deletions web/src/components/netflow-topology/2d/topology-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import {
ElementData,
FilterDir,
generateDataModel,
getStepIntoNext,
GraphElementPeer,
isDirElementFiltered,
LayoutName,
NodeData,
toggleDirElementFilter,
Expand Down Expand Up @@ -55,6 +57,7 @@ export interface TopologyContentProps {
metricType: MetricType;
metricScope: FlowScope;
setMetricScope: (ms: FlowScope) => void;
allowedScopes: FlowScope[];
metrics: TopologyMetrics[];
droppedMetrics: TopologyMetrics[];
options: TopologyOptions;
Expand All @@ -75,6 +78,7 @@ export const TopologyContent: React.FC<TopologyContentProps> = ({
metricType,
metricScope,
setMetricScope,
allowedScopes,
metrics,
droppedMetrics,
options,
Expand Down Expand Up @@ -195,51 +199,58 @@ export const TopologyContent: React.FC<TopologyContentProps> = ({

const onStepInto = React.useCallback(
(data: Decorated<ElementData>) => {
let scope: MetricScopeOptions;
let groupTypes: TopologyGroupTypes;
switch (metricScope) {
case MetricScopeOptions.CLUSTER:
scope = MetricScopeOptions.ZONE;
groupTypes = TopologyGroupTypes.clusters;
break;
case MetricScopeOptions.ZONE:
scope = MetricScopeOptions.HOST;
groupTypes = TopologyGroupTypes.zones;
break;
case MetricScopeOptions.HOST:
scope = MetricScopeOptions.NAMESPACE;
groupTypes = TopologyGroupTypes.none;
groupTypes = TopologyGroupTypes.hosts;
break;
case MetricScopeOptions.NAMESPACE:
scope = MetricScopeOptions.OWNER;
groupTypes = TopologyGroupTypes.namespaces;
break;
default:
scope = MetricScopeOptions.RESOURCE;
groupTypes = TopologyGroupTypes.owners;
}
if (data.nodeType && data.peer) {
const scope = getStepIntoNext(metricScope, allowedScopes);
if (data.nodeType && data.peer && scope) {
setMetricScope(scope);
setOptions({ ...options, groupTypes });
toggleDirElementFilter(
data.nodeType,
data.peer,
'src',
true,
filters.list,
list => {
setFilters({ list: list, backAndForth: true });
},
filterDefinitions
);
if (!isDirElementFiltered(data.nodeType, data.peer, 'src', filters.list, filterDefinitions)) {
toggleDirElementFilter(
data.nodeType,
data.peer,
'src',
false,
filters.list,
list => {
setFilters({ list: list, backAndForth: true });
},
filterDefinitions
);
}
setSelectedIds([data.id]);
//clear search
onChangeSearch();
//clear selection
onSelect(undefined);
}
},
[metricScope, setMetricScope, setOptions, options, filters.list, filterDefinitions, onSelect, setFilters]
[
metricScope,
setMetricScope,
allowedScopes,
setOptions,
options,
filters.list,
filterDefinitions,
onSelect,
setFilters
]
);

const onHover = React.useCallback((data: Decorated<ElementData>) => {
Expand Down Expand Up @@ -344,6 +355,7 @@ export const TopologyContent: React.FC<TopologyContentProps> = ({
droppedMetrics,
getOptions(),
metricScope,
allowedScopes,
searchEvent?.searchValue || '',
highlightedId,
filters,
Expand Down Expand Up @@ -386,6 +398,7 @@ export const TopologyContent: React.FC<TopologyContentProps> = ({
selectedIds,
getOptions,
metricScope,
allowedScopes,
searchEvent?.searchValue,
filters,
t,
Expand Down
1 change: 1 addition & 0 deletions web/src/components/netflow-topology/netflow-topology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const NetflowTopology: React.FC<NetflowTopologyProps> = ({
metricType={metricType}
metricScope={metricScope}
setMetricScope={setMetricScope}
allowedScopes={allowedScopes}
metrics={displayedMetrics}
droppedMetrics={droppedMetrics}
options={options}
Expand Down
22 changes: 13 additions & 9 deletions web/src/components/netflow-traffic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
const [lastTop, setLastTop] = useLocalStorage<number>(localStorageLastTopKey, topValues[0]);
const [range, setRange] = React.useState<number | TimeRange>(getRangeFromURL());
const [histogramRange, setHistogramRange] = React.useState<TimeRange>();
const [metricScope, setMetricScope] = useLocalStorage<FlowScope>(localStorageMetricScopeKey, 'namespace');
const [metricScope, _setMetricScope] = useLocalStorage<FlowScope>(localStorageMetricScopeKey, 'namespace');
const [topologyMetricFunction, setTopologyMetricFunction] = useLocalStorage<StatFunction>(
localStorageMetricFunctionKey,
defaultMetricFunction
Expand Down Expand Up @@ -435,6 +435,18 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
[config, getQuickFilters]
);

const setMetricScope = React.useCallback(
(scope: FlowScope) => {
_setMetricScope(scope);
// Invalidate groups if necessary, when metrics scope changed
const groups = getGroupsForScope(scope as MetricScopeOptions);
if (!groups.includes(topologyOptions.groupTypes)) {
setTopologyOptions({ ...topologyOptions, groupTypes: TopologyGroupTypes.none });
}
},
[_setMetricScope, topologyOptions, setTopologyOptions]
);

const getTopologyMetrics = React.useCallback(() => {
switch (topologyMetricType) {
case 'Bytes':
Expand Down Expand Up @@ -1261,14 +1273,6 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [filters]);

//invalidate groups if necessary, when metrics scope changed
React.useEffect(() => {
const groups = getGroupsForScope(metricScope as MetricScopeOptions);
if (!groups.includes(topologyOptions.groupTypes)) {
setTopologyOptions({ ...topologyOptions, groupTypes: TopologyGroupTypes.none });
}
}, [metricScope, topologyOptions, setTopologyOptions]);

const clearFilters = React.useCallback(() => {
if (forcedFilters) {
navigate(netflowTrafficPath);
Expand Down
39 changes: 32 additions & 7 deletions web/src/model/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@ export const isGroupEnabled = (group: TopologyGroupTypes, enabledScopes: FlowSco
);
};

export const getStepIntoNext = (current: FlowScope, allowedScopes: FlowScope[]): FlowScope | undefined => {
let next: FlowScope | undefined = undefined;
switch (current) {
case 'cluster':
next = 'zone';
break;
case 'zone':
next = 'host';
break;
case 'host':
next = 'resource';
break;
case 'namespace':
next = 'owner';
break;
case 'owner':
next = 'resource';
break;
}
if (!next || allowedScopes.includes(next)) {
return next;
}
return getStepIntoNext(next, allowedScopes);
};

export interface TopologyOptions {
maxEdgeStat: number;
nodeBadges?: boolean;
Expand Down Expand Up @@ -456,6 +481,7 @@ export const generateDataModel = (
droppedMetrics: TopologyMetrics[],
options: TopologyOptions,
metricScope: FlowScope,
allowedScopes: FlowScope[],
searchValue: string,
highlightedId: string,
filters: Filters,
Expand Down Expand Up @@ -656,23 +682,22 @@ export const generateDataModel = (
};

const peerToNodeData = (p: TopologyMetricPeer): NodeData => {
const canStepInto = getStepIntoNext(metricScope, allowedScopes) !== undefined;
switch (metricScope) {
case 'cluster':
return _.isEmpty(p.clusterName)
? { peer: p, nodeType: 'unknown' }
: { peer: p, nodeType: 'cluster', canStepInto: true };
: { peer: p, nodeType: 'cluster', canStepInto };
case 'zone':
return _.isEmpty(p.zone) ? { peer: p, nodeType: 'unknown' } : { peer: p, nodeType: 'zone', canStepInto: true };
return _.isEmpty(p.zone) ? { peer: p, nodeType: 'unknown' } : { peer: p, nodeType: 'zone', canStepInto };
case 'host':
return _.isEmpty(p.hostName)
? { peer: p, nodeType: 'unknown' }
: { peer: p, nodeType: 'host', canStepInto: true };
return _.isEmpty(p.hostName) ? { peer: p, nodeType: 'unknown' } : { peer: p, nodeType: 'host', canStepInto };
case 'namespace':
return _.isEmpty(p.namespace)
? { peer: p, nodeType: 'unknown' }
: { peer: p, nodeType: 'namespace', canStepInto: true };
: { peer: p, nodeType: 'namespace', canStepInto };
case 'owner':
return p.owner ? { peer: p, nodeType: 'owner', canStepInto: true } : { peer: p, nodeType: 'unknown' };
return p.owner ? { peer: p, nodeType: 'owner', canStepInto } : { peer: p, nodeType: 'unknown' };
case 'resource':
default:
return { peer: p, nodeType: 'resource' };
Expand Down
Loading