Skip to content

frontend: Map: Add weights to GraphNodes #3389

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adwait-godbole
Copy link
Contributor

@adwait-godbole adwait-godbole commented May 29, 2025

Fixes #3369

  1. Before Weights:

Screenshot from 2025-05-30 01-13-41

After Weights:

Screenshot from 2025-05-30 01-15-15

  1. Before Weights:
Screencast.from.29-05-25.08.25.38.PM.IST.webm

After Weights:

Screencast.from.29-05-25.08.27.19.PM.IST.webm

cc @sniok @yolossn

@k8s-ci-robot k8s-ci-robot requested a review from illume May 29, 2025 14:58
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 29, 2025
@k8s-ci-robot k8s-ci-robot requested a review from yolossn May 29, 2025 14:58
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: adwait-godbole
Once this PR has been reviewed and has the lgtm label, please assign sniok for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 29, 2025
Copy link
Contributor

@sniok sniok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice implementation! Thanks for taking a look.

I left a couple of small comments, but overall it looks good.
Oh and a couple of tests are failing

}

// sort nodes by weight (descending) and return the highest weighted node
const sortedByWeight = [...nodes].sort((a, b) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rewrite this function so that it doesn't create a copy and doesn't sort them all? It's possible to find a node with the biggest weight in linear time without allocating a new array

}

// if weights are the same, fall back to the hardcoded hierarchy
const deployment = nodes.find(it => it.kubeObject?.kind === 'Deployment');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think relying just on weight is better, we shouldn't have this fallback, especially since all of these kinds are covered already

* @param node - The GraphNode to get weight for
* @returns The effective weight (higher = more important)
*/
export function getNodeWeight(node: GraphNode): number {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be used for the layout, to determine in which order nodes are displayed. currently it's hardcoded in graphLayout.tsx:57 getPartitionLevel() function. Would you mind also using it there? Not very important but would be nice, if you have time

@adwait-godbole adwait-godbole force-pushed the feat/add-weights-to-graphnodes branch 2 times, most recently from 047660b to c15efae Compare May 30, 2025 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Map: Add ability for plugins to customize main node behavior in node group
3 participants