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

refactor: refactor the logs of lvmcluster controller #137

Merged
merged 1 commit into from
Apr 7, 2022

Conversation

iamniting
Copy link
Member

Signed-off-by: Nitin Goyal [email protected]

Copy link
Contributor

@leelavg leelavg left a comment

Choose a reason for hiding this comment

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

  • general observation, do we need to log error/info in both call and execution site (ex: getRunningPodImage)?
  • it seems PR increased number of info level logs, (ex: openshiftsccs)
  • when we debug issues, we first jump into error site and go up the stack and logging similar errors may not be helpful always (this is only my opinion)

Copy link
Contributor

@nbalacha nbalacha left a comment

Choose a reason for hiding this comment

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

Can you post the before and after logs for the operator so we can see what the changes look like?

@@ -183,7 +186,8 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, instance *lvmv1alp
for _, unit := range resourceCreationList {
err := unit.ensureCreated(r, ctx, instance)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed reconciling: %s %w", unit.getName(), err)
r.Log.Error(err, "failed reconciling", "Resource", unit.getName())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually changing the error being returned, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes I know, We should return an original error IMO as that can be used to determine the error in the caller's place.

}

pod := &corev1.Pod{}
if err := r.Get(ctx, types.NamespacedName{Name: podName, Namespace: r.Namespace}, pod); err != nil {
return fmt.Errorf("failed to get pod %s in namespace %s", podName, r.Namespace)
r.Log.Error(err, "Failed to get pod.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this include information about the pod that was requested?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes error will have it, This is the error which gets generated pods "test" not found when I ran the below code.

pod := &corev1.Pod{}                                    
err = fakeReconciler.Client.Get(context.TODO(), types.NamespacedName{Name: "test", Namespace: "test"}, pod)                                                       
fmt.Println(err)

@iamniting
Copy link
Member Author

iamniting commented Mar 31, 2022

Can you post the before and after logs for the operator so we can see what the changes look like?

before-lvm.log
after-lvm.log

@iamniting iamniting requested a review from nbalacha March 31, 2022 09:26
@nbalacha
Copy link
Contributor

nbalacha commented Apr 1, 2022

Can the following be done?

  1. Remove "reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster" from the messages. I think they are unnecessary.
  2. Rework the messages to remove duplicate fields. For instance, the req name and namespace already have the information captured in name and namespace in the messages below:
{"level":"info","ts":1648710461.5450764,"logger":"controller.lvmcluster.lvmcluster-controller","msg":"openshiftSCC found, setting cluster type to openshift.","reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster","name":"lvmcluster-sample","namespace":"lvm-operator-system","Request.Namespace":"lvm-operator-system","Request.Name":"lvmcluster-sample"}
{"level":"info","ts":1648710461.6462138,"logger":"controller.lvmcluster.lvmcluster-controller","msg":"Finalizer not found for LvmCluster. Adding finalizer.","reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster","name":"lvmcluster-sample","namespace":"lvm-operator-system","Request.Namespace":"lvm-operator-system","Request.Name":"lvmcluster-sample"}
  1. Uniform capitalization for messages. The older ones do not start with a capital letter.
  2. uniform capitalization for field names. Older ones use all smallcase letters for the most part.
  3. Reconsider some of the existing log fields. For instance:
    {"level":"info","ts":1648710462.1055522,"logger":"controller.lvmcluster.lvmcluster-controller","msg":"already exists","reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster","name":"lvmcluster-sample","namespace":"lvm-operator-system","Request.Namespace":"lvm-operator-system","Request.Name":"lvmcluster-sample","SecurityContextConstraint":"odf-lvm-vgmanager"}
    may be better as
    {"level":"info","ts":1648710462.1055522,"logger":"controller.lvmcluster.lvmcluster-controller","msg":"already exists","reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster","name":"lvmcluster-sample","namespace":"lvm-operator-system","Request.Namespace":"lvm-operator-system","Request.Name":"lvmcluster-sample", "type","SecurityContextConstraint", "name", "odf-lvm-vgmanager"}
    or
    {"level":"info","ts":1648710462.1055522,"logger":"controller.lvmcluster.lvmcluster-controller","msg":"SCC odf-lvm-vgmanager already exists","reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster","name":"lvmcluster-sample","namespace":"lvm-operator-system","Request.Namespace":"lvm-operator-system","Request.Name":"lvmcluster-sample"}

@iamniting iamniting force-pushed the log branch 4 times, most recently from f7db3db to 097c59a Compare April 1, 2022 11:40
@iamniting
Copy link
Member Author

Can the following be done?

  1. Remove "reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster" from the messages. I think they are unnecessary.
  2. Rework the messages to remove duplicate fields. For instance, the req name and namespace already have the information captured in name and namespace in the messages below:
{"level":"info","ts":1648710461.5450764,"logger":"controller.lvmcluster.lvmcluster-controller","msg":"openshiftSCC found, setting cluster type to openshift.","reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster","name":"lvmcluster-sample","namespace":"lvm-operator-system","Request.Namespace":"lvm-operator-system","Request.Name":"lvmcluster-sample"}
{"level":"info","ts":1648710461.6462138,"logger":"controller.lvmcluster.lvmcluster-controller","msg":"Finalizer not found for LvmCluster. Adding finalizer.","reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster","name":"lvmcluster-sample","namespace":"lvm-operator-system","Request.Namespace":"lvm-operator-system","Request.Name":"lvmcluster-sample"}
  1. Uniform capitalization for messages. The older ones do not start with a capital letter.
  2. uniform capitalization for field names. Older ones use all smallcase letters for the most part.
  3. Reconsider some of the existing log fields. For instance:
    {"level":"info","ts":1648710462.1055522,"logger":"controller.lvmcluster.lvmcluster-controller","msg":"already exists","reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster","name":"lvmcluster-sample","namespace":"lvm-operator-system","Request.Namespace":"lvm-operator-system","Request.Name":"lvmcluster-sample","SecurityContextConstraint":"odf-lvm-vgmanager"}
    may be better as
    {"level":"info","ts":1648710462.1055522,"logger":"controller.lvmcluster.lvmcluster-controller","msg":"already exists","reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster","name":"lvmcluster-sample","namespace":"lvm-operator-system","Request.Namespace":"lvm-operator-system","Request.Name":"lvmcluster-sample", "type","SecurityContextConstraint", "name", "odf-lvm-vgmanager"}
    or
    {"level":"info","ts":1648710462.1055522,"logger":"controller.lvmcluster.lvmcluster-controller","msg":"SCC odf-lvm-vgmanager already exists","reconciler group":"lvm.topolvm.io","reconciler kind":"LVMCluster","name":"lvmcluster-sample","namespace":"lvm-operator-system","Request.Namespace":"lvm-operator-system","Request.Name":"lvmcluster-sample"}

made most of the changes, pls take a look.

Copy link
Contributor

@leelavg leelavg left a comment

Choose a reason for hiding this comment

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

minor comments.

@@ -324,10 +340,11 @@ func (r *LVMClusterReconciler) getRunningPodImage(ctx context.Context) error {
}
}

return fmt.Errorf("failed to get container image for %s in pod %s", LVMOperatorContainerName, podName)
err := fmt.Errorf("failed to get container image for %s in pod %s", LVMOperatorContainerName, podName)
r.Log.Error(err, "container image not found")
Copy link
Contributor

Choose a reason for hiding this comment

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

  • we need LVMOperatorContainerName in log as well to know we are looking for correct container or not

Copy link
Member Author

Choose a reason for hiding this comment

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

We already have if you see above created err.

}

pod := &corev1.Pod{}
if err := r.Get(ctx, types.NamespacedName{Name: podName, Namespace: r.Namespace}, pod); err != nil {
return fmt.Errorf("failed to get pod %s in namespace %s", podName, r.Namespace)
r.Log.Error(err, "failed to get pod")
Copy link
Contributor

Choose a reason for hiding this comment

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

  • better log at-least pod name

Copy link
Contributor

Choose a reason for hiding this comment

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

agree

Copy link
Member Author

Choose a reason for hiding this comment

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

err will have it, but still i added in the logs again.

@@ -183,7 +186,8 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, instance *lvmv1alp
for _, unit := range resourceCreationList {
err := unit.ensureCreated(r, ctx, instance)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed reconciling: %s %w", unit.getName(), err)
r.Log.Error(err, "failed reconciling", "resource", unit.getName())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
r.Log.Error(err, "failed reconciling", "resource", unit.getName())
r.Log.Error(err, "failed to reconcile", "resource", unit.getName())

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}

pod := &corev1.Pod{}
if err := r.Get(ctx, types.NamespacedName{Name: podName, Namespace: r.Namespace}, pod); err != nil {
return fmt.Errorf("failed to get pod %s in namespace %s", podName, r.Namespace)
r.Log.Error(err, "failed to get pod")
Copy link
Contributor

Choose a reason for hiding this comment

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

agree

@@ -52,14 +52,16 @@ func (c openshiftSccs) ensureCreated(r *LVMClusterReconciler, ctx context.Contex
r.Log.Info("creating SecurityContextConstraint", "SecurityContextConstraint", scc.Name)
_, err := r.SecurityClient.SecurityContextConstraints().Create(ctx, scc, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("failed to create SCC %q: %v", scc.Name, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please include the scc name in the error and the log

Copy link
Member Author

Choose a reason for hiding this comment

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

err will already have it, But I have added it again in the logs.

Copy link
Contributor

@leelavg leelavg left a comment

Choose a reason for hiding this comment

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

/lgtm

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

openshift-ci bot commented Apr 7, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: iamniting, leelavg, nbalacha

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 7, 2022
@openshift-merge-robot openshift-merge-robot merged commit 8d77b03 into openshift:main Apr 7, 2022
@iamniting iamniting deleted the log branch April 13, 2022 17:15
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