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

Prettify error messages for exec.Commands in Fluid #2718

Conversation

TrafalgarZZZ
Copy link
Member

Ⅰ. Describe what this PR does

Fluid relies on exec.Command to execute some operations and interacts with K8s API-Server(e.g. The helm for install/check/delete engine-related resources). exec.Command will always returns a meaningless err that would confuses users about the cause of their problems.

For example, when Fluid CSI Plugin fails to bind mount a FUSE mount point onto a pod, an event is issued on the pod showing messages like:

MountVolume.Setup failed for volume "default-jfsdemo": rpc error: code = InvalidArgument desc = exit status 1

This PR prettifies such error messages with a clearer explanation about the cause. For example, the event message mentioned above would be changed to:

MountVolume.Setup failed for volume "default-jfsdemo": rpc error: code = Internal desc = timeout waiting for FUSE mount point to be ready

which indicates that it's highly possible the FUSE pod is still not ready on that node

Ⅱ. Does this pull request fix one issue?

NONE

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>
Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>
}

return err
return nil
}
Copy link
Collaborator

@cheyang cheyang Mar 9, 2023

Choose a reason for hiding this comment

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

How about change it into

if err != nil {
    errMsg := fmt.Sprintf("failed to execute InstallRelease() command: %s", err)
    log.Error(err, errMsg, "command", cmd.String())
    err = errors.Wrap(err, "failed to create engine-related kubernetes resources")
}



return err

Copy link
Member Author

Choose a reason for hiding this comment

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

With such implementation, log.Error may print double err info in the log.

And, errors.Wrap returns something like failed to create engine-related kubernetes resources: exit status 1 which I think is more confusing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok

@codecov
Copy link

codecov bot commented Mar 9, 2023

Codecov Report

Merging #2718 (6682531) into master (05589e9) will decrease coverage by 0.01%.
The diff coverage is 72.72%.

❗ Current head 6682531 differs from pull request most recent head 0993071. Consider uploading reports for the commit 0993071 to get more accurate results

@@            Coverage Diff             @@
##           master    #2718      +/-   ##
==========================================
- Coverage   67.55%   67.54%   -0.01%     
==========================================
  Files         381      381              
  Lines       21968    21982      +14     
==========================================
+ Hits        14840    14848       +8     
- Misses       5381     5386       +5     
- Partials     1747     1748       +1     
Impacted Files Coverage Δ
pkg/utils/mount.go 84.84% <40.00%> (-8.14%) ⬇️
pkg/utils/helm/utils.go 82.88% <100.00%> (+0.80%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

}
return err
}
return nil
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about using errors.As instead of strings.HasPrefix?

if errors.Is(err, exec.ErrNotFound) {
    return errors.New("fusemount command not found")
}
var fuseMountErr *exec.ExitError
if errors.As(err, &fuseMountErr) {
    switch fuseMountErr.ExitCode() {
    case 1:
        return errors.New("timeout waiting for FUSE mount point to be ready")
    case 2:
        return fmt.Errorf("subPath \"%s\" not exists under FUSE mount", subPath)
    }
}
return err

Copy link
Member Author

Choose a reason for hiding this comment

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

Thx. Changed to errors.As

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>
Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>
pkg/utils/helm/utils.go Outdated Show resolved Hide resolved
Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>
@sonarcloud
Copy link

sonarcloud bot commented Mar 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@TrafalgarZZZ
Copy link
Member Author

/test fluid-e2e

@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Mar 9, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cheyang

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

@cheyang
Copy link
Collaborator

cheyang commented Mar 9, 2023

/lgtm

@fluid-e2e-bot fluid-e2e-bot bot added the lgtm label Mar 9, 2023
@fluid-e2e-bot fluid-e2e-bot bot merged commit abb8b01 into fluid-cloudnative:master Mar 9, 2023
cheyang pushed a commit to cheyang/fluid that referenced this pull request Mar 23, 2023
…#2718)

* Prettify error log message when calling NodePublishVolume

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Prettify error logs when calling helm-related funcs

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Use instead `errors.As`

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Use instead `errors.As`

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Set higher log level for helm exec

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

---------

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>
cheyang pushed a commit to cheyang/fluid that referenced this pull request Mar 23, 2023
…#2718)

* Prettify error log message when calling NodePublishVolume

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Prettify error logs when calling helm-related funcs

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Use instead `errors.As`

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Use instead `errors.As`

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Set higher log level for helm exec

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

---------

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>
Signed-off-by: cheyang <cheyang@163.com>
cheyang added a commit that referenced this pull request Mar 27, 2023
* [juicefs] fix worker cache when set option (#2563)

* fix worker cache when set option

Signed-off-by: zwwhdls <zww@hdls.me>

* update changelog in chart

Signed-off-by: zwwhdls <zww@hdls.me>

* fix unittest

Signed-off-by: zwwhdls <zww@hdls.me>

---------

Signed-off-by: zwwhdls <zww@hdls.me>
Signed-off-by: cheyang <cheyang@163.com>

* fix multi cache dir (#2639)

* fix multi cache dir

Signed-off-by: zwwhdls <zww@hdls.me>

* fix unit test

---------

Signed-off-by: zwwhdls <zww@hdls.me>
Signed-off-by: cheyang <cheyang@163.com>

* [Enhancement]CSI plugin checks mount point liveness before binding mount points (#2703)

* Clean up broken mount point when NodeStageVolume

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Check mount point aliveness when NodePublishVolume

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Clean up broken mount point when NodeStageVolume

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Fix cleaning logic

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

---------

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>
Signed-off-by: cheyang <cheyang@163.com>

* Prettify error messages for exec.Commands in Fluid (#2718)

* Prettify error log message when calling NodePublishVolume

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Prettify error logs when calling helm-related funcs

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Use instead `errors.As`

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Use instead `errors.As`

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

* Set higher log level for helm exec

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>

---------

Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>
Signed-off-by: cheyang <cheyang@163.com>

* update mount to check mountinfo, To #48327952

Signed-off-by: cheyang <cheyang@163.com>

* update mount to check mountinfo, To #48327952

Signed-off-by: cheyang <cheyang@163.com>

* Build docker images for v0.8.5, To #48327952

Signed-off-by: cheyang <cheyang@163.com>

---------

Signed-off-by: zwwhdls <zww@hdls.me>
Signed-off-by: cheyang <cheyang@163.com>
Signed-off-by: dongyun.xzh <dongyun.xzh@alibaba-inc.com>
Co-authored-by: Weiwei <zww@hdls.me>
Co-authored-by: TzZtzt <trafalgarz@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants