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

Adding error handling and logging #694

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Fiona-Waters
Copy link
Contributor

Issue link

Closes #613

What changes have been made

Added error handling and logging. This issue has not been fully completed as we will now be working on V2 of MCAD. Hoping to merge the work that was done before this decision was made.

Verification steps

Code review.

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • Testing is not required for this change

Copy link

openshift-ci bot commented Nov 23, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign asm582 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

Copy link
Contributor

@z103cb z103cb left a comment

Choose a reason for hiding this comment

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

Small nitpicks.

@@ -42,7 +43,7 @@ func buildConfig(master, kubeconfig string) (*rest.Config, error) {
func Run(opt *options.ServerOption) error {
restConfig, err := buildConfig(opt.Master, opt.Kubeconfig)
if err != nil {
return err
return fmt.Errorf("[Run] unable to build server config, - error: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

errors should not start with Uppercase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @z103cb, are you referring here to the function name - [Run] or to the string following it? Throughout the mcad codebase the log lines are very inconsistent in terms of starting with upper and lowercase, but a lot of them start with the function name which I have done here. Please clarify, thank you.

Copy link

Choose a reason for hiding this comment

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

I noticed a point in Google's style guide for Go that suggests not capitalizing error strings, as they typically appear within other contexts before being presented to the user:
https://google.github.io/styleguide/go/decisions.html#error-strings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @ronensc thank you, yes I understand this. I can either remove the [Function] part altogether or make it lowercase [function]? There are a large number of pre-existing error logs in the code base that include the function name which starts with an uppercase letter. So perhaps all of these need to be updated - we need to decide how to proceed in this case.

Copy link

Choose a reason for hiding this comment

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

@Fiona-Waters I'm with you. I think for this PR, we can keep it as is, and uniquely format the error messages in a future PR once a decision is made.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's ok if we fix this later wholesale.

@@ -71,7 +72,8 @@ func Run(opt *options.ServerOption) error {
// This call is blocking (unless an error occurs) which equates to <-neverStop
err = listenHealthProbe(opt)
if err != nil {
return err
return fmt.Errorf("[Run] unable to start health probe listener, - error: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

see above.

Copy link
Contributor

@ChristianZaccaria ChristianZaccaria left a comment

Choose a reason for hiding this comment

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

Very awesome job @Fiona-Waters ! I left a few nitpicks and the comment below

I think this file should be addressed as well:

klog.V(8).Infof("[GetAggregatedResources] Failure aggregating resources for %s/%s, err=%#v, genericItem=%#v",

pkg/controller/queuejob/queuejob_controller_ex.go Outdated Show resolved Hide resolved
@@ -2077,9 +2113,9 @@ func (cc *XController) manageQueueJob(ctx context.Context, qj *arbv1.AppWrapper,
_, err00 := cc.genericresources.SyncQueueJob(qj, &ar)
if err00 != nil {
if apierrors.IsInvalid(err00) {
klog.Warningf("[manageQueueJob] Invalid generic item sent for dispatching by app wrapper='%s/%s' err=%v", qj.Namespace, qj.Name, err00)
klog.Warningf("[manageQueueJob] Invalid generic item sent for dispatching by app wrapper='%s/%s' - error: %v", qj.Namespace, qj.Name, err00)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be an Error log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I just updated the formatting so I'm not sure about changing this. @z103cb added this a few months ago. Maybe there were reasons for using klog.Warningf here rather than Errorf.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I recall correctly, this was done to not generate a spurious error message when there's a bad definition for the generic resource. As they say beauty in in the eye of the beholder, if you will if this warning should be an error I would not object.

@Fiona-Waters
Copy link
Contributor Author

Very awesome job @Fiona-Waters ! I left a few nitpicks and the comment below

I think this file should be addressed as well:

klog.V(8).Infof("[GetAggregatedResources] Failure aggregating resources for %s/%s, err=%#v, genericItem=%#v",

Thanks for the review. This issue wasn't fully completed but as we are moving to mcad v2 Anish suggested I create a PR with what was completed so far, but not to do any more. Therefore all files haven't been covered.

@z103cb
Copy link
Contributor

z103cb commented Dec 6, 2023

/LGTM

Copy link

openshift-ci bot commented Dec 6, 2023

@z103cb: changing LGTM is restricted to collaborators

In response to this:

/LGTM

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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Error handling] Evaluate MCAD code base for better error handling
5 participants