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

vpa-recommender: Log object's namespace #6909

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

ialidzhikov
Copy link
Contributor

@ialidzhikov ialidzhikov commented Jun 10, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

Similar to #6903 but for the vpa-recommender. The Pod/VPA resources are namespaced and logging only the name does not allow these objections to be unambiguously identified in the cluster.

Which issue(s) this PR fixes:

N/A

Special notes for your reviewer:

N/A

Does this PR introduce a user-facing change?

vpa-recommender logging is now improved. In many cases it now logs the objects' namespaces as well.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jun 10, 2024
@k8s-ci-robot k8s-ci-robot requested a review from kgolab June 10, 2024 13:21
@k8s-ci-robot k8s-ci-robot added 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. labels Jun 10, 2024
@adrianmoisey
Copy link
Member

adrianmoisey commented Jun 11, 2024

Not a maintainer: but this PR looks good to me. I think the additional namespaces will help in the logs.

@adrianmoisey
Copy link
Member

Does this PR introduce a user-facing change?

Does it make sense to add a change log entry for this? I think it's useful for users to know that logs have improved if this lands.

@ialidzhikov
Copy link
Contributor Author

Does it make sense to add a change log entry for this? I think it's useful for users to know that logs have improved if this lands.

Done.

@ialidzhikov ialidzhikov requested a review from adrianmoisey June 13, 2024 06:55
@adrianmoisey
Copy link
Member

Sorry, I can't approve, I'm not an approver for the project. Just someone trying to get involved.

@@ -359,7 +359,7 @@ func (feeder *clusterStateFeeder) LoadVPAs() {
}

selector, conditions := feeder.getSelector(vpaCRD)
klog.V(4).Infof("Using selector %s for VPA %s/%s", selector.String(), vpaCRD.Namespace, vpaCRD.Name)
Copy link
Member

Choose a reason for hiding this comment

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

For some lines above you added that they are namespace/name. Is there a specific rule when to print namespacedName vs. the whole resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are not printing the whole resource. As explained in #6909 (comment) klog.KObj only prints <namespace>/<name>.

If you are asking why in some places we use klog.KObj and in some places we have to use %s/%s and pass the namespace and name: KObj accepts the interface KMetadata:

type KMetadata interface {
GetName() string
GetNamespace() string
}
. Structs like
type VpaID struct {
Namespace string
VpaName string
}
and
// PodID contains information needed to identify a Pod within a cluster.
type PodID struct {
// Namespaces where the Pod is defined.
Namespace string
// PodName is the name of the pod unique within a namespace.
PodName string
}
don't implement that interface and that's why I am using %s/%s for them.

Copy link
Member

Choose a reason for hiding this comment

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

I see, thanks. I wonder if it's worth implementing that interface on those types instead for consistency. But I'm good with this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if it's worth implementing that interface on those types instead for consistency. But I'm good with this too.

I discovered klog.KRef and adapted the VpaID/PodID usages to it: see 1739a71

@ialidzhikov ialidzhikov requested a review from kwiesmueller June 14, 2024 08:13
@raywainman
Copy link
Contributor

/lgtm

Thanks for making this consistent!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 14, 2024
@kwiesmueller
Copy link
Member

/lgtm
/hold
Feel free to remove hold if you don't want to implement the KMetadata interface on relevant types, I'm good either way.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 14, 2024
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2024
@ialidzhikov
Copy link
Contributor Author

/hold cancel
see #6909 (comment)

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 19, 2024
@ialidzhikov
Copy link
Contributor Author

@kwiesmueller could you have a look when you have time? Thanks in advance!

Copy link
Member

@kwiesmueller kwiesmueller left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Left a last safety question, otherwise great.
If the answer to my question is no, please just unhold.

/hold

@@ -113,10 +114,10 @@ func (s *externalMetricsClient) List(ctx context.Context, namespace string, opts
return nil, err
}
if m == nil || len(m.Items) == 0 {
klog.V(4).Infof("External Metrics Query for VPA %+v: resource %+v, metric %+v, No items,", vpa.ID, resourceName, metricName)
klog.V(4).Infof("External Metrics Query for VPA %s: resource %+v, metric %+v, No items,", klog.KRef(vpa.ID.Namespace, vpa.ID.VpaName), resourceName, metricName)
Copy link
Member

Choose a reason for hiding this comment

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

Just a sanity check as I can't dive deeper on my current device. Can ID be nil?

/hold

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In

func (cluster *ClusterState) AddOrUpdateVpa(apiObject *vpa_types.VerticalPodAutoscaler, selector labels.Selector) error {
it seems that vpaID is always set to Vpa model.

If vpa.ID is nil, it would panic earlier at

ObjectMeta: v1.ObjectMeta{Namespace: vpa.ID.Namespace, Name: pod.PodName},
.

/hold cancel

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jun 27, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ialidzhikov, kwiesmueller

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jun 27, 2024
@k8s-ci-robot k8s-ci-robot merged commit d0441f7 into kubernetes:master Jun 28, 2024
7 checks passed
@ialidzhikov ialidzhikov deleted the enh/recommender-logging branch June 29, 2024 17:04
@raywainman raywainman mentioned this pull request Aug 6, 2024
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. area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants