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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 Log full object name and creation error for topology template reconcile #7295

Conversation

killianmuldoon
Copy link
Contributor

Signed-off-by: killianmuldoon kmuldoon@vmware.com

Add a log with the full object name in before stripping the unique identifier in createErrorWithoutObjectName.

Fixes #7238

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 27, 2022
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Sep 27, 2022
@killianmuldoon killianmuldoon force-pushed the logs/log-full-object-name-for-templates branch from da05e3a to 5ea7dbc Compare September 27, 2022 13:28
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 27, 2022
func createErrorWithoutObjectName(err error, obj client.Object) error {
func createErrorWithoutObjectName(ctx context.Context, err error, obj client.Object) error {
log := ctrl.LoggerFrom(ctx)
log.Info("Failed to create object", "object", klog.KObj(obj), "error", err.Error())
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 think the simplest solution is just a generic log every time this function is called, but I'm open to opinions on when this might not be desired.

Copy link
Member

Choose a reason for hiding this comment

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

I think thats fair, except it not being obvious to log the error due to the function name 馃

But createAndLogErrorWithoutObjectName is also weird.

Copy link
Member

Choose a reason for hiding this comment

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

Can we fix this by using log.WithCallDepth(1)?
If we can get this fixed I'm oke with the solution given that is scoped to a single file/private, but we should add one comment explaining that we log here in order to surface the name somewhere (without triggering reconcile)

Copy link
Member

Choose a reason for hiding this comment

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

What about the following?

log.WithCallDepth(1).Error(err, "Failed to create object", obj.GetObjectKind().GroupVersionKind().Kind, klog.KObj(obj))
  • uses the Kind instead of just object (I think it should be always set, we set it explicitly in MD and all the unstructured stuff needs it). Would be good to double-check though.
  • WithCallDepth(1) should work, but please verify
  • I would use .Error instead of adding a error k/v pair

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Call Depth is already set here as this case is using the topology logger (which sets its own call level). Right now it's logging the line number where the function call occurs which is the desired behaviour.

I've updated to use Kind (which I'm mixed on because object makes it clearer to me which object the creation error refers to in this line) and changed to .Error() in the latest version.

Signed-off-by: killianmuldoon <kmuldoon@vmware.com>
@killianmuldoon killianmuldoon force-pushed the logs/log-full-object-name-for-templates branch from c91ae75 to 6997cf6 Compare October 5, 2022 12:44
@fabriziopandini
Copy link
Member

/lgtm
/approve

/cherry-pick release-1.2

@k8s-infra-cherrypick-robot

@fabriziopandini: once the present PR merges, I will cherry-pick it on top of release-1.2 in a new PR and assign it to you.

In response to this:

/lgtm
/approve

/cherry-pick release-1.2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 5, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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 Oct 5, 2022
@k8s-ci-robot k8s-ci-robot merged commit da99b25 into kubernetes-sigs:main Oct 5, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.3 milestone Oct 5, 2022
@k8s-infra-cherrypick-robot

@fabriziopandini: new pull request created: #7352

In response to this:

/lgtm
/approve

/cherry-pick release-1.2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClusterClass: Make it easier to debug errors on object creation
6 participants