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-1927 scopes config #634

Merged
merged 9 commits into from
Nov 18, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
step into
jpinsonneau committed Nov 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 0c65c7f8690ce052f3c0cdf69d1c120780567cf5
5 changes: 5 additions & 0 deletions config/sample-config.yaml
Original file line number Diff line number Diff line change
@@ -991,6 +991,7 @@ frontend:
- K8S_ClusterName
feature: multiCluster
filter: cluster_name
stepInto: zone
- id: zone
name: Zone
shortName: AZ
@@ -1004,6 +1005,7 @@ frontend:
filters:
- src_zone
- dst_zone
stepInto: host
- id: host
name: Node
description: Node on which the resources are running
@@ -1017,6 +1019,7 @@ frontend:
filters:
- src_host_name
- dst_host_name
stepInto: resource
- id: namespace
name: Namespace
shortName: NS
@@ -1034,6 +1037,7 @@ frontend:
filters:
- src_namespace
- dst_namespace
stepInto: owner
- id: owner
name: Owner
shortName: Own
@@ -1059,6 +1063,7 @@ frontend:
filters:
- src_owner_name
- dst_owner_name
stepInto: resource
- id: resource
name: Resource
shortName: Res
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -102,6 +102,7 @@ type Scope struct {
Groups []string `yaml:"groups,omitempty" json:"groups,omitempty"`
Filter string `yaml:"filter,omitempty" json:"filter,omitempty"`
Filters []string `yaml:"filters,omitempty" json:"filters,omitempty"`
StepInto string `yaml:"stepInto,omitempty" json:"stepInto,omitempty"`
}

type QuickFilter struct {
Original file line number Diff line number Diff line change
@@ -23,13 +23,12 @@ import { Config } from '../../../../model/config';
import { Filter, FilterDefinition, Filters } from '../../../../model/filters';
import { FlowScope, MetricType, StatFunction } from '../../../../model/flow-query';
import { getStat } from '../../../../model/metrics';
import { ScopeConfigDef } from '../../../../model/scope';
import { getStepInto, ScopeConfigDef } from '../../../../model/scope';
import {
Decorated,
ElementData,
FilterDir,
generateDataModel,
getStepIntoNext,
GraphElementPeer,
isDirElementFiltered,
LayoutName,
@@ -207,7 +206,7 @@ export const TopologyContent: React.FC<TopologyContentProps> = ({
const onStepInto = React.useCallback(
(data: Decorated<ElementData>) => {
const groupTypes: TopologyGroupTypes = metricScope;
const scope = getStepIntoNext(metricScope, scopes);
const scope = getStepInto(metricScope, scopes);
if (data.nodeType && data.peer && scope) {
setMetricScope(scope);
setOptions({ ...options, groupTypes });
5 changes: 5 additions & 0 deletions web/src/model/scope.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ export type ScopeConfigDef = {
groups?: string[];
filter?: string;
filters?: string[];
stepInto?: string;
};

export const getScopeName = (sc: ScopeConfigDef | undefined, t: (k: string) => string) => {
@@ -75,3 +76,7 @@ export const getNonDirectionnalScopes = () => {
export const getDirectionnalScopes = () => {
return ContextSingleton.getScopes().filter(sc => isDirectionnal(sc));
};

export const getStepInto = (scopeId: FlowScope, scopes: ScopeConfigDef[]): FlowScope | undefined => {
return scopes.find(sc => sc.id === scopeId)?.stepInto;
};
16 changes: 5 additions & 11 deletions web/src/model/topology.ts
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ import { createPeer, getFormattedValue } from '../utils/metrics';
import { defaultMetricFunction, defaultMetricType } from '../utils/router';
import { FlowScope, Groups, MetricFunction, MetricType, NodeType, StatFunction } from './flow-query';
import { getStat } from './metrics';
import { isDirectionnal, ScopeConfigDef } from './scope';
import { getStepInto, isDirectionnal, ScopeConfigDef } from './scope';

export enum LayoutName {
threeD = '3d',
@@ -41,15 +41,6 @@ export enum LayoutName {

export type TopologyGroupTypes = 'none' | Groups;

export const getStepIntoNext = (current: FlowScope, scopes: ScopeConfigDef[]): FlowScope | undefined => {
let next: FlowScope | undefined = undefined;
const index = scopes.findIndex(sc => sc.id === current);
if (index >= 0 && index < scopes.length) {
next = scopes[index].id;
}
return next;
};

export interface TopologyOptions {
maxEdgeStat: number;
nodeBadges?: boolean;
@@ -114,6 +105,9 @@ const getDirFilterDefValue = (
if (fields.resource && fields.namespace) {
def = findFilter(filterDefinitions, `${dir}_resource`)!;
value = `${fields.resource.type}.${fields.namespace}.${fields.resource.name}`;
} else if (nodeType === 'owner' && fields.owner) {
def = findFilter(filterDefinitions, `${dir}_owner_name`)!;
value = `"${fields.owner.name}"`;
} else {
// try by scope definitions
ContextSingleton.getScopes().forEach(sc => {
@@ -552,7 +546,7 @@ export const generateDataModel = (
};

const peerToNodeData = (p: TopologyMetricPeer): NodeData => {
const canStepInto = getStepIntoNext(metricScope, scopes) !== undefined;
const canStepInto = getStepInto(metricScope, scopes) !== undefined;
switch (metricScope) {
case 'owner':
return p.owner ? { peer: p, nodeType: 'owner', canStepInto } : { peer: p, nodeType: 'unknown' };