Skip to content

Commit

Permalink
step into
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinsonneau committed Nov 12, 2024
1 parent aeac5b8 commit 0c65c7f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
5 changes: 5 additions & 0 deletions config/sample-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ frontend:
- K8S_ClusterName
feature: multiCluster
filter: cluster_name
stepInto: zone
- id: zone
name: Zone
shortName: AZ
Expand All @@ -1004,6 +1005,7 @@ frontend:
filters:
- src_zone
- dst_zone
stepInto: host
- id: host
name: Node
description: Node on which the resources are running
Expand All @@ -1017,6 +1019,7 @@ frontend:
filters:
- src_host_name
- dst_host_name
stepInto: resource
- id: namespace
name: Namespace
shortName: NS
Expand All @@ -1034,6 +1037,7 @@ frontend:
filters:
- src_namespace
- dst_namespace
stepInto: owner
- id: owner
name: Owner
shortName: Own
Expand All @@ -1059,6 +1063,7 @@ frontend:
filters:
- src_owner_name
- dst_owner_name
stepInto: resource
- id: resource
name: Resource
shortName: Res
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 });
Expand Down
5 changes: 5 additions & 0 deletions web/src/model/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Up @@ -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',
Expand All @@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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' };
Expand Down

0 comments on commit 0c65c7f

Please sign in to comment.