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

feat: Add support for endpoint topology routing hints #2090

Merged
merged 14 commits into from
Aug 31, 2023

Conversation

MarkSRobinson
Copy link
Contributor

@MarkSRobinson MarkSRobinson commented Jun 5, 2023

What this PR does / why we need it:

This PR adds support for reporting the topology routing hints applied to Endpoint objects in kubernetes. This is useful to check if the underlying network layer has hints enabled or if it's been disabled. This will let users diagnose if they had topology aware routing enabled or disable in the networking configuration.

How does this change affect the cardinality of KSM: Increases, if people have topology aware routing enabled and working.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 5, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 5, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @MarkSRobinson!

It looks like this is your first PR to kubernetes/kube-state-metrics 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kube-state-metrics has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 5, 2023
Fix goimports

Fix gocritic issue
@mrueg
Copy link
Member

mrueg commented Jun 5, 2023

Thanks for your contribution!
This is a new feature and should target the main branch.

Also please review the CLA and sign it, otherwise we are unable to accept your change.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 5, 2023
@MarkSRobinson MarkSRobinson changed the base branch from release-2.9 to main June 5, 2023 21:11
@MarkSRobinson
Copy link
Contributor Author

@mrueg I've changed the base to main, but I'm hoping for a release on the 2.9 branch too. I'm trying to keep my k8s version and ksm/go-client version reasonably closely in-sync.

I've signed the CLA too.

@MarkSRobinson
Copy link
Contributor Author

@mrueg This PR is ready to go when you're ready.

@logicalhan
Copy link
Member

/triage accepted
/assign @dgrisonnet @rexagod

@k8s-ci-robot k8s-ci-robot added the triage/accepted Indicates an issue or PR is ready to be actively worked on. label Jun 15, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jun 15, 2023
@@ -17,6 +17,7 @@ import (
"testing"

corev1 "k8s.io/api/core/v1"

Copy link
Member

Choose a reason for hiding this comment

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

No need to add a blank line here

MarkSRobinson and others added 2 commits July 17, 2023 09:40
Co-authored-by: Manuel Rüger <manuel@rueg.eu>
Co-authored-by: Manuel Rüger <manuel@rueg.eu>
@MarkSRobinson MarkSRobinson changed the title Add support for endpoint topology routing hints feat: Add support for endpoint topology routing hints Jul 17, 2023
Dockerfile Outdated Show resolved Hide resolved
@mrueg
Copy link
Member

mrueg commented Aug 11, 2023

@MarkSRobinson if you can remove the Dockerfile changes, we can get this merged. :)

@MarkSRobinson
Copy link
Contributor Author

@mrueg Let me clean that up. I found that building for ARM was was easier if we pulled the Go parameters from the Docker build target environment. This let's us build it in k8s super easily.

Copy link
Member

@dgrisonnet dgrisonnet left a comment

Choose a reason for hiding this comment

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

I would suggest creating a new metric kube_endpointslice_endpoints_hints

Comment on lines 137 to 160
newlabelValues = append(newlabelValues, address)

// Hint is populated when the endpoint is configured to be zone aware and preferentially route requests to its local zone.
if ep.Hints != nil && len(ep.Hints.ForZones) > 0 {

// Because each endpoint can have multiple zones, we need to create a metric for each zone.
// and we need to make sure we aren't adding the hint label repeatedly, we need to copy the array
for _, zone := range ep.Hints.ForZones {
zoneLabelValues := make([]string, len(newlabelValues))
copy(zoneLabelValues, newlabelValues)
zoneLabelValues = append(zoneLabelValues, zone.Name)
m = append(m, &metric.Metric{
LabelKeys: append(labelKeys, "hint"),
LabelValues: zoneLabelValues,
Value: 1,
})
}
} else {
m = append(m, &metric.Metric{
LabelKeys: labelKeys,
LabelValues: newlabelValues,
Value: 1,
})
}
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't need to be in the loop iterating over addresses

Copy link
Member

Choose a reason for hiding this comment

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

@MarkSRobinson this is the comment I was mentioning 🙂

@MarkSRobinson
Copy link
Contributor Author

@mrueg I'm ready to merge this PR if you are.

@mrueg
Copy link
Member

mrueg commented Aug 24, 2023

@mrueg I'm ready to merge this PR if you are.

Can you address @dgrisonnet's comment here please? #2090 (comment)

@MarkSRobinson
Copy link
Contributor Author

@dgrisonnet Can you explain why you want a new metric instead of adding to the existing one?

@dgrisonnet
Copy link
Member

@MarkSRobinson it is generally a better practice to keep metrics focus on only one purpose as they become more readable and easier to use. So that's why I am suggesting to create a new metric dedicated to the hints rather than adding yet another label to the already very packed endpoints metric.

@dgrisonnet
Copy link
Member

Hi @MarkSRobinson, we are planning to start cutting a new release of kube-state-metrics Wednesday. Do you think you'll be able to address the comments by then?

@MarkSRobinson
Copy link
Contributor Author

@dgrisonnet yeah, I can get to this tomorrow

@MarkSRobinson
Copy link
Contributor Author

@dgrisonnet It's ready if you want to take a look

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MarkSRobinson, mrueg

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 30, 2023
internal/store/endpointslice.go Show resolved Hide resolved
internal/store/endpointslice.go Outdated Show resolved Hide resolved
internal/store/endpointslice.go Outdated Show resolved Hide resolved
@MarkSRobinson
Copy link
Contributor Author

If someone can kick off another build, we can get this merged.

@dgrisonnet
Copy link
Member

Merging manually to squash the commits.

@dgrisonnet dgrisonnet merged commit f369828 into kubernetes:main Aug 31, 2023
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants