Skip to content

Label names displayed as-Is when nodes lack the specified labels - #352

Merged
tzneal merged 2 commits into
awslabs:mainfrom
rnakamine:fix/missing-extra-labels-display
Jan 21, 2025
Merged

tzneal merged 2 commits into
awslabs:mainfrom
rnakamine:fix/missing-extra-labels-display

Conversation

@rnakamine

@rnakamine rnakamine commented Dec 8, 2024 •

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

When specifying custom labels with the -extra-labels option, if a node does not have the specified label, the label name is displayed as-is.

For example, if you specify a label such as type using the following command:

$ eks-node-viewer -extra-labels type,eks-node-viewer/node-age -node-sort type

The output may look like this:

26 nodes (156331m/205660m) 76.0% cpu ██████████████████████████████░░░░░░░░░░ $6.115/hour | $4,463.950/month
350 pods (2 pending 348 running 350 bound)

ip-172-30-22-56.ap-northeast-1.compute.internal  cpu █████████████████████████████████░░  95% (13 pods) m7i.2xlarge/$0.4032 On-Demand -        Ready type       3d3h
ip-172-30-26-26.ap-northeast-1.compute.internal  cpu ███████████████████████████████░░░░  89% (14 pods) m7i.2xlarge/$0.4032 On-Demand -        Ready type       3d1h
ip-172-30-27-21.ap-northeast-1.compute.internal  cpu ███████████████████████████████░░░░  89% (10 pods) m7i.2xlarge/$0.4032 On-Demand -        Ready type       2d1h
ip-172-30-26-252.ap-northeast-1.compute.internal cpu ███████████████████████████████░░░░  89% (10 pods) m7i.2xlarge/$0.4032 On-Demand -        Ready type       2d1h
ip-172-30-23-219.ap-northeast-1.compute.internal cpu ███████████████████████████████░░░░  89% (10 pods) m7i.2xlarge/$0.4032 On-Demand -        Ready type       2d1h
ip-172-30-23-39.ap-northeast-1.compute.internal  cpu ████████████████████████████████░░░  92% (9 pods)  m7i.2xlarge/$0.4032 On-Demand -        Ready type       2d1h
ip-172-30-27-251.ap-northeast-1.compute.internal cpu ██████████████████████████████░░░░░  86% (9 pods)  m7i.2xlarge/$0.4032 On-Demand -        Ready type       2d1h
ip-172-30-27-125.ap-northeast-1.compute.internal cpu ███████████████████████████░░░░░░░░  76% (8 pods)  m6g.2xlarge/$0.1892 Spot      -        Ready apm        47h
ip-172-30-21-20.ap-northeast-1.compute.internal  cpu ██████████████████████████░░░░░░░░░  74% (8 pods)  m7g.2xlarge/$0.1721 Spot      -        Ready apm        24h
ip-172-30-21-207.ap-northeast-1.compute.internal cpu ███████████░░░░░░░░░░░░░░░░░░░░░░░░  32% (9 pods)  m7g.2xlarge/$0.1721 Spot      Cordoned Ready monitoring 18h
ip-172-30-21-136.ap-northeast-1.compute.internal cpu ███████████████████████████████████ 100% (18 pods) m7g.2xlarge/$0.1721 Spot      -        Ready type       17h
ip-172-30-22-189.ap-northeast-1.compute.internal cpu ███████████████████████████████████ 100% (28 pods) m7g.2xlarge/$0.1721 Spot      -        Ready type       17h

To address this, I modified the behavior so that if labels other than eks-node-viewer/node-age or eks-node-viewer/node-xxx-usage are specified, and a node does not have the specified label, a - will be displayed instead.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@rnakamine
rnakamine requested a review from a team as a code owner December 8, 2024 08:34
@rnakamine rnakamine changed the title Label Names Displayed as-Is When Nodes Lack the Specified Labels Label names displayed as-Is when nodes lack the specified labels Dec 8, 2024
Comment thread pkg/model/uimodel.go Outdated
labelValue = n.ComputeLabel(label)
if labelValue == label {
labelValue = "-"
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The ComputeLabel method returns the input label name as-is if it doesn't match a custom label; in such cases, it should display - instead.

// ComputeLabel computes dynamic labels
func (n *Node) ComputeLabel(labelName string) string {
switch labelName {
case "eks-node-viewer/node-age":
return duration.HumanDuration(time.Since(n.Created()))
}
// resource based custom labels
if match := resourceLabelRe.FindStringSubmatch(labelName); len(match) > 0 {
return pctUsage(n.Allocatable(), n.Used(), match[1])
}
return labelName
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can just put this into the ComputeLabel function (e.g. return - instead of labelName)

@rnakamine rnakamine Jan 7, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You can just put this into the ComputeLabel function (e.g. return - instead of labelName)

Fixed in 507e7c8

@rnakamine

rnakamine commented Dec 23, 2024 •

Copy link
Copy Markdown
Contributor Author

Hi @tzneal , could you please look at this PR when you can? Thanks!

@tzneal tzneal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@tzneal
tzneal merged commit de3d8b3 into awslabs:main Jan 21, 2025
@rnakamine
rnakamine deleted the fix/missing-extra-labels-display branch January 22, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants