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

logging: stop using formatted strings for object identifiers #1730

Merged

Conversation

stevekuznetsov
Copy link
Contributor

logging: format Kind better when none is present

Signed-off-by: Steve Kuznetsov skuznets@redhat.com


logging: stop using formatted strings for object identifiers

Signed-off-by: Steve Kuznetsov skuznets@redhat.com


Part of #1694
/assign @sttts @ncdc

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
@openshift-ci openshift-ci bot assigned ncdc and sttts Aug 10, 2022
@openshift-ci openshift-ci bot requested review from ncdc and sttts August 10, 2022 17:39
@stevekuznetsov
Copy link
Contributor Author

Before:

I0810 11:22:39.327675  348965 apibinding_controller.go:254] "queueing APIBinding because of APIExport because of APIResourceSchema because of CRD" reconciler="kcp-apibinding" *v1.customresourcedefinition.workspace="system:bound-crds" *v1.customresourcedefinition.namespace="" *v1.customresourcedefinition.name="1252198f-f5c3-4e29-80ca-a640b4916446" *v1.customresourcedefinition.apiVersion="" groupResource="locations.scheduling.kcp.dev" established=false APIResourceSchema="root|v220801-c65c674d4.locations.scheduling.kcp.dev" APIExport="root|scheduling.kcp.dev" key="root|scheduling.kcp.dev"

After:

I0810 11:41:44.332237  356454 apibinding_controller.go:254] "queueing APIBinding because of APIExport because of APIResourceSchema because of CRD" reconciler="kcp-apibinding" customresourcedefinition.workspace="system:bound-crds" customresourcedefinition.namespace="" customresourcedefinition.name="31e4234e-f93b-44ba-a8f3-360292b73b54" customresourcedefinition.apiVersion="" groupResource="cowboys.wildwest.dev" established=false apiresourceschema.workspace="root:e2e-org-ttkbv:e2e-workspace-wr6sq" apiresourceschema.namespace="" apiresourceschema.name="today.cowboys.wildwest.dev" apiresourceschema.apiVersion="" apiexport.workspace="root:e2e-org-ttkbv:e2e-workspace-wr6sq" apiexport.namespace="" apiexport.name="today-cowboys" apiexport.apiVersion="" key="root:e2e-org-ttkbv:e2e-workspace-p2vg4|cowboys"

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
@stevekuznetsov stevekuznetsov force-pushed the skuznets/fixup-object-keys branch from 65de975 to 04df6b3 Compare August 10, 2022 17:42
list, err := c.apiExportLister.List(labels.Everything())
if err != nil {
runtime.HandleError(err)
return
}

logger := logging.WithReconciler(klog.Background(), controllerName).WithValues("ClusterWorkspacShard", clusterWorkspaceShardKey)
logger := logging.WithObject(logging.WithReconciler(klog.Background(), controllerName), clusterWorkspaceShard.(*tenancyv1alpha1.ClusterWorkspaceShard))
Copy link
Member

Choose a reason for hiding this comment

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

(no action required) I'd split this in 2 to make it easier to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fairly pervasive at this point - perhaps I can try to make this a builder pattern in a follow-up and fix them all?

Copy link
Member

Choose a reason for hiding this comment

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

SGTM

@@ -243,7 +236,7 @@ func (c *controller) enqueueSecret(obj interface{}) {
return
}

logger := logging.WithReconciler(klog.Background(), controllerName).WithValues("Secret", secretKey)
logger := logging.WithObject(logging.WithReconciler(klog.Background(), controllerName), obj.(*corev1.Secret))
Copy link
Member

Choose a reason for hiding this comment

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

(no action required) I'd split this in 2 to make it easier to read

ctx = klog.NewContext(ctx, logger)
if _, err := c.getNamespace(clusterName, c.secretNamespace); errors.IsNotFound(err) {
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: c.secretNamespace,
Name: c.secretNamespace,
Annotations: map[string]string{logicalcluster.AnnotationKey: clusterName.String()},
Copy link
Member

Choose a reason for hiding this comment

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

Just making sure: this is only needed for logging.WithObject to include the cluster name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I'm open to better ideas :|

@@ -130,6 +131,7 @@ func (c *controller) createIdentitySecret(ctx context.Context, clusterName logic
if err != nil {
return err
}
secret.Annotations[logicalcluster.AnnotationKey] = clusterName.String()
Copy link
Member

Choose a reason for hiding this comment

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

Just making sure: this is only needed for logging.WithObject to include the cluster name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I'm open to better ideas :|

list, err := c.clusterWorkspaceTypeLister.List(labels.Everything())
if err != nil {
runtime.HandleError(err)
return
}

logger := logging.WithObject(logging.WithReconciler(klog.Background(), controllerName), clusterWorkspaceShard.(*tenancyv1alpha1.ClusterWorkspaceShard))
Copy link
Member

Choose a reason for hiding this comment

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

(no action required) I'd split this in 2 to make it easier to read

@ncdc
Copy link
Member

ncdc commented Aug 10, 2022

/approve

@sttts WDYT about #1730 (comment) ?

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 10, 2022
@ncdc
Copy link
Member

ncdc commented Aug 10, 2022

Happy to merge & iterate too (on the annotation bit)

@stevekuznetsov
Copy link
Contributor Author

@ncdc sure thing - the obvious choice would be logging.WithClusterObject(obj Object, cluster logicalcluster.Name) but I'm still not entirely certain why having the logical cluster on the object itself is bad and why we should prefer to pass it out-of-band to clients?

@stevekuznetsov
Copy link
Contributor Author

/retest

@stevekuznetsov stevekuznetsov force-pushed the skuznets/fixup-object-keys branch from 1d45745 to 7f78634 Compare August 10, 2022 19:26
@ncdc
Copy link
Member

ncdc commented Aug 10, 2022

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 10, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 10, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ncdc

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

@sttts
Copy link
Member

sttts commented Aug 10, 2022

/retest

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
@stevekuznetsov stevekuznetsov force-pushed the skuznets/fixup-object-keys branch from 7f78634 to 7439a16 Compare August 11, 2022 11:35
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 11, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 11, 2022

New changes are detected. LGTM label has been removed.

@stevekuznetsov stevekuznetsov added the lgtm Indicates that a PR is ready to be merged. label Aug 11, 2022
@openshift-merge-robot openshift-merge-robot merged commit 147bb87 into kcp-dev:main Aug 11, 2022
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants