Skip to content

Commit 779616e

Browse files
committed
New auto group
Currently automatically groups as namespaces when available More logic can easily be inserted
1 parent 418cd67 commit 779616e

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

web/src/components/netflow-traffic.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { FiltersToolbar } from './toolbar/filters-toolbar';
5858
import ChipsPopover from './toolbar/filters/chips-popover';
5959
import HistogramToolbar from './toolbar/histogram-toolbar';
6060
import ViewOptionsToolbar from './toolbar/view-options-toolbar';
61+
import { resolveGroupTypes } from '../model/scope';
6162

6263
export type ViewId = 'overview' | 'table' | 'topology';
6364

@@ -289,7 +290,9 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({
289290
query.aggregateBy = model.metricScope;
290291
if (model.selectedViewId === 'topology') {
291292
query.type = model.topologyMetricType;
292-
query.groups = model.topologyOptions.groupTypes !== 'none' ? model.topologyOptions.groupTypes : undefined;
293+
const scopes = getAvailableScopes();
294+
const resolvedGroup = resolveGroupTypes(model.topologyOptions.groupTypes, model.metricScope, scopes);
295+
query.groups = resolvedGroup !== 'none' ? resolvedGroup : undefined;
293296
} else if (model.selectedViewId === 'overview') {
294297
query.limit = topValues.includes(model.limit) ? model.limit : topValues[0];
295298
query.groups = undefined;

web/src/components/tabs/netflow-topology/2d/topology-content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export const TopologyContent: React.FC<TopologyContentProps> = ({
207207

208208
const onStepInto = React.useCallback(
209209
(data: Decorated<ElementData>) => {
210-
const groupTypes: TopologyGroupTypes = metricScope;
210+
const groupTypes: TopologyGroupTypes = options.groupTypes === 'auto' ? 'auto' : metricScope;
211211
const scope = getStepInto(
212212
metricScope,
213213
scopes.map(sc => sc.id)

web/src/model/netflow-traffic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export function netflowTrafficModel() {
150150
// Invalidate groups if necessary, when metrics scope changed
151151
const groups = getGroupsForScope(scope, config.scopes);
152152
if (!groups.includes(topologyOptions.groupTypes)) {
153-
setTopologyOptions({ ...topologyOptions, groupTypes: 'none' });
153+
setTopologyOptions({ ...topologyOptions, groupTypes: 'auto' });
154154
}
155155
},
156156
[setMetricScope, config.scopes, topologyOptions, setTopologyOptions]

web/src/model/scope.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,32 @@ export const getScopeName = (sc: ScopeConfigDef | undefined, t: (k: string) => s
2222
return sc.name || sc.id;
2323
};
2424

25-
export const getGroupsForScope = (scopeId: FlowScope, scopes: ScopeConfigDef[]) => {
25+
export const getGroupsForScope = (scopeId: FlowScope, scopes: ScopeConfigDef[]): TopologyGroupTypes[] => {
2626
const scope = scopes.find(sc => sc.id === scopeId);
2727
if (scope?.groups?.length) {
2828
const availableParts = scopes.map(sc => `${sc.id}s`);
29-
return ['none', ...scope.groups.filter(gp => gp.split('+').every(part => availableParts.includes(part)))];
29+
return ['none', 'auto', ...scope.groups.filter(gp => gp.split('+').every(part => availableParts.includes(part)))];
3030
}
31-
return ['none'];
31+
return ['none', 'auto'];
32+
};
33+
34+
export const resolveGroupTypes = (inGroupTypes: TopologyGroupTypes, scopeId: FlowScope, scopes: ScopeConfigDef[]): TopologyGroupTypes => {
35+
if (inGroupTypes === 'auto') {
36+
const groups = getGroupsForScope(scopeId, scopes);
37+
if (groups.includes('namespaces')) {
38+
return 'namespaces';
39+
}
40+
// More logic can be added here for more default behaviours
41+
return 'none';
42+
}
43+
return inGroupTypes;
3244
};
3345

3446
export const getGroupName = (group: TopologyGroupTypes, scopes: ScopeConfigDef[], t: (k: string) => string) => {
3547
if (group === 'none') {
3648
return t('None');
49+
} else if (group === 'auto') {
50+
return t('Auto');
3751
} else if (group.includes('+')) {
3852
return group
3953
.split('+')

web/src/model/topology.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { createPeer, getFormattedValue } from '../utils/metrics';
2525
import { defaultMetricFunction, defaultMetricType } from '../utils/router';
2626
import { FlowScope, Groups, MetricFunction, MetricType, NodeType, StatFunction } from './flow-query';
2727
import { getStat } from './metrics';
28-
import { getStepInto, isDirectionnal, ScopeConfigDef } from './scope';
28+
import { getStepInto, isDirectionnal, resolveGroupTypes, ScopeConfigDef } from './scope';
2929

3030
export enum LayoutName {
3131
threeD = '3d',
@@ -40,7 +40,7 @@ export enum LayoutName {
4040
grid = 'Grid'
4141
}
4242

43-
export type TopologyGroupTypes = 'none' | Groups;
43+
export type TopologyGroupTypes = 'none' | 'auto' | Groups;
4444

4545
export interface TopologyOptions {
4646
maxEdgeStat: number;
@@ -66,7 +66,7 @@ export const DefaultOptions: TopologyOptions = {
6666
startCollapsed: false,
6767
truncateLength: TruncateLength.M,
6868
layout: LayoutName.colaNoForce,
69-
groupTypes: 'none',
69+
groupTypes: 'auto',
7070
lowScale: 0.3,
7171
medScale: 0.5,
7272
metricFunction: defaultMetricFunction,
@@ -537,11 +537,12 @@ export const generateDataModel = (
537537
const addPossibleGroups = (peer: TopologyMetricPeer): NodeModel | undefined => {
538538
// groups are all possible scopes except last one
539539
const parentScopes = ContextSingleton.getScopes().slice(0, -1);
540+
const resolvedGroups = resolveGroupTypes(options.groupTypes, metricScope, scopes);
540541

541542
// build parent tree from biggest to smallest group
542543
let parent: NodeModel | undefined = undefined;
543544
parentScopes.forEach(sc => {
544-
if (options.groupTypes.includes(`${sc.id}s`) && !_.isEmpty(peer[sc.id])) {
545+
if (resolvedGroups.includes(`${sc.id}s`) && !_.isEmpty(peer[sc.id])) {
545546
parent = addGroup(
546547
{ [sc.id]: peer[sc.id], namespace: ['namespace', 'owner'].includes(sc.id) ? peer.namespace : undefined },
547548
sc.id,

0 commit comments

Comments
 (0)